auto-patch 638-dev-dev01-2024-05-14T20_44_36
This commit is contained in:
@@ -351,7 +351,26 @@ class ActionScheduler_ActionFactory {
|
||||
*/
|
||||
protected function store_unique_action( ActionScheduler_Action $action ) {
|
||||
$store = ActionScheduler_Store::instance();
|
||||
return method_exists( $store, 'save_unique_action' ) ?
|
||||
$store->save_unique_action( $action ) : $store->save_action( $action );
|
||||
if ( method_exists( $store, 'save_unique_action' ) ) {
|
||||
return $store->save_unique_action( $action );
|
||||
} else {
|
||||
/**
|
||||
* Fallback to non-unique action if the store doesn't support unique actions.
|
||||
* We try to save the action as unique, accepting that there might be a race condition.
|
||||
* This is likely still better than givinig up on unique actions entirely.
|
||||
*/
|
||||
$existing_action_id = (int) $store->find_action(
|
||||
$action->get_hook(),
|
||||
array(
|
||||
'args' => $action->get_args(),
|
||||
'status' => ActionScheduler_Store::STATUS_PENDING,
|
||||
'group' => $action->get_group(),
|
||||
)
|
||||
);
|
||||
if ( $existing_action_id > 0 ) {
|
||||
return 0;
|
||||
}
|
||||
return $store->save_action( $action );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,8 +192,8 @@ class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
|
||||
# Print notice.
|
||||
echo '<div class="notice notice-warning"><p>';
|
||||
printf(
|
||||
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
|
||||
_n(
|
||||
// translators: 1) is the number of affected actions, 2) is a link to an admin screen.
|
||||
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>',
|
||||
'<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>',
|
||||
$num_pastdue_actions,
|
||||
@@ -224,6 +224,7 @@ class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
|
||||
'id' => 'action_scheduler_about',
|
||||
'title' => __( 'About', 'woocommerce' ),
|
||||
'content' =>
|
||||
// translators: %s is the Action Scheduler version.
|
||||
'<h2>' . sprintf( __( 'About Action Scheduler %s', 'woocommerce' ), $as_version ) . '</h2>' .
|
||||
'<p>' .
|
||||
__( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'woocommerce' ) .
|
||||
|
||||
@@ -313,6 +313,24 @@ abstract class ActionScheduler_Abstract_ListTable extends WP_List_Table {
|
||||
return "ORDER BY {$orderby} {$order}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Querystring arguments to persist between form submissions.
|
||||
*
|
||||
* @since 3.7.3
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function get_request_query_args_to_persist() {
|
||||
return array_merge(
|
||||
$this->sort_by,
|
||||
array(
|
||||
'page',
|
||||
'status',
|
||||
'tab',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sortable column specified for this request to order the results by, if any.
|
||||
*
|
||||
@@ -682,8 +700,8 @@ abstract class ActionScheduler_Abstract_ListTable extends WP_List_Table {
|
||||
|
||||
// Translated status labels.
|
||||
$status_labels = ActionScheduler_Store::instance()->get_status_labels();
|
||||
$status_labels['all'] = _x( 'All', 'status labels', 'woocommerce' );
|
||||
$status_labels['past-due'] = _x( 'Past-due', 'status labels', 'woocommerce' );
|
||||
$status_labels['all'] = esc_html_x( 'All', 'status labels', 'woocommerce' );
|
||||
$status_labels['past-due'] = esc_html_x( 'Past-due', 'status labels', 'woocommerce' );
|
||||
|
||||
foreach ( $this->status_counts as $status_slug => $count ) {
|
||||
|
||||
@@ -717,12 +735,15 @@ abstract class ActionScheduler_Abstract_ListTable extends WP_List_Table {
|
||||
*/
|
||||
protected function display_table() {
|
||||
echo '<form id="' . esc_attr( $this->_args['plural'] ) . '-filter" method="get">';
|
||||
foreach ( $_GET as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( '_' === $key[0] || 'paged' === $key || 'ID' === $key ) {
|
||||
foreach ( $this->get_request_query_args_to_persist() as $arg ) {
|
||||
$arg_value = isset( $_GET[ $arg ] ) ? sanitize_text_field( wp_unslash( $_GET[ $arg ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! $arg_value ) {
|
||||
continue;
|
||||
}
|
||||
echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />';
|
||||
|
||||
echo '<input type="hidden" name="' . esc_attr( $arg ) . '" value="' . esc_attr( $arg_value ) . '" />';
|
||||
}
|
||||
|
||||
if ( ! empty( $this->search_by ) ) {
|
||||
echo $this->search_box( $this->get_search_box_button_text(), 'plugin' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
@@ -325,7 +325,8 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
* @throws InvalidArgumentException When json encoded args is too long.
|
||||
*/
|
||||
protected function validate_action( ActionScheduler_Action $action ) {
|
||||
if ( strlen( json_encode( $action->get_args() ) ) > static::$max_args_length ) {
|
||||
if ( strlen( wp_json_encode( $action->get_args() ) ) > static::$max_args_length ) {
|
||||
// translators: %d is a number (maximum length of action arguments).
|
||||
throw new InvalidArgumentException( sprintf( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than %d characters when encoded as JSON.', 'woocommerce' ), static::$max_args_length ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
// Last try, guess timezone string manually.
|
||||
foreach ( timezone_abbreviations_list() as $abbr ) {
|
||||
foreach ( $abbr as $city ) {
|
||||
if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) {
|
||||
if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) { // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- we are actually interested in the runtime timezone.
|
||||
return $city['timezone_id'];
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
|
||||
// Try mapping to the first abbreviation we can find.
|
||||
if ( false === $tzstring ) {
|
||||
$is_dst = date( 'I' );
|
||||
$is_dst = date( 'I' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- we are actually interested in the runtime timezone.
|
||||
foreach ( timezone_abbreviations_list() as $abbr ) {
|
||||
foreach ( $abbr as $city ) {
|
||||
if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
|
||||
|
||||
@@ -146,7 +146,7 @@ class ActionScheduler_DBStore extends ActionScheduler_Store {
|
||||
$column_sql = '`' . implode( '`, `', $columns ) . '`';
|
||||
$placeholder_sql = implode( ', ', $placeholders );
|
||||
$where_clause = $this->build_where_clause_for_insert( $data, $table_name, $unique );
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $column_sql and $where_clause are already prepared. $placeholder_sql is hardcoded.
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $column_sql and $where_clause are already prepared. $placeholder_sql is hardcoded.
|
||||
$insert_query = $wpdb->prepare(
|
||||
"
|
||||
INSERT INTO $table_name ( $column_sql )
|
||||
@@ -181,7 +181,7 @@ WHERE ( $where_clause ) IS NULL",
|
||||
);
|
||||
$pending_status_placeholders = implode( ', ', array_fill( 0, count( $pending_statuses ), '%s' ) );
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- $pending_status_placeholders is hardcoded.
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- $pending_status_placeholders is hardcoded.
|
||||
$where_clause = $wpdb->prepare(
|
||||
"
|
||||
SELECT action_id FROM $table_name
|
||||
@@ -480,7 +480,7 @@ AND `group_id` = %d
|
||||
case 'like':
|
||||
foreach ( $query['args'] as $key => $value ) {
|
||||
$sql .= ' AND a.args LIKE %s';
|
||||
$json_partial = $wpdb->esc_like( trim( json_encode( array( $key => $value ) ), '{}' ) );
|
||||
$json_partial = $wpdb->esc_like( trim( wp_json_encode( array( $key => $value ) ), '{}' ) );
|
||||
$sql_params[] = "%{$json_partial}%";
|
||||
}
|
||||
break;
|
||||
@@ -1031,7 +1031,7 @@ AND `group_id` = %d
|
||||
$row_updates = 0;
|
||||
if ( count( $action_ids ) > 0 ) {
|
||||
$action_id_string = implode( ',', array_map( 'absint', $action_ids ) );
|
||||
$row_updates = $wpdb->query( "UPDATE {$wpdb->actionscheduler_actions} SET claim_id = 0 WHERE action_id IN ({$action_id_string})" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
$row_updates = $wpdb->query( "UPDATE {$wpdb->actionscheduler_actions} SET claim_id = 0 WHERE action_id IN ({$action_id_string})" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
}
|
||||
|
||||
$wpdb->delete( $wpdb->actionscheduler_claims, array( 'claim_id' => $claim->get_id() ), array( '%d' ) );
|
||||
@@ -1039,6 +1039,7 @@ AND `group_id` = %d
|
||||
if ( $row_updates < count( $action_ids ) ) {
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
// translators: %d is an id.
|
||||
__( 'Unable to release actions from claim id %d.', 'woocommerce' ),
|
||||
$claim->get_id()
|
||||
)
|
||||
|
||||
@@ -690,7 +690,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
$params[] = $limit;
|
||||
|
||||
// Run the query and gather results.
|
||||
$rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); // phpcs:ignore // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||
$rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||
|
||||
if ( false === $rows_affected ) {
|
||||
throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) );
|
||||
@@ -725,7 +725,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
|
||||
'post_status' => ActionScheduler_Store::STATUS_PENDING,
|
||||
'has_password' => false,
|
||||
'posts_per_page' => $limit * 3,
|
||||
'suppress_filters' => true,
|
||||
'suppress_filters' => true, // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters
|
||||
'no_found_rows' => true,
|
||||
'orderby' => array(
|
||||
'menu_order' => 'ASC',
|
||||
|
||||
@@ -92,6 +92,7 @@ class ActionMigrator {
|
||||
|
||||
$test_action = $this->source->fetch_action( $source_action_id );
|
||||
if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
|
||||
// translators: %s is an action ID.
|
||||
throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) );
|
||||
}
|
||||
do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
|
||||
|
||||
@@ -41,6 +41,7 @@ class ActionScheduler_DBStoreMigrator extends ActionScheduler_DBStore {
|
||||
|
||||
return $action_id;
|
||||
} catch ( \Exception $e ) {
|
||||
// translators: %s is an error message.
|
||||
throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'woocommerce' ), $e->getMessage() ), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user