Skip to content

Commit

Permalink
fixup! chore: upgrade action-scheduler library to fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
antoscarface committed Oct 22, 2024
1 parent 1559594 commit b6cba8d
Show file tree
Hide file tree
Showing 61 changed files with 342 additions and 875 deletions.
2 changes: 1 addition & 1 deletion src/libraries/action-scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Action Scheduler is a scalable, traceable job queue for background processing large sets of actions in WordPress. It's specially designed to be distributed in WordPress plugins.

Action Scheduler works by triggering an action hook to run at some time in the future. Each hook can be scheduled with unique data, to allow callbacks to perform operations on that data. The hook can also be scheduled to run on one or more occasions.
Action Scheduler works by triggering an action hook to run at some time in the future. Each hook can be scheduled with unique data, to allow callbacks to perform operations on that data. The hook can also be scheduled to run on one or more occassions.

Think of it like an extension to `do_action()` which adds the ability to delay and repeat a hook.

Expand Down
22 changes: 10 additions & 12 deletions src/libraries/action-scheduler/action-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Description: A robust scheduling library for use in WordPress plugins.
* Author: Automattic
* Author URI: https://automattic.com/
* Version: 3.8.2
* Version: 3.6.4
* License: GPLv3
* Requires at least: 6.4
* Tested up to: 6.6
* Requires PHP: 7.0
* Tested up to: 6.3
* Requires at least: 5.2
* Requires PHP: 5.6
*
* Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)
*
Expand All @@ -29,29 +29,27 @@
* @package ActionScheduler
*/

