plugin updates
This commit is contained in:
@@ -8,12 +8,16 @@ use Action_Scheduler\Migration\Controller;
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
abstract class ActionScheduler {
|
||||
/** @var string */
|
||||
private static $plugin_file = '';
|
||||
/** @var ActionScheduler_ActionFactory */
|
||||
private static $factory = NULL;
|
||||
/** @var bool */
|
||||
private static $data_store_initialized = false;
|
||||
|
||||
/**
|
||||
* Factory.
|
||||
*/
|
||||
public static function factory() {
|
||||
if ( !isset(self::$factory) ) {
|
||||
self::$factory = new ActionScheduler_ActionFactory();
|
||||
@@ -21,22 +25,37 @@ abstract class ActionScheduler {
|
||||
return self::$factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Store instance.
|
||||
*/
|
||||
public static function store() {
|
||||
return ActionScheduler_Store::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Lock instance.
|
||||
*/
|
||||
public static function lock() {
|
||||
return ActionScheduler_Lock::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Logger instance.
|
||||
*/
|
||||
public static function logger() {
|
||||
return ActionScheduler_Logger::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get QueueRunner instance.
|
||||
*/
|
||||
public static function runner() {
|
||||
return ActionScheduler_QueueRunner::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AdminView instance.
|
||||
*/
|
||||
public static function admin_view() {
|
||||
return ActionScheduler_AdminView::instance();
|
||||
}
|
||||
@@ -44,13 +63,13 @@ abstract class ActionScheduler {
|
||||
/**
|
||||
* Get the absolute system path to the plugin directory, or a file therein
|
||||
* @static
|
||||
* @param string $path
|
||||
* @param string $path Path relative to plugin directory.
|
||||
* @return string
|
||||
*/
|
||||
public static function plugin_path( $path ) {
|
||||
$base = dirname(self::$plugin_file);
|
||||
if ( $path ) {
|
||||
return trailingslashit($base).$path;
|
||||
return trailingslashit($base) . $path;
|
||||
} else {
|
||||
return untrailingslashit($base);
|
||||
}
|
||||
@@ -59,13 +78,18 @@ abstract class ActionScheduler {
|
||||
/**
|
||||
* Get the absolute URL to the plugin directory, or a file therein
|
||||
* @static
|
||||
* @param string $path
|
||||
* @param string $path Path relative to plugin directory.
|
||||
* @return string
|
||||
*/
|
||||
public static function plugin_url( $path ) {
|
||||
return plugins_url($path, self::$plugin_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload.
|
||||
*
|
||||
* @param string $class Class name.
|
||||
*/
|
||||
public static function autoload( $class ) {
|
||||
$d = DIRECTORY_SEPARATOR;
|
||||
$classes_dir = self::plugin_path( 'classes' . $d );
|
||||
@@ -128,7 +152,7 @@ abstract class ActionScheduler {
|
||||
* Initialize the plugin
|
||||
*
|
||||
* @static
|
||||
* @param string $plugin_file
|
||||
* @param string $plugin_file Plugin file path.
|
||||
*/
|
||||
public static function init( $plugin_file ) {
|
||||
self::$plugin_file = $plugin_file;
|
||||
@@ -149,7 +173,8 @@ abstract class ActionScheduler {
|
||||
|
||||
// Ensure initialization on plugin activation.
|
||||
if ( ! did_action( 'init' ) ) {
|
||||
add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init()
|
||||
// phpcs:ignore Squiz.PHP.CommentedOutCode
|
||||
add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init().
|
||||
add_action( 'init', array( $store, 'init' ), 1, 0 );
|
||||
add_action( 'init', array( $logger, 'init' ), 1, 0 );
|
||||
add_action( 'init', array( $runner, 'init' ), 1, 0 );
|
||||
@@ -308,18 +333,33 @@ abstract class ActionScheduler {
|
||||
return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone.
|
||||
*/
|
||||
final public function __clone() {
|
||||
trigger_error("Singleton. No cloning allowed!", E_USER_ERROR);
|
||||
trigger_error('Singleton. No cloning allowed!', E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wakeup.
|
||||
*/
|
||||
final public function __wakeup() {
|
||||
trigger_error("Singleton. No serialization allowed!", E_USER_ERROR);
|
||||
trigger_error('Singleton. No serialization allowed!', E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*/
|
||||
final private function __construct() {}
|
||||
|
||||
/** Deprecated **/
|
||||
|
||||
/**
|
||||
* Get DateTime object.
|
||||
*
|
||||
* @param null|string $when Date/time string.
|
||||
* @param string $timezone Timezone string.
|
||||
*/
|
||||
public static function get_datetime_object( $when = null, $timezone = 'UTC' ) {
|
||||
_deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' );
|
||||
return as_get_datetime_object( $when, $timezone );
|
||||
|
||||
@@ -27,9 +27,9 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
/**
|
||||
* ActionScheduler_Abstract_QueueRunner constructor.
|
||||
*
|
||||
* @param ActionScheduler_Store $store
|
||||
* @param ActionScheduler_FatalErrorMonitor $monitor
|
||||
* @param ActionScheduler_QueueCleaner $cleaner
|
||||
* @param ActionScheduler_Store $store Store object.
|
||||
* @param ActionScheduler_FatalErrorMonitor $monitor Monitor object.
|
||||
* @param ActionScheduler_QueueCleaner $cleaner Cleaner object.
|
||||
*/
|
||||
public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
|
||||
|
||||
@@ -43,9 +43,10 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
/**
|
||||
* Process an individual action.
|
||||
*
|
||||
* @param int $action_id The action ID to process.
|
||||
* @param int $action_id The action ID to process.
|
||||
* @param string $context Optional identifier for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
|
||||
* Generally, this should be capitalised and not localised as it's a proper noun.
|
||||
* Generally, this should be capitalised and not localised as it's a proper noun.
|
||||
* @throws \Exception When error running action.
|
||||
*/
|
||||
public function process_action( $action_id, $context = '' ) {
|
||||
// Temporarily override the error handler while we process the current action.
|
||||
@@ -141,8 +142,8 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
/**
|
||||
* Schedule the next instance of the action if necessary.
|
||||
*
|
||||
* @param ActionScheduler_Action $action
|
||||
* @param int $action_id
|
||||
* @param ActionScheduler_Action $action Action.
|
||||
* @param int $action_id Action ID.
|
||||
*/
|
||||
protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) {
|
||||
// If a recurring action has been consistently failing, we may wish to stop rescheduling it.
|
||||
@@ -256,7 +257,7 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
|
||||
$time_limit = 30;
|
||||
|
||||
// Apply deprecated filter from deprecated get_maximum_execution_time() method
|
||||
// Apply deprecated filter from deprecated get_maximum_execution_time() method.
|
||||
if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) {
|
||||
_deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' );
|
||||
$time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit );
|
||||
@@ -288,7 +289,7 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
/**
|
||||
* Check if the host's max execution time is (likely) to be exceeded if processing more actions.
|
||||
*
|
||||
* @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
|
||||
* @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action.
|
||||
* @return bool
|
||||
*/
|
||||
protected function time_likely_to_be_exceeded( $processed_actions ) {
|
||||
@@ -318,7 +319,7 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
if ( function_exists( 'ini_get' ) ) {
|
||||
$memory_limit = ini_get( 'memory_limit' );
|
||||
} else {
|
||||
$memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce
|
||||
$memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce.
|
||||
}
|
||||
|
||||
if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) {
|
||||
@@ -353,7 +354,7 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
|
||||
*
|
||||
* Based on WC_Background_Process::batch_limits_exceeded()
|
||||
*
|
||||
* @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
|
||||
* @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action.
|
||||
* @return bool
|
||||
*/
|
||||
protected function batch_limits_exceeded( $processed_actions ) {
|
||||
|
||||
@@ -35,8 +35,8 @@ abstract class ActionScheduler_Abstract_RecurringSchedule extends ActionSchedule
|
||||
protected $recurrence;
|
||||
|
||||
/**
|
||||
* @param DateTime $date The date & time to run the action.
|
||||
* @param mixed $recurrence The data used to determine the schedule's recurrence.
|
||||
* @param DateTime $date The date & time to run the action.
|
||||
* @param mixed $recurrence The data used to determine the schedule's recurrence.
|
||||
* @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
|
||||
*/
|
||||
public function __construct( DateTime $date, $recurrence, DateTime $first = null ) {
|
||||
|
||||
@@ -36,7 +36,7 @@ abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedul
|
||||
/**
|
||||
* Calculate when the next instance of this schedule would run based on a given date & time.
|
||||
*
|
||||
* @param DateTime $after
|
||||
* @param DateTime $after Start timestamp.
|
||||
* @return DateTime
|
||||
*/
|
||||
abstract protected function calculate_next( DateTime $after );
|
||||
@@ -44,7 +44,7 @@ abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedul
|
||||
/**
|
||||
* Get the next date & time when this schedule should run after a given date & time.
|
||||
*
|
||||
* @param DateTime $after
|
||||
* @param DateTime $after Start timestamp.
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function get_next( DateTime $after ) {
|
||||
@@ -76,6 +76,9 @@ abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedul
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wakeup.
|
||||
*/
|
||||
public function __wakeup() {
|
||||
$this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
|
||||
unset( $this->scheduled_timestamp );
|
||||
|
||||
@@ -43,14 +43,14 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
public function register_tables( $force_update = false ) {
|
||||
global $wpdb;
|
||||
|
||||
// make WP aware of our tables
|
||||
// make WP aware of our tables.
|
||||
foreach ( $this->tables as $table ) {
|
||||
$wpdb->tables[] = $table;
|
||||
$name = $this->get_full_table_name( $table );
|
||||
$wpdb->$table = $name;
|
||||
}
|
||||
|
||||
// create the tables
|
||||
// create the tables.
|
||||
if ( $this->schema_update_required() || $force_update ) {
|
||||
foreach ( $this->tables as $table ) {
|
||||
/**
|
||||
@@ -67,7 +67,9 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table The name of the table
|
||||
* Get table definition.
|
||||
*
|
||||
* @param string $table The name of the table.
|
||||
*
|
||||
* @return string The CREATE TABLE statement, suitable for passing to dbDelta
|
||||
*/
|
||||
@@ -84,7 +86,7 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
$option_name = 'schema-' . static::class;
|
||||
$this->db_version = get_option( $option_name, 0 );
|
||||
|
||||
// Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema
|
||||
// Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema.
|
||||
if ( 0 === $this->db_version ) {
|
||||
|
||||
$plugin_option_name = 'schema-';
|
||||
@@ -115,7 +117,7 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
private function mark_schema_update_complete() {
|
||||
$option_name = 'schema-' . static::class;
|
||||
|
||||
// work around race conditions and ensure that our option updates
|
||||
// work around race conditions and ensure that our option updates.
|
||||
$value_to_save = (string) $this->schema_version . '.0.' . time();
|
||||
|
||||
update_option( $option_name, $value_to_save );
|
||||
@@ -124,7 +126,7 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
/**
|
||||
* Update the schema for the given table
|
||||
*
|
||||
* @param string $table The name of the table to update
|
||||
* @param string $table The name of the table to update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -142,7 +144,9 @@ abstract class ActionScheduler_Abstract_Schema {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* Get full table name.
|
||||
*
|
||||
* @param string $table Table name.
|
||||
*
|
||||
* @return string The full name of the table, including the
|
||||
* table prefix for the current blog
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
abstract class ActionScheduler_Logger {
|
||||
|
||||
/** @var null|self */
|
||||
private static $logger = NULL;
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @return ActionScheduler_Logger
|
||||
*/
|
||||
public static function instance() {
|
||||
@@ -19,23 +23,29 @@ abstract class ActionScheduler_Logger {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* @param string $message
|
||||
* @param DateTime $date
|
||||
* Create log entry.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
* @param string $message Log message.
|
||||
* @param DateTime $date Log date.
|
||||
*
|
||||
* @return string The log entry ID
|
||||
*/
|
||||
abstract public function log( $action_id, $message, DateTime $date = NULL );
|
||||
|
||||
/**
|
||||
* @param string $entry_id
|
||||
* Get action's log entry.
|
||||
*
|
||||
* @param string $entry_id Entry ID.
|
||||
*
|
||||
* @return ActionScheduler_LogEntry
|
||||
*/
|
||||
abstract public function get_entry( $entry_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Get action's logs.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*
|
||||
* @return ActionScheduler_LogEntry[]
|
||||
*/
|
||||
@@ -43,6 +53,8 @@ abstract class ActionScheduler_Logger {
|
||||
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function init() {
|
||||
@@ -60,22 +72,44 @@ abstract class ActionScheduler_Logger {
|
||||
add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register callback for storing action.
|
||||
*/
|
||||
public function hook_stored_action() {
|
||||
add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhook callback for storing action.
|
||||
*/
|
||||
public function unhook_stored_action() {
|
||||
remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action stored.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
*/
|
||||
public function log_stored_action( $action_id ) {
|
||||
$this->log( $action_id, __( 'action created', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action cancellation.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
*/
|
||||
public function log_canceled_action( $action_id ) {
|
||||
$this->log( $action_id, __( 'action canceled', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action start.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param string $context Action execution context.
|
||||
*/
|
||||
public function log_started_action( $action_id, $context = '' ) {
|
||||
if ( ! empty( $context ) ) {
|
||||
/* translators: %s: context */
|
||||
@@ -86,6 +120,13 @@ abstract class ActionScheduler_Logger {
|
||||
$this->log( $action_id, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action completion.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param null|ActionScheduler_Action $action Action.
|
||||
* @param string $context Action exeuction context.
|
||||
*/
|
||||
public function log_completed_action( $action_id, $action = NULL, $context = '' ) {
|
||||
if ( ! empty( $context ) ) {
|
||||
/* translators: %s: context */
|
||||
@@ -96,6 +137,13 @@ abstract class ActionScheduler_Logger {
|
||||
$this->log( $action_id, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action failure.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param Exception $exception Exception.
|
||||
* @param string $context Action execution context.
|
||||
*/
|
||||
public function log_failed_action( $action_id, Exception $exception, $context = '' ) {
|
||||
if ( ! empty( $context ) ) {
|
||||
/* translators: 1: context 2: exception message */
|
||||
@@ -107,11 +155,23 @@ abstract class ActionScheduler_Logger {
|
||||
$this->log( $action_id, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action timeout.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param string $timeout Timeout.
|
||||
*/
|
||||
public function log_timed_out_action( $action_id, $timeout ) {
|
||||
/* translators: %s: amount of time */
|
||||
$this->log( $action_id, sprintf( __( 'action marked as failed after %s seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.', 'woocommerce' ), $timeout ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log unexpected shutdown.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param mixed[] $error Error.
|
||||
*/
|
||||
public function log_unexpected_shutdown( $action_id, $error ) {
|
||||
if ( ! empty( $error ) ) {
|
||||
/* translators: 1: error message 2: filename 3: line */
|
||||
@@ -119,10 +179,21 @@ abstract class ActionScheduler_Logger {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log action reset.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
*/
|
||||
public function log_reset_action( $action_id ) {
|
||||
$this->log( $action_id, __( 'action reset', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log ignored action.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param string $context Action execution context.
|
||||
*/
|
||||
public function log_ignored_action( $action_id, $context = '' ) {
|
||||
if ( ! empty( $context ) ) {
|
||||
/* translators: %s: context */
|
||||
@@ -134,10 +205,10 @@ abstract class ActionScheduler_Logger {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* @param Exception|NULL $exception The exception which occurred when fetching the action. NULL by default for backward compatibility.
|
||||
* Log the failure of fetching the action.
|
||||
*
|
||||
* @return ActionScheduler_LogEntry[]
|
||||
* @param string $action_id Action ID.
|
||||
* @param null|Exception $exception The exception which occurred when fetching the action. NULL by default for backward compatibility.
|
||||
*/
|
||||
public function log_failed_fetch_action( $action_id, Exception $exception = NULL ) {
|
||||
|
||||
@@ -151,6 +222,12 @@ abstract class ActionScheduler_Logger {
|
||||
$this->log( $action_id, $log_message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the failure of scheduling the action's next instance.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
* @param Exception $exception Exception object.
|
||||
*/
|
||||
public function log_failed_schedule_next_instance( $action_id, Exception $exception ) {
|
||||
/* translators: %s: exception message */
|
||||
$this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'woocommerce' ), $exception->getMessage() ) );
|
||||
|
||||
@@ -19,17 +19,19 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
protected static $max_args_length = 191;
|
||||
|
||||
/**
|
||||
* @param ActionScheduler_Action $action
|
||||
* @param DateTime $scheduled_date Optional Date of the first instance
|
||||
* to store. Otherwise uses the first date of the action's
|
||||
* schedule.
|
||||
* @param ActionScheduler_Action $action Action to save.
|
||||
* @param null|DateTime $scheduled_date Optional Date of the first instance
|
||||
* to store. Otherwise uses the first date of the action's
|
||||
* schedule.
|
||||
*
|
||||
* @return int The action ID
|
||||
*/
|
||||
abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Get action.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*
|
||||
* @return ActionScheduler_Action
|
||||
*/
|
||||
@@ -141,7 +143,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
public function extra_action_counts() {
|
||||
$extra_actions = array();
|
||||
|
||||
$pastdue_action_counts = ( int ) $this->query_actions( array(
|
||||
$pastdue_action_counts = (int) $this->query_actions( array(
|
||||
'status' => self::STATUS_PENDING,
|
||||
'date' => as_get_datetime_object(),
|
||||
), 'count' );
|
||||
@@ -160,17 +162,23 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Cancel action.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*/
|
||||
abstract public function cancel_action( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Delete action.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*/
|
||||
abstract public function delete_action( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Get action's schedule or run timestamp.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*
|
||||
* @return DateTime The date the action is schedule to run, or the date that it ran.
|
||||
*/
|
||||
@@ -178,7 +186,9 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
|
||||
|
||||
/**
|
||||
* @param int $max_actions
|
||||
* Make a claim.
|
||||
*
|
||||
* @param int $max_actions Maximum number of actions to claim.
|
||||
* @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now.
|
||||
* @param array $hooks Claim only actions with a hook or hooks.
|
||||
* @param string $group Claim only actions in the given group.
|
||||
@@ -188,56 +198,75 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
|
||||
|
||||
/**
|
||||
* Get claim count.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function get_claim_count();
|
||||
|
||||
/**
|
||||
* @param ActionScheduler_ActionClaim $claim
|
||||
* Release the claim.
|
||||
*
|
||||
* @param ActionScheduler_ActionClaim $claim Claim object.
|
||||
*/
|
||||
abstract public function release_claim( ActionScheduler_ActionClaim $claim );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Un-claim the action.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*/
|
||||
abstract public function unclaim_action( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Mark action as failed.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*/
|
||||
abstract public function mark_failure( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Log action's execution.
|
||||
*
|
||||
* @param string $action_id Actoin ID.
|
||||
*/
|
||||
abstract public function log_execution( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Mark action as complete.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
*/
|
||||
abstract public function mark_complete( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Get action's status.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_status( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $action_id
|
||||
* Get action's claim ID.
|
||||
*
|
||||
* @param string $action_id Action ID.
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function get_claim_id( $action_id );
|
||||
|
||||
/**
|
||||
* @param string $claim_id
|
||||
* Find actions by claim ID.
|
||||
*
|
||||
* @param string $claim_id Claim ID.
|
||||
* @return array
|
||||
*/
|
||||
abstract public function find_actions_by_claim_id( $claim_id );
|
||||
|
||||
/**
|
||||
* @param string $comparison_operator
|
||||
* Validate SQL operator.
|
||||
*
|
||||
* @param string $comparison_operator Operator.
|
||||
* @return string
|
||||
*/
|
||||
protected function validate_sql_comparator( $comparison_operator ) {
|
||||
@@ -250,8 +279,8 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
/**
|
||||
* Get the time MySQL formatted date/time string for an action's (next) scheduled date.
|
||||
*
|
||||
* @param ActionScheduler_Action $action
|
||||
* @param DateTime $scheduled_date (optional)
|
||||
* @param ActionScheduler_Action $action Action.
|
||||
* @param null|DateTime $scheduled_date Action's schedule date (optional).
|
||||
* @return string
|
||||
*/
|
||||
protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
|
||||
@@ -267,8 +296,8 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
/**
|
||||
* Get the time MySQL formatted date/time string for an action's (next) scheduled date.
|
||||
*
|
||||
* @param ActionScheduler_Action $action
|
||||
* @param DateTime $scheduled_date (optional)
|
||||
* @param ActionScheduler_Action $action Action.
|
||||
* @param null|DateTime $scheduled_date Action's scheduled date (optional).
|
||||
* @return string
|
||||
*/
|
||||
protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
|
||||
@@ -386,7 +415,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param array $action_ids List of action IDs.
|
||||
* @param int[] $action_ids List of action IDs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -399,7 +428,9 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* Get status labels.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function get_status_labels() {
|
||||
return array(
|
||||
@@ -414,14 +445,12 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
/**
|
||||
* Check if there are any pending scheduled actions due to run.
|
||||
*
|
||||
* @param ActionScheduler_Action $action
|
||||
* @param DateTime $scheduled_date (optional)
|
||||
* @return string
|
||||
*/
|
||||
public function has_pending_actions_due() {
|
||||
$pending_actions = $this->query_actions( array(
|
||||
'date' => as_get_datetime_object(),
|
||||
'status' => ActionScheduler_Store::STATUS_PENDING,
|
||||
'status' => self::STATUS_PENDING,
|
||||
'orderby' => 'none',
|
||||
) );
|
||||
|
||||
@@ -435,6 +464,8 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
|
||||
|
||||
/**
|
||||
* Callable function to mark an action as migrated optionally overridden in derived classes.
|
||||
*
|
||||
* @param int $action_id Action ID.
|
||||
*/
|
||||
public function mark_migrated( $action_id ) {}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* Class ActionScheduler_TimezoneHelper
|
||||
*/
|
||||
abstract class ActionScheduler_TimezoneHelper {
|
||||
|
||||
/** @var null|DateTimeZone */
|
||||
private static $local_timezone = NULL;
|
||||
|
||||
/**
|
||||
@@ -12,12 +14,12 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param DateTime $date
|
||||
* @param DateTime $date Timestamp.
|
||||
* @return ActionScheduler_DateTime
|
||||
*/
|
||||
public static function set_local_timezone( DateTime $date ) {
|
||||
|
||||
// Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime
|
||||
// Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime.
|
||||
if ( ! is_a( $date, 'ActionScheduler_DateTime' ) ) {
|
||||
$date = as_get_datetime_object( $date->format( 'U' ) );
|
||||
}
|
||||
@@ -42,6 +44,7 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
* timezone.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @param bool $reset Unused.
|
||||
* @return string PHP timezone string for the site or empty if no timezone string is available.
|
||||
*/
|
||||
protected static function get_local_timezone_string( $reset = false ) {
|
||||
@@ -75,7 +78,7 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
}
|
||||
}
|
||||
|
||||
// No timezone string
|
||||
// No timezone string.
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -97,6 +100,9 @@ abstract class ActionScheduler_TimezoneHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local timezone.
|
||||
*
|
||||
* @param bool $reset Toggle to discard stored value.
|
||||
* @deprecated 2.1.0
|
||||
*/
|
||||
public static function get_local_timezone( $reset = FALSE ) {
|
||||
|
||||
Reference in New Issue
Block a user