Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -5,8 +5,11 @@
|
||||
* Description: A robust scheduling library for use in WordPress plugins.
|
||||
* Author: Automattic
|
||||
* Author URI: https://automattic.com/
|
||||
* Version: 3.6.1
|
||||
* Version: 3.6.4
|
||||
* License: GPLv3
|
||||
* Tested up to: 6.3
|
||||
* Requires at least: 5.2
|
||||
* Requires PHP: 5.6
|
||||
*
|
||||
* Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)
|
||||
*
|
||||
@@ -26,27 +29,27 @@
|
||||
* @package ActionScheduler
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'action_scheduler_register_3_dot_6_dot_1' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION.
|
||||
if ( ! function_exists( 'action_scheduler_register_3_dot_6_dot_4' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION.
|
||||
|
||||
if ( ! class_exists( 'ActionScheduler_Versions', false ) ) {
|
||||
require_once __DIR__ . '/classes/ActionScheduler_Versions.php';
|
||||
add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 );
|
||||
}
|
||||
|
||||
add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_6_dot_1', 0, 0 ); // WRCS: DEFINED_VERSION.
|
||||
add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_6_dot_4', 0, 0 ); // WRCS: DEFINED_VERSION.
|
||||
|
||||
/**
|
||||
* Registers this version of Action Scheduler.
|
||||
*/
|
||||
function action_scheduler_register_3_dot_6_dot_1() { // WRCS: DEFINED_VERSION.
|
||||
function action_scheduler_register_3_dot_6_dot_4() { // WRCS: DEFINED_VERSION.
|
||||
$versions = ActionScheduler_Versions::instance();
|
||||
$versions->register( '3.6.1', 'action_scheduler_initialize_3_dot_6_dot_1' ); // WRCS: DEFINED_VERSION.
|
||||
$versions->register( '3.6.4', 'action_scheduler_initialize_3_dot_6_dot_4' ); // WRCS: DEFINED_VERSION.
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this version of Action Scheduler.
|
||||
*/
|
||||
function action_scheduler_initialize_3_dot_6_dot_1() { // WRCS: DEFINED_VERSION.
|
||||
function action_scheduler_initialize_3_dot_6_dot_4() { // WRCS: DEFINED_VERSION.
|
||||
// A final safety check is required even here, because historic versions of Action Scheduler
|
||||
// followed a different pattern (in some unusual cases, we could reach this point and the
|
||||
// ActionScheduler class is already defined—so we need to guard against that).
|
||||
@@ -58,7 +61,7 @@ if ( ! function_exists( 'action_scheduler_register_3_dot_6_dot_1' ) && function_
|
||||
|
||||
// Support usage in themes - load this version if no plugin has loaded a version yet.
|
||||
if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) {
|
||||
action_scheduler_initialize_3_dot_6_dot_1(); // WRCS: DEFINED_VERSION.
|
||||
action_scheduler_initialize_3_dot_6_dot_4(); // WRCS: DEFINED_VERSION.
|
||||
do_action( 'action_scheduler_pre_theme_init' );
|
||||
ActionScheduler_Versions::initialize_latest_version();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
*** Changelog ***
|
||||
|
||||
= 3.6.4 - 2023-10-11 =
|
||||
* 3.6.3 release.
|
||||
* Fix option lock test.
|
||||
* Fix: Use orderby => 'none' when bulk cancelling actions.
|
||||
* Tweak - WP 6.3 compatibility.
|
||||
* Update PR unit tests matrix.
|
||||
|
||||
= 3.6.3 - 2023-09-13 =
|
||||
* Use `_doing_it_wrong` in initialization check.
|
||||
|
||||
= 3.6.2 - 2023-08-09 =
|
||||
* Add guidance about passing arguments.
|
||||
* Atomic option locking.
|
||||
* Improve bulk delete handling.
|
||||
* Include database error in the exception message.
|
||||
* Tweak - WP 6.3 compatibility.
|
||||
|
||||
= 3.6.1 - 2023-06-14 =
|
||||
* Document new optional `$priority` arg for various API functions.
|
||||
* Document the new `--exclude-groups` WP CLI option.
|
||||
* Document the new `action_scheduler_init` hook.
|
||||
* Ensure actions within each claim are executed in the expected order.
|
||||
* Fix incorrect text domain.
|
||||
* Remove SHOW TABLES usage when checking if tables exist.
|
||||
|
||||
= 3.6.0 - 2023-05-10 =
|
||||
* Add $unique parameter to function signatures.
|
||||
* Add a cast-to-int for extra safety before forming new DateTime object.
|
||||
* Add a hook allowing exceptions for consistently failing recurring actions.
|
||||
* Add action priorities.
|
||||
* Add init hook.
|
||||
* Always raise the time limit.
|
||||
* Bump minimatch from 3.0.4 to 3.0.8.
|
||||
* Bump yaml from 2.2.1 to 2.2.2.
|
||||
* Defensive coding relating to gaps in declared schedule types.
|
||||
* Do not process an action if it cannot be set to `in-progress`.
|
||||
* Filter view labels (status names) should be translatable | #919.
|
||||
* Fix WPCLI progress messages.
|
||||
* Improve data-store initialization flow.
|
||||
* Improve error handling across all supported PHP versions.
|
||||
* Improve logic for flushing the runtime cache.
|
||||
* Support exclusion of multiple groups.
|
||||
* Update lint-staged and Node/NPM requirements.
|
||||
* add CLI clean command.
|
||||
* add CLI exclude-group filter.
|
||||
* exclude past-due from list table all filter count.
|
||||
* throwing an exception if as_schedule_recurring_action interval param is not of type integer.
|
||||
|
||||
= 3.5.4 - 2023-01-17 =
|
||||
* Add pre filters during action registration.
|
||||
* Async scheduling.
|
||||
* Calculate timeouts based on total actions.
|
||||
* Correctly order the parameters for `ActionScheduler_ActionFactory`'s calls to `single_unique`.
|
||||
* Fetch action in memory first before releasing claim to avoid deadlock.
|
||||
* PHP 8.2: declare property to fix creation of dynamic property warning.
|
||||
* PHP 8.2: fix "Using ${var} in strings is deprecated, use {$var} instead".
|
||||
* Prevent `undefined variable` warning for `$num_pastdue_actions`.
|
||||
|
||||
= 3.5.3 - 2022-11-09 =
|
||||
* Query actions with partial match.
|
||||
|
||||
= 3.5.2 - 2022-09-16 =
|
||||
* Fix - erroneous 3.5.1 release.
|
||||
|
||||
= 3.5.1 - 2022-09-13 =
|
||||
* Maintenance on A/S docs.
|
||||
* fix: PHP 8.2 deprecated notice.
|
||||
|
||||
= 3.5.0 - 2022-08-25 =
|
||||
* Add - The active view link within the "Tools > Scheduled Actions" screen is now clickable.
|
||||
* Add - A warning when there are past-due actions.
|
||||
* Enhancement - Added the ability to schedule unique actions via an atomic operation.
|
||||
* Enhancement - Improvements to cache invalidation when processing batches (when running on WordPress 6.0+).
|
||||
* Enhancement - If a recurring action is found to be consistently failing, it will stop being rescheduled.
|
||||
* Enhancement - Adds a new "Past Due" view to the scheduled actions list table.
|
||||
|
||||
= 3.4.2 - 2022-06-08 =
|
||||
* Fix - Change the include for better linting.
|
||||
* Fix - update: Added Action scheduler completed action hook.
|
||||
|
||||
= 3.4.1 - 2022-05-24 =
|
||||
* Fix - Change the include for better linting.
|
||||
* Fix - Fix the documented return type.
|
||||
|
||||
= 3.4.0 - 2021-10-29 =
|
||||
* Enhancement - Number of items per page can now be set for the Scheduled Actions view (props @ovidiul). #771
|
||||
* Fix - Do not lower the max_execution_time if it is already set to 0 (unlimited) (props @barryhughes). #755
|
||||
* Fix - Avoid triggering autoloaders during the version resolution process (props @olegabr). #731 & #776
|
||||
* Dev - ActionScheduler_wcSystemStatus PHPCS fixes (props @ovidiul). #761
|
||||
* Dev - ActionScheduler_DBLogger.php PHPCS fixes (props @ovidiul). #768
|
||||
* Dev - Fixed phpcs for ActionScheduler_Schedule_Deprecated (props @ovidiul). #762
|
||||
* Dev - Improve actions table indicies (props @glagonikas). #774 & #777
|
||||
* Dev - PHPCS fixes for ActionScheduler_DBStore.php (props @ovidiul). #769 & #778
|
||||
* Dev - PHPCS Fixes for ActionScheduler_Abstract_ListTable (props @ovidiul). #763 & #779
|
||||
* Dev - Adds new filter action_scheduler_claim_actions_order_by to allow tuning of the claim query (props @glagonikas). #773
|
||||
* Dev - PHPCS fixes for ActionScheduler_WpPostStore class (props @ovidiul). #780
|
||||
|
||||
= 3.3.0 - 2021-09-15 =
|
||||
* Enhancement - Adds as_has_scheduled_action() to provide a performant way to test for existing actions. #645
|
||||
* Fix - Improves compatibility with environments where NO_ZERO_DATE is enabled. #519
|
||||
* Fix - Adds safety checks to guard against errors when our database tables cannot be created. #645
|
||||
* Dev - Now supports queries that use multiple statuses. #649
|
||||
* Dev - Minimum requirements for WordPress and PHP bumped (to 5.2 and 5.6 respectively). #723
|
||||
|
||||
= 3.2.1 - 2021-06-21 =
|
||||
* Fix - Add extra safety/account for different versions of AS and different loading patterns. #714
|
||||
* Fix - Handle hidden columns (Tools → Scheduled Actions) | #600.
|
||||
|
||||
= 3.2.0 - 2021-06-03 =
|
||||
* Fix - Add "no ordering" option to as_next_scheduled_action().
|
||||
* Fix - Add secondary scheduled date checks when claiming actions (DBStore) | #634.
|
||||
* Fix - Add secondary scheduled date checks when claiming actions (wpPostStore) | #634.
|
||||
* Fix - Adds a new index to the action table, reducing the potential for deadlocks (props: @glagonikas).
|
||||
* Fix - Fix unit tests infrastructure and adapt tests to PHP 8.
|
||||
* Fix - Identify in-use data store.
|
||||
* Fix - Improve test_migration_is_scheduled.
|
||||
* Fix - PHP notice on list table.
|
||||
* Fix - Speed up clean up and batch selects.
|
||||
* Fix - Update pending dependencies.
|
||||
* Fix - [PHP 8.0] Only pass action arg values through to do_action_ref_array().
|
||||
* Fix - [PHP 8] Set the PHP version to 7.1 in composer.json for PHP 8 compatibility.
|
||||
* Fix - add is_initialized() to docs.
|
||||
* Fix - fix file permissions.
|
||||
* Fix - fixes #664 by replacing __ with esc_html__.
|
||||
|
||||
= 3.1.6 - 2020-05-12 =
|
||||
* Change log starts.
|
||||
@@ -502,7 +502,20 @@ class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
|
||||
*/
|
||||
protected function bulk_delete( array $ids, $ids_sql ) {
|
||||
foreach ( $ids as $id ) {
|
||||
$this->store->delete_action( $id );
|
||||
try {
|
||||
$this->store->delete_action( $id );
|
||||
} catch ( Exception $e ) {
|
||||
// A possible reason for an exception would include a scenario where the same action is deleted by a
|
||||
// concurrent request.
|
||||
error_log(
|
||||
sprintf(
|
||||
/* translators: 1: action ID 2: exception message. */
|
||||
__( 'Action Scheduler was unable to delete action %1$d. Reason: %2$s', 'woocommerce' ),
|
||||
$id,
|
||||
$e->getMessage()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,37 @@ class ActionScheduler_OptionLock extends ActionScheduler_Lock {
|
||||
* @bool True if lock value has changed, false if not or if set failed.
|
||||
*/
|
||||
public function set( $lock_type ) {
|
||||
return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) );
|
||||
global $wpdb;
|
||||
|
||||
$lock_key = $this->get_key( $lock_type );
|
||||
$existing_lock_value = $this->get_existing_lock( $lock_type );
|
||||
$new_lock_value = $this->new_lock_value( $lock_type );
|
||||
|
||||
// The lock may not exist yet, or may have been deleted.
|
||||
if ( empty( $existing_lock_value ) ) {
|
||||
return (bool) $wpdb->insert(
|
||||
$wpdb->options,
|
||||
array(
|
||||
'option_name' => $lock_key,
|
||||
'option_value' => $new_lock_value,
|
||||
'autoload' => 'no',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->get_expiration_from( $existing_lock_value ) >= time() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, try to obtain the lock.
|
||||
return (bool) $wpdb->update(
|
||||
$wpdb->options,
|
||||
array( 'option_value' => $new_lock_value ),
|
||||
array(
|
||||
'option_name' => $lock_key,
|
||||
'option_value' => $existing_lock_value,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +64,30 @@ class ActionScheduler_OptionLock extends ActionScheduler_Lock {
|
||||
* @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
|
||||
*/
|
||||
public function get_expiration( $lock_type ) {
|
||||
return get_option( $this->get_key( $lock_type ) );
|
||||
return $this->get_expiration_from( $this->get_existing_lock( $lock_type ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the lock string, derives the lock expiration timestamp (or false if it cannot be determined).
|
||||
*
|
||||
* @param string $lock_value String containing a timestamp, or pipe-separated combination of unique value and timestamp.
|
||||
*
|
||||
* @return false|int
|
||||
*/
|
||||
private function get_expiration_from( $lock_value ) {
|
||||
$lock_string = explode( '|', $lock_value );
|
||||
|
||||
// Old style lock?
|
||||
if ( count( $lock_string ) === 1 && is_numeric( $lock_string[0] ) ) {
|
||||
return (int) $lock_string[0];
|
||||
}
|
||||
|
||||
// New style lock?
|
||||
if ( count( $lock_string ) === 2 && is_numeric( $lock_string[1] ) ) {
|
||||
return (int) $lock_string[1];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,4 +99,37 @@ class ActionScheduler_OptionLock extends ActionScheduler_Lock {
|
||||
protected function get_key( $lock_type ) {
|
||||
return sprintf( 'action_scheduler_lock_%s', $lock_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplies the existing lock value, or an empty string if not set.
|
||||
*
|
||||
* @param string $lock_type A string to identify different lock types.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_existing_lock( $lock_type ) {
|
||||
global $wpdb;
|
||||
|
||||
// Now grab the existing lock value, if there is one.
|
||||
return (string) $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_value FROM $wpdb->options WHERE option_name = %s",
|
||||
$this->get_key( $lock_type )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplies a lock value consisting of a unique value and the current timestamp, which are separated by a pipe
|
||||
* character.
|
||||
*
|
||||
* Example: (string) "649de012e6b262.09774912|1688068114"
|
||||
*
|
||||
* @param string $lock_type A string to identify different lock types.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function new_lock_value( $lock_type ) {
|
||||
return uniqid( '', true ) . '|' . ( time() + $this->get_duration( $lock_type ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,12 @@ class ActionScheduler_QueueRunner extends ActionScheduler_Abstract_QueueRunner {
|
||||
* should dispatch a request to process pending actions.
|
||||
*/
|
||||
public function maybe_dispatch_async_request() {
|
||||
if ( is_admin() && ! ActionScheduler::lock()->is_locked( 'async-request-runner' ) ) {
|
||||
// Only start an async queue at most once every 60 seconds
|
||||
ActionScheduler::lock()->set( 'async-request-runner' );
|
||||
// Only start an async queue at most once every 60 seconds.
|
||||
if (
|
||||
is_admin()
|
||||
&& ! ActionScheduler::lock()->is_locked( 'async-request-runner' )
|
||||
&& ActionScheduler::lock()->set( 'async-request-runner' )
|
||||
) {
|
||||
$this->async_request->maybe_dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ abstract class ActionScheduler {
|
||||
__( '%s() was called before the Action Scheduler data store was initialized', 'woocommerce' ),
|
||||
esc_attr( $function_name )
|
||||
);
|
||||
error_log( $message );
|
||||
_doing_it_wrong( $function_name, $message, '3.1.6' );
|
||||
}
|
||||
|
||||
return self::$data_store_initialized;
|
||||
|
||||
@@ -26,6 +26,8 @@ abstract class ActionScheduler_Lock {
|
||||
/**
|
||||
* Set a lock.
|
||||
*
|
||||
* To prevent race conditions, implementations should avoid setting the lock if the lock is already held.
|
||||
*
|
||||
* @param string $lock_type A string to identify different lock types.
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
@@ -347,7 +347,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
'hook' => $hook,
|
||||
'status' => self::STATUS_PENDING,
|
||||
'per_page' => 1000,
|
||||
'orderby' => 'action_id',
|
||||
'orderby' => 'none',
|
||||
)
|
||||
);
|
||||
|
||||
@@ -372,7 +372,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
'group' => $group,
|
||||
'status' => self::STATUS_PENDING,
|
||||
'per_page' => 1000,
|
||||
'orderby' => 'action_id',
|
||||
'orderby' => 'none',
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -705,7 +705,7 @@ AND `group_id` = %d
|
||||
array(
|
||||
'per_page' => 1000,
|
||||
'status' => self::STATUS_PENDING,
|
||||
'orderby' => 'action_id',
|
||||
'orderby' => 'none',
|
||||
)
|
||||
);
|
||||
|
||||
@@ -935,7 +935,17 @@ AND `group_id` = %d
|
||||
$sql = $wpdb->prepare( "{$update} {$where} {$order} LIMIT %d", $params ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders
|
||||
$rows_affected = $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
if ( false === $rows_affected ) {
|
||||
throw new \RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) );
|
||||
$error = empty( $wpdb->last_error )
|
||||
? _x( 'unknown', 'database error', 'woocommerce' )
|
||||
: $wpdb->last_error;
|
||||
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
/* translators: %s database error. */
|
||||
__( 'Unable to claim actions. Database error: %s.', 'woocommerce' ),
|
||||
$error
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (int) $rows_affected;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
=== Action Scheduler ===
|
||||
Contributors: Automattic, wpmuguru, claudiosanches, peterfabian1000, vedjain, jamosova, obliviousharmony, konamiman, sadowski, royho, barryhughes-1
|
||||
Tags: scheduler, cron
|
||||
Requires at least: 5.2
|
||||
Tested up to: 6.0
|
||||
Stable tag: 3.6.1
|
||||
Stable tag: 3.6.4
|
||||
License: GPLv3
|
||||
Requires PHP: 5.6
|
||||
Tested up to: 6.3
|
||||
|
||||
Action Scheduler - Job Queue for WordPress
|
||||
|
||||
@@ -47,6 +45,23 @@ Collaboration is cool. We'd love to work with you to improve Action Scheduler. [
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 3.6.4 - 2023-10-11 =
|
||||
* 3.6.3 release.
|
||||
* Fix option lock test.
|
||||
* Fix: Use orderby => 'none' when bulk cancelling actions.
|
||||
* Tweak - WP 6.3 compatibility.
|
||||
* Update PR unit tests matrix.
|
||||
|
||||
= 3.6.3 - 2023-09-13 =
|
||||
* Use `_doing_it_wrong` in initialization check.
|
||||
|
||||
= 3.6.2 - 2023-08-09 =
|
||||
* Add guidance about passing arguments.
|
||||
* Atomic option locking.
|
||||
* Improve bulk delete handling.
|
||||
* Include database error in the exception message.
|
||||
* Tweak - WP 6.3 compatibility.
|
||||
|
||||
= 3.6.1 - 2023-06-14 =
|
||||
* Document new optional `$priority` arg for various API functions.
|
||||
* Document the new `--exclude-groups` WP CLI option.
|
||||
|
||||
Reference in New Issue
Block a user