if ( ! function_exists( 'action_scheduler_register_3_dot_8_dot_2' ) && 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_8_dot_2', 0, 0 ); // WRCS: DEFINED_VERSION.
add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_6_dot_4', 0, 0 ); // WRCS: DEFINED_VERSION.

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Registers this version of Action Scheduler.
*/
function action_scheduler_register_3_dot_8_dot_2() { // WRCS: DEFINED_VERSION.
function action_scheduler_register_3_dot_6_dot_4() { // WRCS: DEFINED_VERSION.
$versions = ActionScheduler_Versions::instance();
$versions->register( '3.8.2', 'action_scheduler_initialize_3_dot_8_dot_2' ); // WRCS: DEFINED_VERSION.
$versions->register( '3.6.4', 'action_scheduler_initialize_3_dot_6_dot_4' ); // WRCS: DEFINED_VERSION.
}

// phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace
/**
* Initializes this version of Action Scheduler.
*/
function action_scheduler_initialize_3_dot_8_dot_2() { // 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).
Expand All @@ -63,7 +61,7 @@ function action_scheduler_initialize_3_dot_8_dot_2() { // WRCS: DEFINED_VERSION.

// 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_8_dot_2(); // 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();
}
Expand Down
52 changes: 6 additions & 46 deletions src/libraries/action-scheduler/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
*** Changelog ***

= 3.8.2 - 2024-09-12 =
* Add missing parameter to the `pre_as_enqueue_async_action` hook.
* Bump minimum PHP version to 7.0.
* Bump minimum WordPress version to 6.4.
* Make the batch size adjustable during processing.

= 3.8.1 - 2024-06-20 =
* Fix typos.
* Improve the messaging in our unidentified action exceptions.

= 3.8.0 - 2024-05-22 =
* Documentation - Fixed typos in perf.md.
* Update - We now require WordPress 6.3 or higher.
* Update - We now require PHP 7.0 or higher.

= 3.7.4 - 2024-04-05 =
* Give a clear description of how the $unique parameter works.
* Preserve the tab field if set.
* Tweak - WP 6.5 compatibility.

= 3.7.3 - 2024-03-20 =
* Do not iterate over all of GET when building form in list table.
* Fix a few issues reported by PCP (Plugin Check Plugin).
* Try to save actions as unique even when the store doesn't support it.
* Tweak - WP 6.4 compatibility.
* Update "Tested up to" tag to WordPress 6.5.
* update version in package-lock.json.

= 3.7.2 - 2024-02-14 =
* No longer user variables in `_n()` translation function.

= 3.7.1 - 2023-12-13 =
* update semver to 5.7.2 because of a security vulnerability in 5.7.1.

= 3.7.0 - 2023-11-20 =
* Important: starting with this release, Action Scheduler follows an L-2 version policy (WordPress, and consequently PHP).
* Add extended indexes for hook_status_scheduled_date_gmt and status_scheduled_date_gmt.
* Catch and log exceptions thrown when actions can't be created, e.g. under a corrupt database schema.
* Tweak - WP 6.4 compatibility.
* Update unit tests for upcoming dependency version policy.
* make sure hook action_scheduler_failed_execution can access original exception object.
* mention dependency version policy in usage.md.

= 3.6.4 - 2023-10-11 =
* Performance improvements when bulk cancelling actions.
* Dev-related fixes.
* 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.
Expand Down Expand Up @@ -131,7 +91,7 @@
* 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 indices (props @glagonikas). #774 & #777
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,20 @@
* Class ActionScheduler_ActionClaim
*/
class ActionScheduler_ActionClaim {
/** @var string */
private $id = '';
/** @var int[] */
private $action_ids = array();

/**
* Construct.
*
* @param string $id Claim ID.
* @param int[] $action_ids Action IDs.
*/
public function __construct( $id, array $action_ids ) {
$this->id = $id;
$this->action_ids = $action_ids;
}

/**
* Get claim ID.
*/
public function get_id() {
return $this->id;
}

/**
* Get IDs of claimed actions.
*/
public function get_actions() {
return $this->action_ids;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ActionScheduler_ActionFactory {
* @param array $args Args to pass to callbacks when the hook is triggered.
* @param ActionScheduler_Schedule $schedule The action's schedule.
* @param string $group A group to put the action in.
* phpcs:ignore Squiz.Commenting.FunctionComment.ExtraParamComment
* @param int $priority The action priority.
*
* @return ActionScheduler_Action An instance of the stored action.
Expand Down Expand Up @@ -246,7 +245,8 @@ public function repeat( $action ) {
* This general purpose method can be used in place of specific methods such as async(),
* async_unique(), single() or single_unique(), etc.
*
* @internal Not intended for public use, should not be overridden by subclasses.
* @internal Not intended for public use, should not be overriden by subclasses.
* @throws Exception May be thrown if invalid options are passed.
*
* @param array $options {
* Describes the action we wish to schedule.
Expand All @@ -263,7 +263,7 @@ public function repeat( $action ) {
* @type int $priority Lower values means higher priority. Should be in the range 0-255.
* }
*
* @return int The action ID. Zero if there was an error scheduling the action.
* @return int
*/
public function create( array $options = array() ) {
$defaults = array(
Expand Down Expand Up @@ -307,27 +307,12 @@ public function create( array $options = array() ) {
break;

default:
error_log( "Unknown action type '{$options['type']}' specified when trying to create an action for '{$options['hook']}'." );
return 0;
throw new Exception( "Unknown action type '{$options['type']}' specified when trying to create an action for '{$options['hook']}'." );
}

$action = new ActionScheduler_Action( $options['hook'], $options['arguments'], $schedule, $options['group'] );
$action->set_priority( $options['priority'] );

$action_id = 0;
try {
$action_id = $options['unique'] ? $this->store_unique_action( $action ) : $this->store( $action );
} catch ( Exception $e ) {
error_log(
sprintf(
/* translators: %1$s is the name of the hook to be enqueued, %2$s is the exception message. */
__( 'Caught exception while enqueuing action "%1$s": %2$s', 'action-scheduler' ),
$options['hook'],
$e->getMessage()
)
);
}
return $action_id;
return $options['unique'] ? $this->store_unique_action( $action ) : $this->store( $action );
}

/**
Expand All @@ -351,26 +336,7 @@ protected function store( ActionScheduler_Action $action ) {
*/
protected function store_unique_action( ActionScheduler_Action $action ) {
$store = ActionScheduler_Store::instance();
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 giving 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 );
}
return method_exists( $store, 'save_unique_action' ) ?
$store->save_unique_action( $action ) : $store->save_action( $action );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/
class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {

/** @var null|self */
private static $admin_view = NULL;

/** @var string */
private static $screen_id = 'tools_page_action-scheduler';

/** @var ActionScheduler_ListTable */
Expand All @@ -30,8 +28,6 @@ public static function instance() {
}

/**
* Initialize.
*
* @codeCoverageIgnore
*/
public function init() {
Expand All @@ -49,9 +45,6 @@ public function init() {
}
}

/**
* Print system status report.
*/
public function system_status_report() {
$table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
$table->render();
Expand Down Expand Up @@ -126,20 +119,20 @@ protected function get_list_table() {
*/
public function maybe_check_pastdue_actions() {

// Filter to prevent checking actions (ex: inappropriate user).
# Filter to prevent checking actions (ex: inappropriate user).
if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) {
return;
}

// Get last check transient.
# Get last check transient.
$last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' );

// If transient exists, we're within interval, so bail.
# If transient exists, we're within interval, so bail.
if ( ! empty( $last_check ) ) {
return;
}

// Perform the check.
# Perform the check.
$this->check_pastdue_actions();
}

Expand All @@ -150,9 +143,9 @@ public function maybe_check_pastdue_actions() {
*/
protected function check_pastdue_actions() {

// Set thresholds.
$threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );
# Set thresholds.
$threshold_seconds = ( int ) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS );
$threshhold_min = ( int ) apply_filters( 'action_scheduler_pastdue_actions_min', 1 );

// Set fallback value for past-due actions count.
$num_pastdue_actions = 0;
Expand All @@ -165,24 +158,24 @@ protected function check_pastdue_actions() {
return;
}

// Scheduled actions query arguments.
# Scheduled actions query arguments.
$query_args = array(
'date' => as_get_datetime_object( time() - $threshold_seconds ),
'status' => ActionScheduler_Store::STATUS_PENDING,
'per_page' => $threshold_min,
'per_page' => $threshhold_min,
);

// If no third-party preempted, run default check.
# If no third-party preempted, run default check.
if ( is_null( $check ) ) {
$store = ActionScheduler_Store::instance();
$num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' );
$num_pastdue_actions = ( int ) $store->query_actions( $query_args, 'count' );

// Check if past-due actions count is greater than or equal to threshold.
$check = ( $num_pastdue_actions >= $threshold_min );
$check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshold_min );
# Check if past-due actions count is greater than or equal to threshold.
$check = ( $num_pastdue_actions >= $threshhold_min );
$check = ( bool ) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min );
}

// If check failed, set transient and abort.
# If check failed, set transient and abort.
if ( ! boolval( $check ) ) {
$interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds );
set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval );
Expand All @@ -196,11 +189,11 @@ protected function check_pastdue_actions() {
'order' => 'asc',
), admin_url( 'tools.php' ) );

// Print notice.
# 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 &raquo;</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 &raquo;</a>',
$num_pastdue_actions,
Expand All @@ -211,7 +204,7 @@ protected function check_pastdue_actions() {
);
echo '</p></div>';

// Facilitate third-parties to evaluate and print notices.
# Facilitate third-parties to evaluate and print notices.
do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args );
}

Expand All @@ -231,7 +224,6 @@ public function add_help_tabs() {
'id' => 'action_scheduler_about',
'title' => __( 'About', 'action-scheduler' ),
'content' =>
// translators: %s is the Action Scheduler version.
'<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $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.', 'action-scheduler' ) .
Expand Down
Loading

0 comments on commit b6cba8d

Please sign in to comment.