diff --git a/classes/data-stores/ActionScheduler_DBStore.php b/classes/data-stores/ActionScheduler_DBStore.php index 79cdcf38c..78484db13 100644 --- a/classes/data-stores/ActionScheduler_DBStore.php +++ b/classes/data-stores/ActionScheduler_DBStore.php @@ -19,8 +19,13 @@ class ActionScheduler_DBStore extends ActionScheduler_Store { */ private $claim_before_date = null; - /** @var int */ - protected static $max_args_length = 8000; + /** + * The "longtext" field type can store up to 4,294,967,295 (4GB) characters. + * For sanity, allow up to half the length of 4GB (2GB) in the field. + * + * @var int + */ + protected static $max_args_length = 2147483647; // longtext length (4GB) /** @var int */ protected static $max_index_length = 191; diff --git a/classes/schema/ActionScheduler_StoreSchema.php b/classes/schema/ActionScheduler_StoreSchema.php index 2506f0180..b4fe817bf 100644 --- a/classes/schema/ActionScheduler_StoreSchema.php +++ b/classes/schema/ActionScheduler_StoreSchema.php @@ -16,7 +16,7 @@ class ActionScheduler_StoreSchema extends ActionScheduler_Abstract_Schema { /** * @var int Increment this value to trigger a schema update. */ - protected $schema_version = 6; + protected $schema_version = 7; public function __construct() { $this->tables = [ @@ -31,6 +31,7 @@ public function __construct() { */ public function init() { add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_5_0' ), 10, 2 ); + add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_7_0' ), 10, 2 ); } protected function get_table_definition( $table ) { @@ -56,7 +57,7 @@ protected function get_table_definition( $table ) { last_attempt_gmt datetime NULL default '${default_date}', last_attempt_local datetime NULL default '${default_date}', claim_id bigint(20) unsigned NOT NULL default '0', - extended_args varchar(8000) DEFAULT NULL, + extended_args longtext, PRIMARY KEY (action_id), KEY hook (hook($max_index_length)), KEY status (status), @@ -126,4 +127,24 @@ public function update_schema_5_0( $table, $db_version ) { } // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared } + + /** + * Update the actions table schema, changing `$extended_args` fields to be longtext. + * + * @param string $table Name of table being updated. + * @param string $db_version The existing schema version of the table. + */ + public function update_schema_7_0( $table, $db_version ) { + global $wpdb; + + if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '7', '>=' ) ) { + return; + } + + $table_name = $wpdb->prefix . 'actionscheduler_actions'; + $table_list = $wpdb->get_col( "SHOW TABLES LIKE '${table_name}'" ); + if ( ! empty( $table_list ) ) { + $wpdb->query( "ALTER TABLE ${table_name} MODIFY COLUMN extended_args longtext" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + } + } }