Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error saving action: ActionScheduler_Action::$args too long #855

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions classes/data-stores/ActionScheduler_DBStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 23 additions & 2 deletions classes/schema/ActionScheduler_StoreSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 ) {
Expand All @@ -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),
Expand Down Expand Up @@ -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
}
}
}