From c14774e45a228a10d1deadedea66eb221ad1a079 Mon Sep 17 00:00:00 2001 From: WordPress Fan <146129302+wordpressfan@users.noreply.github.com> Date: Thu, 30 Jan 2025 19:43:26 +0200 Subject: [PATCH] Downgrade Action scheduler to 3.9.0 (#7263) --- composer.json | 2 +- .../ActionScheduler/action-scheduler.php | 16 +- .../ActionScheduler/changelog.txt | 7 - .../classes/ActionScheduler_ActionFactory.php | 14 +- .../classes/ActionScheduler_AdminView.php | 28 +- .../classes/ActionScheduler_Versions.php | 97 ----- .../ActionScheduler_WPCommentCleaner.php | 8 +- .../classes/WP_CLI/Action/Cancel_Command.php | 120 ------ .../classes/WP_CLI/Action/Create_Command.php | 151 -------- .../classes/WP_CLI/Action/Delete_Command.php | 108 ------ .../WP_CLI/Action/Generate_Command.php | 121 ------ .../classes/WP_CLI/Action/Get_Command.php | 75 ---- .../classes/WP_CLI/Action/List_Command.php | 133 ------- .../classes/WP_CLI/Action/Next_Command.php | 71 ---- .../classes/WP_CLI/Action/Run_Command.php | 194 ---------- .../classes/WP_CLI/Action_Command.php | 353 ------------------ .../classes/WP_CLI/System_Command.php | 276 -------------- .../classes/abstracts/ActionScheduler.php | 11 +- .../ActionScheduler_WPCLI_Command.php | 83 ---- .../ActionScheduler_Schedule_Deprecated.php | 2 +- .../lib/cron-expression/CronExpression.php | 2 +- inc/Dependencies/ActionScheduler/readme.txt | 11 +- 22 files changed, 26 insertions(+), 1857 deletions(-) delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Cancel_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Create_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Delete_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Generate_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Get_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/List_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Next_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Run_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/Action_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/WP_CLI/System_Command.php delete mode 100644 inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php diff --git a/composer.json b/composer.json index ee7e1f184e..59757da516 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "psr/container": "1.1.1", "roave/security-advisories": "dev-master", "szepeviktor/phpstan-wordpress": "^1.3", - "woocommerce/action-scheduler": "^3.9", + "woocommerce/action-scheduler": "3.9.0", "wp-coding-standards/wpcs": "^3", "wp-media/background-processing": "^1.3", "wp-media/monolog": "^0.0", diff --git a/inc/Dependencies/ActionScheduler/action-scheduler.php b/inc/Dependencies/ActionScheduler/action-scheduler.php index 4d0839c544..9649e65748 100644 --- a/inc/Dependencies/ActionScheduler/action-scheduler.php +++ b/inc/Dependencies/ActionScheduler/action-scheduler.php @@ -5,10 +5,10 @@ * Description: A robust scheduling library for use in WordPress plugins. * Author: Automattic * Author URI: https://automattic.com/ - * Version: 3.9.1 + * Version: 3.9.0 * License: GPLv3 * Requires at least: 6.5 - * Tested up to: 6.5 + * Tested up to: 6.7 * Requires PHP: 7.1 * * Copyright 2019 Automattic, Inc. (https://automattic.com/contact/) @@ -29,29 +29,29 @@ * @package ActionScheduler */ -if ( ! function_exists( 'action_scheduler_register_3_dot_9_dot_1' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. +if ( ! function_exists( 'action_scheduler_register_3_dot_9_dot_0' ) && 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_9_dot_1', 0, 0 ); // WRCS: DEFINED_VERSION. + add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_9_dot_0', 0, 0 ); // WRCS: DEFINED_VERSION. // phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace /** * Registers this version of Action Scheduler. */ - function action_scheduler_register_3_dot_9_dot_1() { // WRCS: DEFINED_VERSION. + function action_scheduler_register_3_dot_9_dot_0() { // WRCS: DEFINED_VERSION. $versions = ActionScheduler_Versions::instance(); - $versions->register( '3.9.1', 'action_scheduler_initialize_3_dot_9_dot_1' ); // WRCS: DEFINED_VERSION. + $versions->register( '3.9.0', 'action_scheduler_initialize_3_dot_9_dot_0' ); // WRCS: DEFINED_VERSION. } // phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace /** * Initializes this version of Action Scheduler. */ - function action_scheduler_initialize_3_dot_9_dot_1() { // WRCS: DEFINED_VERSION. + function action_scheduler_initialize_3_dot_9_dot_0() { // 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). @@ -63,7 +63,7 @@ function action_scheduler_initialize_3_dot_9_dot_1() { // 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_9_dot_1(); // WRCS: DEFINED_VERSION. + action_scheduler_initialize_3_dot_9_dot_0(); // WRCS: DEFINED_VERSION. do_action( 'action_scheduler_pre_theme_init' ); ActionScheduler_Versions::initialize_latest_version(); } diff --git a/inc/Dependencies/ActionScheduler/changelog.txt b/inc/Dependencies/ActionScheduler/changelog.txt index e42c84e4f2..9e04412606 100644 --- a/inc/Dependencies/ActionScheduler/changelog.txt +++ b/inc/Dependencies/ActionScheduler/changelog.txt @@ -1,12 +1,5 @@ *** Changelog *** -= 3.9.1 - 2025-01-21 = -* A number of new WP CLI commands have been added, making it easier to manage actions in the terminal and from scripts. -* New wp action-scheduler source command to help determine how Action Scheduler is being loaded. -* Additional information about the active instance of Action Scheduler is now available in the Help pull-down drawer. -* Make some other nullable parameters explicitly nullable. -* Set option value to `no` rather than deleting. - = 3.9.0 - 2024-11-14 = * Minimum required version of PHP is now 7.1. * Performance improvements for the `as_pending_actions_due()` function. diff --git a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php index ea60d60ba8..722b60204e 100644 --- a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php +++ b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_ActionFactory.php @@ -8,17 +8,17 @@ class ActionScheduler_ActionFactory { /** * Return stored actions for given params. * - * @param string $status The action's status in the data store. - * @param string $hook The hook to trigger when this action runs. - * @param array $args Args to pass to callbacks when the hook is triggered. - * @param ActionScheduler_Schedule|null $schedule The action's schedule. - * @param string $group A group to put the action in. + * @param string $status The action's status in the data store. + * @param string $hook The hook to trigger when this action runs. + * @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. + * @param int $priority The action priority. * * @return ActionScheduler_Action An instance of the stored action. */ - public function get_stored_action( $status, $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, $group = '' ) { + public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) { // The 6th parameter ($priority) is not formally declared in the method signature to maintain compatibility with // third-party subclasses created before this param was added. $priority = func_num_args() >= 6 ? (int) func_get_arg( 5 ) : 10; diff --git a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_AdminView.php b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_AdminView.php index 0d715f5ba1..6f866547ae 100644 --- a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_AdminView.php +++ b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_AdminView.php @@ -250,20 +250,7 @@ public function add_help_tabs() { return; } - $as_version = ActionScheduler_Versions::instance()->latest_version(); - $as_source = ActionScheduler_Versions::instance()->active_source(); - $as_source_path = ActionScheduler_Versions::instance()->active_source_path(); - $as_source_markup = sprintf( '%s', esc_html( $as_source_path ) ); - - if ( ! empty( $as_source ) ) { - $as_source_markup = sprintf( - '%s: %s', - ucfirst( $as_source['type'] ), - esc_attr( $as_source_path ), - esc_html( $as_source['name'] ) - ); - } - + $as_version = ActionScheduler_Versions::instance()->latest_version(); $screen->add_help_tab( array( 'id' => 'action_scheduler_about', @@ -273,19 +260,6 @@ public function add_help_tabs() { '

' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '

' . '

' . __( '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' ) . - '

' . - '

' . esc_html__( 'Source', 'action-scheduler' ) . '

' . - '

' . - esc_html__( 'Action Scheduler is currently being loaded from the following location. This can be useful when debugging, or if requested by the support team.', 'action-scheduler' ) . - '

' . - '

' . $as_source_markup . '

' . - '

' . esc_html__( 'WP CLI', 'action-scheduler' ) . '

' . - '

' . - sprintf( - /* translators: %1$s is WP CLI command (not translatable) */ - esc_html__( 'WP CLI commands are available: execute %1$s for a list of available commands.', 'action-scheduler' ), - 'wp help action-scheduler' - ) . '

', ) ); diff --git a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_Versions.php b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_Versions.php index 3c7bd26856..4bde88391b 100644 --- a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_Versions.php +++ b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_Versions.php @@ -18,13 +18,6 @@ class ActionScheduler_Versions { */ private $versions = array(); - /** - * Registered sources. - * - * @var array - */ - private $sources = array(); - /** * Register version's callback. * @@ -35,13 +28,7 @@ public function register( $version_string, $initialization_callback ) { if ( isset( $this->versions[ $version_string ] ) ) { return false; } - - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace - $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); - $source = $backtrace[0]['file']; - $this->versions[ $version_string ] = $initialization_callback; - $this->sources[ $source ] = $version_string; return true; } @@ -52,15 +39,6 @@ public function get_versions() { return $this->versions; } - /** - * Get registered sources. - * - * @return array - */ - public function get_sources() { - return $this->sources; - } - /** * Get latest version registered. */ @@ -108,79 +86,4 @@ public static function initialize_latest_version() { $self = self::instance(); call_user_func( $self->latest_version_callback() ); } - - /** - * Returns information about the plugin or theme which contains the current active version - * of Action Scheduler. - * - * If this cannot be determined, or if Action Scheduler is being loaded via some other - * method, then it will return an empty array. Otherwise, if populated, the array will - * look like the following: - * - * [ - * 'type' => 'plugin', # or 'theme' - * 'name' => 'Name', - * ] - * - * @return array - */ - public function active_source(): array { - $file = __FILE__; - $dir = __DIR__; - $plugins = get_plugins(); - $plugin_files = array_keys( $plugins ); - - foreach ( $plugin_files as $plugin_file ) { - $plugin_path = trailingslashit( WP_PLUGIN_DIR ) . dirname( $plugin_file ); - $plugin_file = trailingslashit( WP_PLUGIN_DIR ) . $plugin_file; - - if ( 0 !== strpos( dirname( $dir ), $plugin_path ) ) { - continue; - } - - $plugin_data = get_plugin_data( $plugin_file ); - - if ( ! is_array( $plugin_data ) || empty( $plugin_data['Name'] ) ) { - continue; - } - - return array( - 'type' => 'plugin', - 'name' => $plugin_data['Name'], - ); - } - - $themes = (array) search_theme_directories(); - - foreach ( $themes as $slug => $data ) { - $needle = trailingslashit( $data['theme_root'] ) . $slug . '/'; - - if ( 0 !== strpos( $file, $needle ) ) { - continue; - } - - $theme = wp_get_theme( $slug ); - - if ( ! is_object( $theme ) || ! is_a( $theme, \WP_Theme::class ) ) { - continue; - } - - return array( - 'type' => 'theme', - // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - 'name' => $theme->Name, - ); - } - - return array(); - } - - /** - * Returns the directory path for the currently active installation of Action Scheduler. - * - * @return string - */ - public function active_source_path(): string { - return trailingslashit( dirname( __DIR__ ) ); - } } diff --git a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_WPCommentCleaner.php b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_WPCommentCleaner.php index 2725d1feeb..53015e4584 100644 --- a/inc/Dependencies/ActionScheduler/classes/ActionScheduler_WPCommentCleaner.php +++ b/inc/Dependencies/ActionScheduler/classes/ActionScheduler_WPCommentCleaner.php @@ -66,8 +66,6 @@ public static function has_logs() { * Attached to the migration complete hook 'action_scheduler/migration_complete'. */ public static function maybe_schedule_cleanup() { - $has_logs = 'no'; - $args = array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, @@ -75,14 +73,12 @@ public static function maybe_schedule_cleanup() { ); if ( (bool) get_comments( $args ) ) { - $has_logs = 'yes'; + update_option( self::$has_logs_option_key, 'yes' ); if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) { as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook ); } } - - update_option( self::$has_logs_option_key, $has_logs, true ); } /** @@ -99,7 +95,7 @@ public static function delete_all_action_comments() { ) ); - update_option( self::$has_logs_option_key, 'no', true ); + delete_option( self::$has_logs_option_key ); } /** diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Cancel_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Cancel_Command.php deleted file mode 100644 index e9eb9f2607..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Cancel_Command.php +++ /dev/null @@ -1,120 +0,0 @@ -assoc_args, 'group', '' ); - $callback_args = get_flag_value( $this->assoc_args, 'args', null ); - $all = get_flag_value( $this->assoc_args, 'all', false ); - - if ( ! empty( $this->args[0] ) ) { - $hook = $this->args[0]; - } - - if ( ! empty( $callback_args ) ) { - $callback_args = json_decode( $callback_args, true ); - } - - if ( $all ) { - $this->cancel_all( $hook, $callback_args, $group ); - return; - } - - $this->cancel_single( $hook, $callback_args, $group ); - } - - /** - * Cancel single action. - * - * @param string $hook The hook that the job will trigger. - * @param array $callback_args Args that would have been passed to the job. - * @param string $group The group the job is assigned to. - * @return void - */ - protected function cancel_single( $hook, $callback_args, $group ) { - if ( empty( $hook ) ) { - \WP_CLI::error( __( 'Please specify hook of action to cancel.', 'action-scheduler' ) ); - } - - try { - $result = as_unschedule_action( $hook, $callback_args, $group ); - } catch ( \Exception $e ) { - $this->print_error( $e, false ); - } - - if ( null === $result ) { - $e = new \Exception( __( 'Unable to cancel scheduled action: check the logs.', 'action-scheduler' ) ); - $this->print_error( $e, false ); - } - - $this->print_success( false ); - } - - /** - * Cancel all actions. - * - * @param string $hook The hook that the job will trigger. - * @param array $callback_args Args that would have been passed to the job. - * @param string $group The group the job is assigned to. - * @return void - */ - protected function cancel_all( $hook, $callback_args, $group ) { - if ( empty( $hook ) && empty( $group ) ) { - \WP_CLI::error( __( 'Please specify hook and/or group of actions to cancel.', 'action-scheduler' ) ); - } - - try { - $result = as_unschedule_all_actions( $hook, $callback_args, $group ); - } catch ( \Exception $e ) { - $this->print_error( $e, $multiple ); - } - - /** - * Because as_unschedule_all_actions() does not provide a result, - * neither confirm or deny actions cancelled. - */ - \WP_CLI::success( __( 'Request to cancel scheduled actions completed.', 'action-scheduler' ) ); - } - - /** - * Print a success message. - * - * @return void - */ - protected function print_success() { - \WP_CLI::success( __( 'Scheduled action cancelled.', 'action-scheduler' ) ); - } - - /** - * Convert an exception into a WP CLI error. - * - * @param \Exception $e The error object. - * @param bool $multiple Boolean if multiple actions. - * @throws \WP_CLI\ExitException When an error occurs. - * @return void - */ - protected function print_error( \Exception $e, $multiple ) { - \WP_CLI::error( - sprintf( - /* translators: %1$s: singular or plural %2$s: refers to the exception error message. */ - __( 'There was an error cancelling the %1$s: %2$s', 'action-scheduler' ), - $multiple ? __( 'scheduled actions', 'action-scheduler' ) : __( 'scheduled action', 'action-scheduler' ), - $e->getMessage() - ) - ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Create_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Create_Command.php deleted file mode 100644 index fedd417e23..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Create_Command.php +++ /dev/null @@ -1,151 +0,0 @@ -args[0]; - $schedule_start = $this->args[1]; - $callback_args = get_flag_value( $this->assoc_args, 'args', array() ); - $group = get_flag_value( $this->assoc_args, 'group', '' ); - $interval = absint( get_flag_value( $this->assoc_args, 'interval', 0 ) ); - $cron = get_flag_value( $this->assoc_args, 'cron', '' ); - $unique = get_flag_value( $this->assoc_args, 'unique', false ); - $priority = absint( get_flag_value( $this->assoc_args, 'priority', 10 ) ); - - if ( ! empty( $callback_args ) ) { - $callback_args = json_decode( $callback_args, true ); - } - - $function_args = array( - 'start' => $schedule_start, - 'cron' => $cron, - 'interval' => $interval, - 'hook' => $hook, - 'callback_args' => $callback_args, - 'group' => $group, - 'unique' => $unique, - 'priority' => $priority, - ); - - try { - // Generate schedule start if appropriate. - if ( ! in_array( $schedule_start, static::ASYNC_OPTS, true ) ) { - $schedule_start = as_get_datetime_object( $schedule_start ); - $function_args['start'] = $schedule_start->format( 'U' ); - } - } catch ( \Exception $e ) { - \WP_CLI::error( $e->getMessage() ); - } - - // Default to creating single action. - $action_type = 'single'; - $function = 'as_schedule_single_action'; - - if ( ! empty( $interval ) ) { // Creating recurring action. - $action_type = 'recurring'; - $function = 'as_schedule_recurring_action'; - - $function_args = array_filter( - $function_args, - static function( $key ) { - return in_array( $key, array( 'start', 'interval', 'hook', 'callback_args', 'group', 'unique', 'priority' ), true ); - }, - ARRAY_FILTER_USE_KEY - ); - } elseif ( ! empty( $cron ) ) { // Creating cron action. - $action_type = 'cron'; - $function = 'as_schedule_cron_action'; - - $function_args = array_filter( - $function_args, - static function( $key ) { - return in_array( $key, array( 'start', 'cron', 'hook', 'callback_args', 'group', 'unique', 'priority' ), true ); - }, - ARRAY_FILTER_USE_KEY - ); - } elseif ( in_array( $function_args['start'], static::ASYNC_OPTS, true ) ) { // Enqueue async action. - $action_type = 'async'; - $function = 'as_enqueue_async_action'; - - $function_args = array_filter( - $function_args, - static function( $key ) { - return in_array( $key, array( 'hook', 'callback_args', 'group', 'unique', 'priority' ), true ); - }, - ARRAY_FILTER_USE_KEY - ); - } else { // Enqueue single action. - $function_args = array_filter( - $function_args, - static function( $key ) { - return in_array( $key, array( 'start', 'hook', 'callback_args', 'group', 'unique', 'priority' ), true ); - }, - ARRAY_FILTER_USE_KEY - ); - } - - $function_args = array_values( $function_args ); - - try { - $action_id = call_user_func_array( $function, $function_args ); - } catch ( \Exception $e ) { - $this->print_error( $e ); - } - - if ( 0 === $action_id ) { - $e = new \Exception( __( 'Unable to create a scheduled action.', 'action-scheduler' ) ); - $this->print_error( $e ); - } - - $this->print_success( $action_id, $action_type ); - } - - /** - * Print a success message with the action ID. - * - * @param int $action_id Created action ID. - * @param string $action_type Type of action. - * - * @return void - */ - protected function print_success( $action_id, $action_type ) { - \WP_CLI::success( - sprintf( - /* translators: %1$s: type of action, %2$d: ID of the created action */ - __( '%1$s action (%2$d) scheduled.', 'action-scheduler' ), - ucfirst( $action_type ), - $action_id - ) - ); - } - - /** - * Convert an exception into a WP CLI error. - * - * @param \Exception $e The error object. - * @throws \WP_CLI\ExitException When an error occurs. - * @return void - */ - protected function print_error( \Exception $e ) { - \WP_CLI::error( - sprintf( - /* translators: %s refers to the exception error message. */ - __( 'There was an error creating the scheduled action: %s', 'action-scheduler' ), - $e->getMessage() - ) - ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Delete_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Delete_Command.php deleted file mode 100644 index a549e0b4e8..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Delete_Command.php +++ /dev/null @@ -1,108 +0,0 @@ - - */ - protected $action_counts = array( - 'deleted' => 0, - 'failed' => 0, - 'total' => 0, - ); - - /** - * Construct. - * - * @param string[] $args Positional arguments. - * @param array $assoc_args Keyed arguments. - */ - public function __construct( array $args, array $assoc_args ) { - parent::__construct( $args, $assoc_args ); - - $this->action_ids = array_map( 'absint', $args ); - $this->action_counts['total'] = count( $this->action_ids ); - - add_action( 'action_scheduler_deleted_action', array( $this, 'on_action_deleted' ) ); - } - - /** - * Execute. - * - * @return void - */ - public function execute() { - $store = \ActionScheduler::store(); - - $progress_bar = \WP_CLI\Utils\make_progress_bar( - sprintf( - /* translators: %d: number of actions to be deleted */ - _n( 'Deleting %d action', 'Deleting %d actions', $this->action_counts['total'], 'action-scheduler' ), - number_format_i18n( $this->action_counts['total'] ) - ), - $this->action_counts['total'] - ); - - foreach ( $this->action_ids as $action_id ) { - try { - $store->delete_action( $action_id ); - } catch ( \Exception $e ) { - $this->action_counts['failed']++; - \WP_CLI::warning( $e->getMessage() ); - } - - $progress_bar->tick(); - } - - $progress_bar->finish(); - - /* translators: %1$d: number of actions deleted */ - $format = _n( 'Deleted %1$d action', 'Deleted %1$d actions', $this->action_counts['deleted'], 'action-scheduler' ) . ', '; - /* translators: %2$d: number of actions deletions failed */ - $format .= _n( '%2$d failure.', '%2$d failures.', $this->action_counts['failed'], 'action-scheduler' ); - - \WP_CLI::success( - sprintf( - $format, - number_format_i18n( $this->action_counts['deleted'] ), - number_format_i18n( $this->action_counts['failed'] ) - ) - ); - } - - /** - * Action: action_scheduler_deleted_action - * - * @param int $action_id Action ID. - * @return void - */ - public function on_action_deleted( $action_id ) { - if ( 'action_scheduler_deleted_action' !== current_action() ) { - return; - } - - $action_id = absint( $action_id ); - - if ( ! in_array( $action_id, $this->action_ids, true ) ) { - return; - } - - $this->action_counts['deleted']++; - \WP_CLI::debug( sprintf( 'Action %d was deleted.', $action_id ) ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Generate_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Generate_Command.php deleted file mode 100644 index 6e6e8c77bd..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Generate_Command.php +++ /dev/null @@ -1,121 +0,0 @@ -args[0]; - $schedule_start = $this->args[1]; - $callback_args = get_flag_value( $this->assoc_args, 'args', array() ); - $group = get_flag_value( $this->assoc_args, 'group', '' ); - $interval = (int) get_flag_value( $this->assoc_args, 'interval', 0 ); // avoid absint() to support negative intervals - $count = absint( get_flag_value( $this->assoc_args, 'count', 1 ) ); - - if ( ! empty( $callback_args ) ) { - $callback_args = json_decode( $callback_args, true ); - } - - $schedule_start = as_get_datetime_object( $schedule_start ); - - $function_args = array( - 'start' => absint( $schedule_start->format( 'U' ) ), - 'interval' => $interval, - 'count' => $count, - 'hook' => $hook, - 'callback_args' => $callback_args, - 'group' => $group, - ); - - $function_args = array_values( $function_args ); - - try { - $actions_added = $this->generate( ...$function_args ); - } catch ( \Exception $e ) { - $this->print_error( $e ); - } - - $num_actions_added = count( (array) $actions_added ); - - $this->print_success( $num_actions_added, 'single' ); - } - - /** - * Schedule multiple single actions. - * - * @param int $schedule_start Starting timestamp of first action. - * @param int $interval How long to wait between runs. - * @param int $count Limit number of actions to schedule. - * @param string $hook The hook to trigger. - * @param array $args Arguments to pass when the hook triggers. - * @param string $group The group to assign this job to. - * @return int[] IDs of actions added. - */ - protected function generate( $schedule_start, $interval, $count, $hook, array $args = array(), $group = '' ) { - $actions_added = array(); - - $progress_bar = \WP_CLI\Utils\make_progress_bar( - sprintf( - /* translators: %d is number of actions to create */ - _n( 'Creating %d action', 'Creating %d actions', $count, 'action-scheduler' ), - number_format_i18n( $count ) - ), - $count - ); - - for ( $i = 0; $i < $count; $i++ ) { - $actions_added[] = as_schedule_single_action( $schedule_start + ( $i * $interval ), $hook, $args, $group ); - $progress_bar->tick(); - } - - $progress_bar->finish(); - - return $actions_added; - } - - /** - * Print a success message with the action ID. - * - * @param int $actions_added Number of actions generated. - * @param string $action_type Type of actions scheduled. - * @return void - */ - protected function print_success( $actions_added, $action_type ) { - \WP_CLI::success( - sprintf( - /* translators: %1$d refers to the total number of tasks added, %2$s is the action type */ - _n( '%1$d %2$s action scheduled.', '%1$d %2$s actions scheduled.', $actions_added, 'action-scheduler' ), - number_format_i18n( $actions_added ), - $action_type - ) - ); - } - - /** - * Convert an exception into a WP CLI error. - * - * @param \Exception $e The error object. - * @throws \WP_CLI\ExitException When an error occurs. - * @return void - */ - protected function print_error( \Exception $e ) { - \WP_CLI::error( - sprintf( - /* translators: %s refers to the exception error message. */ - __( 'There was an error creating the scheduled action: %s', 'action-scheduler' ), - $e->getMessage() - ) - ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Get_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Get_Command.php deleted file mode 100644 index 95df595500..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Get_Command.php +++ /dev/null @@ -1,75 +0,0 @@ -args[0]; - $store = \ActionScheduler::store(); - $logger = \ActionScheduler::logger(); - $action = $store->fetch_action( $action_id ); - - if ( is_a( $action, ActionScheduler_NullAction::class ) ) { - /* translators: %d is action ID. */ - \WP_CLI::error( sprintf( esc_html__( 'Unable to retrieve action %d.', 'action-scheduler' ), $action_id ) ); - } - - $only_logs = ! empty( $this->assoc_args['field'] ) && 'log_entries' === $this->assoc_args['field']; - $only_logs = $only_logs || ( ! empty( $this->assoc_args['fields'] && 'log_entries' === $this->assoc_args['fields'] ) ); - $log_entries = array(); - - foreach ( $logger->get_logs( $action_id ) as $log_entry ) { - $log_entries[] = array( - 'date' => $log_entry->get_date()->format( static::DATE_FORMAT ), - 'message' => $log_entry->get_message(), - ); - } - - if ( $only_logs ) { - $args = array( - 'format' => \WP_CLI\Utils\get_flag_value( $this->assoc_args, 'format', 'table' ), - ); - - $formatter = new \WP_CLI\Formatter( $args, array( 'date', 'message' ) ); - $formatter->display_items( $log_entries ); - - return; - } - - try { - $status = $store->get_status( $action_id ); - } catch ( \Exception $e ) { - \WP_CLI::error( $e->getMessage() ); - } - - $action_arr = array( - 'id' => $this->args[0], - 'hook' => $action->get_hook(), - 'status' => $status, - 'args' => $action->get_args(), - 'group' => $action->get_group(), - 'recurring' => $action->get_schedule()->is_recurring() ? 'yes' : 'no', - 'scheduled_date' => $this->get_schedule_display_string( $action->get_schedule() ), - 'log_entries' => $log_entries, - ); - - $fields = array_keys( $action_arr ); - - if ( ! empty( $this->assoc_args['fields'] ) ) { - $fields = explode( ',', $this->assoc_args['fields'] ); - } - - $formatter = new \WP_CLI\Formatter( $this->assoc_args, $fields ); - $formatter->display_item( $action_arr ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/List_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/List_Command.php deleted file mode 100644 index 4a3e0835f7..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/List_Command.php +++ /dev/null @@ -1,133 +0,0 @@ -process_csv_arguments_to_arrays(); - - if ( ! empty( $this->assoc_args['fields'] ) ) { - $fields = $this->assoc_args['fields']; - } - - $formatter = new \WP_CLI\Formatter( $this->assoc_args, $fields ); - $query_args = $this->assoc_args; - - /** - * The `claimed` parameter expects a boolean or integer: - * check for string 'false', and set explicitly to `false` boolean. - */ - if ( array_key_exists( 'claimed', $query_args ) && 'false' === strtolower( $query_args['claimed'] ) ) { - $query_args['claimed'] = false; - } - - $return_format = 'OBJECT'; - - if ( in_array( $formatter->format, array( 'ids', 'count' ), true ) ) { - $return_format = '\'ids\''; - } - - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - $params = var_export( $query_args, true ); - - if ( empty( $query_args ) ) { - $params = 'array()'; - } - - \WP_CLI::debug( - sprintf( - 'as_get_scheduled_actions( %s, %s )', - $params, - $return_format - ) - ); - - if ( ! empty( $query_args['args'] ) ) { - $query_args['args'] = json_decode( $query_args['args'], true ); - } - - switch ( $formatter->format ) { - - case 'ids': - $actions = as_get_scheduled_actions( $query_args, 'ids' ); - echo implode( ' ', $actions ); - break; - - case 'count': - $actions = as_get_scheduled_actions( $query_args, 'ids' ); - $formatter->display_items( $actions ); - break; - - default: - $actions = as_get_scheduled_actions( $query_args, OBJECT ); - - $actions_arr = array(); - - foreach ( $actions as $action_id => $action ) { - $action_arr = array( - 'id' => $action_id, - 'hook' => $action->get_hook(), - 'status' => $store->get_status( $action_id ), - 'args' => $action->get_args(), - 'group' => $action->get_group(), - 'recurring' => $action->get_schedule()->is_recurring() ? 'yes' : 'no', - 'scheduled_date' => $this->get_schedule_display_string( $action->get_schedule() ), - 'log_entries' => array(), - ); - - foreach ( $logger->get_logs( $action_id ) as $log_entry ) { - $action_arr['log_entries'][] = array( - 'date' => $log_entry->get_date()->format( static::DATE_FORMAT ), - 'message' => $log_entry->get_message(), - ); - } - - $actions_arr[] = $action_arr; - } - - $formatter->display_items( $actions_arr ); - break; - - } - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Next_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Next_Command.php deleted file mode 100644 index b71744597c..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Next_Command.php +++ /dev/null @@ -1,71 +0,0 @@ -args[0]; - $group = get_flag_value( $this->assoc_args, 'group', '' ); - $callback_args = get_flag_value( $this->assoc_args, 'args', null ); - $raw = (bool) get_flag_value( $this->assoc_args, 'raw', false ); - - if ( ! empty( $callback_args ) ) { - $callback_args = json_decode( $callback_args, true ); - } - - if ( $raw ) { - \WP_CLI::line( as_next_scheduled_action( $hook, $callback_args, $group ) ); - return; - } - - $params = array( - 'hook' => $hook, - 'orderby' => 'date', - 'order' => 'ASC', - 'group' => $group, - ); - - if ( is_array( $callback_args ) ) { - $params['args'] = $callback_args; - } - - $params['status'] = \ActionScheduler_Store::STATUS_RUNNING; - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - \WP_CLI::debug( 'ActionScheduler()::store()->query_action( ' . var_export( $params, true ) . ' )' ); - - $store = \ActionScheduler::store(); - $action_id = $store->query_action( $params ); - - if ( $action_id ) { - echo $action_id; - return; - } - - $params['status'] = \ActionScheduler_Store::STATUS_PENDING; - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - \WP_CLI::debug( 'ActionScheduler()::store()->query_action( ' . var_export( $params, true ) . ' )' ); - - $action_id = $store->query_action( $params ); - - if ( $action_id ) { - echo $action_id; - return; - } - - \WP_CLI::warning( 'No matching next action.' ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Run_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Run_Command.php deleted file mode 100644 index efff37dd9a..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action/Run_Command.php +++ /dev/null @@ -1,194 +0,0 @@ - - */ - protected $action_counts = array( - 'executed' => 0, - 'failed' => 0, - 'ignored' => 0, - 'invalid' => 0, - 'total' => 0, - ); - - /** - * Construct. - * - * @param string[] $args Positional arguments. - * @param array $assoc_args Keyed arguments. - */ - public function __construct( array $args, array $assoc_args ) { - parent::__construct( $args, $assoc_args ); - - $this->action_ids = array_map( 'absint', $args ); - $this->action_counts['total'] = count( $this->action_ids ); - - add_action( 'action_scheduler_execution_ignored', array( $this, 'on_action_ignored' ) ); - add_action( 'action_scheduler_after_execute', array( $this, 'on_action_executed' ) ); - add_action( 'action_scheduler_failed_execution', array( $this, 'on_action_failed' ), 10, 2 ); - add_action( 'action_scheduler_failed_validation', array( $this, 'on_action_invalid' ), 10, 2 ); - } - - /** - * Execute. - * - * @return void - */ - public function execute() { - $runner = \ActionScheduler::runner(); - - $progress_bar = \WP_CLI\Utils\make_progress_bar( - sprintf( - /* translators: %d: number of actions */ - _n( 'Executing %d action', 'Executing %d actions', $this->action_counts['total'], 'action-scheduler' ), - number_format_i18n( $this->action_counts['total'] ) - ), - $this->action_counts['total'] - ); - - foreach ( $this->action_ids as $action_id ) { - $runner->process_action( $action_id, 'Action Scheduler CLI' ); - $progress_bar->tick(); - } - - $progress_bar->finish(); - - foreach ( array( - 'ignored', - 'invalid', - 'failed', - ) as $type ) { - $count = $this->action_counts[ $type ]; - - if ( empty( $count ) ) { - continue; - } - - /* - * translators: - * %1$d: count of actions evaluated. - * %2$s: type of action evaluated. - */ - $format = _n( '%1$d action %2$s.', '%1$d actions %2$s.', $count, 'action-scheduler' ); - - \WP_CLI::warning( - sprintf( - $format, - number_format_i18n( $count ), - $type - ) - ); - } - - \WP_CLI::success( - sprintf( - /* translators: %d: number of executed actions */ - _n( 'Executed %d action.', 'Executed %d actions.', $this->action_counts['executed'], 'action-scheduler' ), - number_format_i18n( $this->action_counts['executed'] ) - ) - ); - } - - /** - * Action: action_scheduler_execution_ignored - * - * @param int $action_id Action ID. - * @return void - */ - public function on_action_ignored( $action_id ) { - if ( 'action_scheduler_execution_ignored' !== current_action() ) { - return; - } - - $action_id = absint( $action_id ); - - if ( ! in_array( $action_id, $this->action_ids, true ) ) { - return; - } - - $this->action_counts['ignored']++; - \WP_CLI::debug( sprintf( 'Action %d was ignored.', $action_id ) ); - } - - /** - * Action: action_scheduler_after_execute - * - * @param int $action_id Action ID. - * @return void - */ - public function on_action_executed( $action_id ) { - if ( 'action_scheduler_after_execute' !== current_action() ) { - return; - } - - $action_id = absint( $action_id ); - - if ( ! in_array( $action_id, $this->action_ids, true ) ) { - return; - } - - $this->action_counts['executed']++; - \WP_CLI::debug( sprintf( 'Action %d was executed.', $action_id ) ); - } - - /** - * Action: action_scheduler_failed_execution - * - * @param int $action_id Action ID. - * @param \Exception $e Exception. - * @return void - */ - public function on_action_failed( $action_id, \Exception $e ) { - if ( 'action_scheduler_failed_execution' !== current_action() ) { - return; - } - - $action_id = absint( $action_id ); - - if ( ! in_array( $action_id, $this->action_ids, true ) ) { - return; - } - - $this->action_counts['failed']++; - \WP_CLI::debug( sprintf( 'Action %d failed execution: %s', $action_id, $e->getMessage() ) ); - } - - /** - * Action: action_scheduler_failed_validation - * - * @param int $action_id Action ID. - * @param \Exception $e Exception. - * @return void - */ - public function on_action_invalid( $action_id, \Exception $e ) { - if ( 'action_scheduler_failed_validation' !== current_action() ) { - return; - } - - $action_id = absint( $action_id ); - - if ( ! in_array( $action_id, $this->action_ids, true ) ) { - return; - } - - $this->action_counts['invalid']++; - \WP_CLI::debug( sprintf( 'Action %d failed validation: %s', $action_id, $e->getMessage() ) ); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action_Command.php deleted file mode 100644 index b32eea31d7..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/Action_Command.php +++ /dev/null @@ -1,353 +0,0 @@ -] - * : Name of the action hook. - * - * [--group=] - * : The group the job is assigned to. - * - * [--args=] - * : JSON object of arguments assigned to the job. - * --- - * default: [] - * --- - * - * [--all] - * : Cancel all occurrences of a scheduled action. - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function cancel( array $args, array $assoc_args ) { - require_once 'Action/Cancel_Command.php'; - $command = new Action\Cancel_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Creates a new scheduled action. - * - * ## OPTIONS - * - * - * : Name of the action hook. - * - * - * : A unix timestamp representing the date you want the action to start. Also 'async' or 'now' to enqueue an async action. - * - * [--args=] - * : JSON object of arguments to pass to callbacks when the hook triggers. - * --- - * default: [] - * --- - * - * [--cron=] - * : A cron-like schedule string (https://crontab.guru/). - * --- - * default: '' - * --- - * - * [--group=] - * : The group to assign this job to. - * --- - * default: '' - * --- - * - * [--interval=] - * : Number of seconds to wait between runs. - * --- - * default: 0 - * --- - * - * ## EXAMPLES - * - * wp action-scheduler action create hook_async async - * wp action-scheduler action create hook_single 1627147598 - * wp action-scheduler action create hook_recurring 1627148188 --interval=5 - * wp action-scheduler action create hook_cron 1627147655 --cron='5 4 * * *' - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function create( array $args, array $assoc_args ) { - require_once 'Action/Create_Command.php'; - $command = new Action\Create_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Delete existing scheduled action(s). - * - * ## OPTIONS - * - * ... - * : One or more IDs of actions to delete. - * --- - * default: 0 - * --- - * - * ## EXAMPLES - * - * # Delete the action with id 100 - * $ wp action-scheduler action delete 100 - * - * # Delete the actions with ids 100 and 200 - * $ wp action-scheduler action delete 100 200 - * - * # Delete the first five pending actions in 'action-scheduler' group - * $ wp action-scheduler action delete $( wp action-scheduler action list --status=pending --group=action-scheduler --format=ids ) - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function delete( array $args, array $assoc_args ) { - require_once 'Action/Delete_Command.php'; - $command = new Action\Delete_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Generates some scheduled actions. - * - * ## OPTIONS - * - * - * : Name of the action hook. - * - * - * : The Unix timestamp representing the date you want the action to start. - * - * [--count=] - * : Number of actions to create. - * --- - * default: 1 - * --- - * - * [--interval=] - * : Number of seconds to wait between runs. - * --- - * default: 0 - * --- - * - * [--args=] - * : JSON object of arguments to pass to callbacks when the hook triggers. - * --- - * default: [] - * --- - * - * [--group=] - * : The group to assign this job to. - * --- - * default: '' - * --- - * - * ## EXAMPLES - * - * wp action-scheduler action generate test_multiple 1627147598 --count=5 --interval=5 - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function generate( array $args, array $assoc_args ) { - require_once 'Action/Generate_Command.php'; - $command = new Action\Generate_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Get details about a scheduled action. - * - * ## OPTIONS - * - * - * : The ID of the action to get. - * --- - * default: 0 - * --- - * - * [--field=] - * : Instead of returning the whole action, returns the value of a single field. - * - * [--fields=] - * : Limit the output to specific fields (comma-separated). Defaults to all fields. - * - * [--format=] - * : Render output in a particular format. - * --- - * default: table - * options: - * - table - * - csv - * - json - * - yaml - * --- - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function get( array $args, array $assoc_args ) { - require_once 'Action/Get_Command.php'; - $command = new Action\Get_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Get a list of scheduled actions. - * - * Display actions based on all arguments supported by - * [as_get_scheduled_actions()](https://actionscheduler.org/api/#function-reference--as_get_scheduled_actions). - * - * ## OPTIONS - * - * [--=] - * : One or more arguments to pass to as_get_scheduled_actions(). - * - * [--field=] - * : Prints the value of a single property for each action. - * - * [--fields=] - * : Limit the output to specific object properties. - * - * [--format=] - * : Render output in a particular format. - * --- - * default: table - * options: - * - table - * - csv - * - ids - * - json - * - count - * - yaml - * --- - * - * ## AVAILABLE FIELDS - * - * These fields will be displayed by default for each action: - * - * * id - * * hook - * * status - * * group - * * recurring - * * scheduled_date - * - * These fields are optionally available: - * - * * args - * * log_entries - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - * - * @subcommand list - */ - public function subcommand_list( array $args, array $assoc_args ) { - require_once 'Action/List_Command.php'; - $command = new Action\List_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Get logs for a scheduled action. - * - * ## OPTIONS - * - * - * : The ID of the action to get. - * --- - * default: 0 - * --- - * - * @param array $args Positional arguments. - * @return void - */ - public function logs( array $args ) { - $command = sprintf( 'action-scheduler action get %d --field=log_entries', $args[0] ); - WP_CLI::runcommand( $command ); - } - - /** - * Get the ID or timestamp of the next scheduled action. - * - * ## OPTIONS - * - * - * : The hook of the next scheduled action. - * - * [--args=] - * : JSON object of arguments to search for next scheduled action. - * --- - * default: [] - * --- - * - * [--group=] - * : The group to which the next scheduled action is assigned. - * --- - * default: '' - * --- - * - * [--raw] - * : Display the raw output of as_next_scheduled_action() (timestamp or boolean). - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function next( array $args, array $assoc_args ) { - require_once 'Action/Next_Command.php'; - $command = new Action\Next_Command( $args, $assoc_args ); - $command->execute(); - } - - /** - * Run existing scheduled action(s). - * - * ## OPTIONS - * - * ... - * : One or more IDs of actions to run. - * --- - * default: 0 - * --- - * - * ## EXAMPLES - * - * # Run the action with id 100 - * $ wp action-scheduler action run 100 - * - * # Run the actions with ids 100 and 200 - * $ wp action-scheduler action run 100 200 - * - * # Run the first five pending actions in 'action-scheduler' group - * $ wp action-scheduler action run $( wp action-scheduler action list --status=pending --group=action-scheduler --format=ids ) - * - * @param array $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @return void - */ - public function run( array $args, array $assoc_args ) { - require_once 'Action/Run_Command.php'; - $command = new Action\Run_Command( $args, $assoc_args ); - $command->execute(); - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/WP_CLI/System_Command.php b/inc/Dependencies/ActionScheduler/classes/WP_CLI/System_Command.php deleted file mode 100644 index 79f2ae8c66..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/WP_CLI/System_Command.php +++ /dev/null @@ -1,276 +0,0 @@ -store = \ActionScheduler::store(); - } - - /** - * Print in-use data store class. - * - * @param array $args Positional args. - * @param array $assoc_args Keyed args. - * @return void - * - * @subcommand data-store - */ - public function datastore( array $args, array $assoc_args ) { - echo $this->get_current_datastore(); - } - - /** - * Print in-use runner class. - * - * @param array $args Positional args. - * @param array $assoc_args Keyed args. - * @return void - */ - public function runner( array $args, array $assoc_args ) { - echo $this->get_current_runner(); - } - - /** - * Get system status. - * - * @param array $args Positional args. - * @param array $assoc_args Keyed args. - * @return void - */ - public function status( array $args, array $assoc_args ) { - /** - * Get runner status. - * - * @link https://github.com/woocommerce/action-scheduler-disable-default-runner - */ - $runner_enabled = has_action( 'action_scheduler_run_queue', array( \ActionScheduler::runner(), 'run' ) ); - - \WP_CLI::line( sprintf( 'Data store: %s', $this->get_current_datastore() ) ); - \WP_CLI::line( sprintf( 'Runner: %s%s', $this->get_current_runner(), ( $runner_enabled ? '' : ' (disabled)' ) ) ); - \WP_CLI::line( sprintf( 'Version: %s', $this->get_latest_version() ) ); - - $rows = array(); - $action_counts = $this->store->action_counts(); - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $action_counts ) ); - - foreach ( $action_counts as $status => $count ) { - $rows[] = array( - 'status' => $status, - 'count' => $count, - 'oldest' => $oldest_and_newest[ $status ]['oldest'], - 'newest' => $oldest_and_newest[ $status ]['newest'], - ); - } - - $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'status', 'count', 'oldest', 'newest' ) ); - $formatter->display_items( $rows ); - } - - /** - * Display the active version, or all registered versions. - * - * ## OPTIONS - * - * [--all] - * : List all registered versions. - * - * @param array $args Positional args. - * @param array $assoc_args Keyed args. - * @return void - */ - public function version( array $args, array $assoc_args ) { - $all = (bool) get_flag_value( $assoc_args, 'all' ); - $latest = $this->get_latest_version( $instance ); - - if ( ! $all ) { - echo $latest; - \WP_CLI::halt( 0 ); - } - - $instance = \ActionScheduler_Versions::instance(); - $versions = $instance->get_versions(); - $rows = array(); - - foreach ( $versions as $version => $callback ) { - $active = $version === $latest; - - $rows[ $version ] = array( - 'version' => $version, - 'callback' => $callback, - 'active' => $active ? 'yes' : 'no', - ); - } - - uksort( $rows, 'version_compare' ); - - $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'version', 'callback', 'active' ) ); - $formatter->display_items( $rows ); - } - - /** - * Display the current source, or all registered sources. - * - * ## OPTIONS - * - * [--all] - * : List all registered sources. - * - * [--fullpath] - * : List full path of source(s). - * - * @param array $args Positional args. - * @param array $assoc_args Keyed args. - * @uses \ActionScheduler_Versions::get_sources() - * @uses \WP_CLI\Formatter::display_items() - * @uses $this->get_latest_version() - * @return void - */ - public function source( array $args, array $assoc_args ) { - $all = (bool) get_flag_value( $assoc_args, 'all' ); - $fullpath = (bool) get_flag_value( $assoc_args, 'fullpath' ); - $versions = \ActionScheduler_Versions::instance(); - $source = $versions->active_source_path(); - $path = $source; - - if ( ! $fullpath ) { - $path = str_replace( ABSPATH, '', $path ); - } - - if ( ! $all ) { - echo $path; - \WP_CLI::halt( 0 ); - } - - $sources = $versions->get_sources(); - $rows = array(); - - foreach ( $sources as $check_source => $version ) { - $active = dirname( $check_source ) === $source; - $path = $check_source; - - if ( ! $fullpath ) { - $path = str_replace( ABSPATH, '', $path ); - } - - $rows[ $check_source ] = array( - 'source' => $path, - 'version' => $version, - 'active' => $active ? 'yes' : 'no', - ); - } - - ksort( $rows ); - - \WP_CLI::log( PHP_EOL . 'Please note there can only be one unique registered instance of Action Scheduler per ' . PHP_EOL . 'version number, so this list may not include all the currently present copies of ' . PHP_EOL . 'Action Scheduler.' . PHP_EOL ); - - $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'source', 'version', 'active' ) ); - $formatter->display_items( $rows ); - } - - /** - * Get current data store. - * - * @return string - */ - protected function get_current_datastore() { - return get_class( $this->store ); - } - - /** - * Get latest version. - * - * @param null|\ActionScheduler_Versions $instance Versions. - * @return string - */ - protected function get_latest_version( $instance = null ) { - if ( is_null( $instance ) ) { - $instance = \ActionScheduler_Versions::instance(); - } - - return $instance->latest_version(); - } - - /** - * Get current runner. - * - * @return string - */ - protected function get_current_runner() { - return get_class( \ActionScheduler::runner() ); - } - - /** - * Get oldest and newest scheduled dates for a given set of statuses. - * - * @param array $status_keys Set of statuses to find oldest & newest action for. - * @return array - */ - protected function get_oldest_and_newest( $status_keys ) { - $oldest_and_newest = array(); - - foreach ( $status_keys as $status ) { - $oldest_and_newest[ $status ] = array( - 'oldest' => '–', - 'newest' => '–', - ); - - if ( 'in-progress' === $status ) { - continue; - } - - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); - } - - return $oldest_and_newest; - } - - /** - * Get oldest or newest scheduled date for a given status. - * - * @param string $status Action status label/name string. - * @param string $date_type Oldest or Newest. - * @return string - */ - protected function get_action_status_date( $status, $date_type = 'oldest' ) { - $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; - - $args = array( - 'claimed' => false, - 'status' => $status, - 'per_page' => 1, - 'order' => $order, - ); - - $action = $this->store->query_actions( $args ); - - if ( ! empty( $action ) ) { - $date_object = $this->store->get_date( $action[0] ); - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); - } else { - $action_date = '–'; - } - - return $action_date; - } - -} diff --git a/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler.php b/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler.php index 774abb1851..d3d281343e 100644 --- a/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler.php +++ b/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler.php @@ -240,8 +240,6 @@ function () { if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Clean_Command' ); - WP_CLI::add_command( 'action-scheduler action', '\Action_Scheduler\WP_CLI\Action_Command' ); - WP_CLI::add_command( 'action-scheduler', '\Action_Scheduler\WP_CLI\System_Command' ); if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) { $command = new Migration_Command(); $command->register(); @@ -298,7 +296,6 @@ protected static function is_class_abstract( $class ) { 'ActionScheduler_Abstract_Schema' => true, 'ActionScheduler_Store' => true, 'ActionScheduler_TimezoneHelper' => true, - 'ActionScheduler_WPCLI_Command' => true, ); return isset( $abstracts[ $class ] ) && $abstracts[ $class ]; @@ -343,11 +340,9 @@ protected static function is_class_migration( $class ) { */ protected static function is_class_cli( $class ) { static $cli_segments = array( - 'QueueRunner' => true, - 'Command' => true, - 'ProgressBar' => true, - '\Action_Scheduler\WP_CLI\Action_Command' => true, - '\Action_Scheduler\WP_CLI\System_Command' => true, + 'QueueRunner' => true, + 'Command' => true, + 'ProgressBar' => true, ); $segments = explode( '_', $class ); diff --git a/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php b/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php deleted file mode 100644 index 847c109ee6..0000000000 --- a/inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_WPCLI_Command.php +++ /dev/null @@ -1,83 +0,0 @@ - - */ - protected $assoc_args; - - /** - * Construct. - * - * @param string[] $args Positional arguments. - * @param array $assoc_args Keyed arguments. - * @throws \Exception When loading a CLI command file outside of WP CLI context. - */ - public function __construct( array $args, array $assoc_args ) { - if ( ! defined( 'WP_CLI' ) || ! constant( 'WP_CLI' ) ) { - /* translators: %s php class name */ - throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), get_class( $this ) ) ); - } - - $this->args = $args; - $this->assoc_args = $assoc_args; - } - - /** - * Execute command. - */ - abstract public function execute(); - - /** - * Get the scheduled date in a human friendly format. - * - * @see ActionScheduler_ListTable::get_schedule_display_string() - * @param ActionScheduler_Schedule $schedule Schedule. - * @return string - */ - protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { - - $schedule_display_string = ''; - - if ( ! $schedule->get_date() ) { - return '0000-00-00 00:00:00'; - } - - $next_timestamp = $schedule->get_date()->getTimestamp(); - - $schedule_display_string .= $schedule->get_date()->format( static::DATE_FORMAT ); - - return $schedule_display_string; - } - - /** - * Transforms arguments with '__' from CSV into expected arrays. - * - * @see \WP_CLI\CommandWithDBObject::process_csv_arguments_to_arrays() - * @link https://github.com/wp-cli/entity-command/blob/c270cc9a2367cb8f5845f26a6b5e203397c91392/src/WP_CLI/CommandWithDBObject.php#L99 - * @return void - */ - protected function process_csv_arguments_to_arrays() { - foreach ( $this->assoc_args as $k => $v ) { - if ( false !== strpos( $k, '__' ) ) { - $this->assoc_args[ $k ] = explode( ',', $v ); - } - } - } - -} diff --git a/inc/Dependencies/ActionScheduler/deprecated/ActionScheduler_Schedule_Deprecated.php b/inc/Dependencies/ActionScheduler/deprecated/ActionScheduler_Schedule_Deprecated.php index af200bca78..496d67b840 100644 --- a/inc/Dependencies/ActionScheduler/deprecated/ActionScheduler_Schedule_Deprecated.php +++ b/inc/Dependencies/ActionScheduler/deprecated/ActionScheduler_Schedule_Deprecated.php @@ -13,7 +13,7 @@ abstract class ActionScheduler_Schedule_Deprecated implements ActionScheduler_Sc * * @return DateTime|null */ - public function next( ?DateTime $after = null ) { + public function next( DateTime $after = null ) { if ( empty( $after ) ) { $return_value = $this->get_date(); $replacement_method = 'get_date()'; diff --git a/inc/Dependencies/ActionScheduler/lib/cron-expression/CronExpression.php b/inc/Dependencies/ActionScheduler/lib/cron-expression/CronExpression.php index 33040eddfe..7f33c378f9 100644 --- a/inc/Dependencies/ActionScheduler/lib/cron-expression/CronExpression.php +++ b/inc/Dependencies/ActionScheduler/lib/cron-expression/CronExpression.php @@ -54,7 +54,7 @@ class CronExpression * * @return CronExpression */ - public static function factory($expression, ?CronExpression_FieldFactory $fieldFactory = null) + public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null) { $mappings = array( '@yearly' => '0 0 1 1 *', diff --git a/inc/Dependencies/ActionScheduler/readme.txt b/inc/Dependencies/ActionScheduler/readme.txt index 359747638e..ea1897ab2a 100644 --- a/inc/Dependencies/ActionScheduler/readme.txt +++ b/inc/Dependencies/ActionScheduler/readme.txt @@ -1,10 +1,10 @@ === Action Scheduler === Contributors: Automattic, wpmuguru, claudiosanches, peterfabian1000, vedjain, jamosova, obliviousharmony, konamiman, sadowski, royho, barryhughes-1 Tags: scheduler, cron -Stable tag: 3.9.1 +Stable tag: 3.9.0 License: GPLv3 Requires at least: 6.5 -Tested up to: 6.5 +Tested up to: 6.7 Requires PHP: 7.1 Action Scheduler - Job Queue for WordPress @@ -47,13 +47,6 @@ Collaboration is cool. We'd love to work with you to improve Action Scheduler. [ == Changelog == -= 3.9.1 - 2025-01-21 = -* A number of new WP CLI commands have been added, making it easier to manage actions in the terminal and from scripts. -* New wp action-scheduler source command to help determine how Action Scheduler is being loaded. -* Additional information about the active instance of Action Scheduler is now available in the Help pull-down drawer. -* Make some other nullable parameters explicitly nullable. -* Set option value to `no` rather than deleting. - = 3.9.0 - 2024-11-14 = * Minimum required version of PHP is now 7.1. * Performance improvements for the `as_pending_actions_due()` function.