woocommerce/includes/libraries/action-scheduler/classes/ActionScheduler_Store.php

213 lines
5.6 KiB
PHP
Raw Normal View History

<?php
/**
* Class ActionScheduler_Store
* @codeCoverageIgnore
*/
abstract class ActionScheduler_Store {
const STATUS_COMPLETE = 'complete';
const STATUS_PENDING = 'pending';
const STATUS_RUNNING = 'in-progress';
const STATUS_FAILED = 'failed';
const STATUS_CANCELED = 'canceled';
/** @var ActionScheduler_Store */
private static $store = NULL;
/**
* @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.
*
* @return string The action ID
*/
abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
/**
* @param string $action_id
*
* @return ActionScheduler_Action
*/
abstract public function fetch_action( $action_id );
/**
* @param string $hook
* @param array $params
* @return string ID of the next action matching the criteria
*/
abstract public function find_action( $hook, $params = array() );
/**
* @param array $query
* @return array The IDs of actions matching the query
*/
abstract public function query_actions( $query = array() );
/**
* Get a count of all actions in the store, grouped by status
*
* @return array
*/
abstract public function action_counts();
/**
* @param string $action_id
*/
abstract public function cancel_action( $action_id );
/**
* @param string $action_id
*/
abstract public function delete_action( $action_id );
/**
* @param string $action_id
*
* @return DateTime The date the action is schedule to run, or the date that it ran.
*/
abstract public function get_date( $action_id );
/**
* @param int $max_actions
* @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.
*
* @return ActionScheduler_ActionClaim
*/
abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
/**
* @return int
*/
abstract public function get_claim_count();
/**
* @param ActionScheduler_ActionClaim $claim
*/
abstract public function release_claim( ActionScheduler_ActionClaim $claim );
/**
* @param string $action_id
*/
abstract public function unclaim_action( $action_id );
/**
* @param string $action_id
*/
abstract public function mark_failure( $action_id );
/**
* @param string $action_id
*/
abstract public function log_execution( $action_id );
/**
* @param string $action_id
*/
abstract public function mark_complete( $action_id );
/**
* @param string $action_id
*
* @return string
*/
abstract public function get_status( $action_id );
/**
* @param string $action_id
* @return mixed
*/
abstract public function get_claim_id( $action_id );
/**
* @param string $claim_id
* @return array
*/
abstract public function find_actions_by_claim_id( $claim_id );
/**
* @param string $comparison_operator
* @return string
*/
protected function validate_sql_comparator( $comparison_operator ) {
if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) {
return $comparison_operator;
}
return '=';
}
/**
* Get the time MySQL formated date/time string for an action's (next) scheduled date.
*
* @param ActionScheduler_Action $action
* @param DateTime $scheduled_date (optional)
* @return string
*/
protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
$next = null === $scheduled_date ? $action->get_schedule()->next() : $scheduled_date;
if ( ! $next ) {
throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'action-scheduler' ) );
}
$next->setTimezone( new DateTimeZone( 'UTC' ) );
return $next->format( 'Y-m-d H:i:s' );
}
/**
* Get the time MySQL formated date/time string for an action's (next) scheduled date.
*
* @param ActionScheduler_Action $action
* @param DateTime $scheduled_date (optional)
* @return string
*/
protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
$next = null === $scheduled_date ? $action->get_schedule()->next() : $scheduled_date;
if ( ! $next ) {
throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'action-scheduler' ) );
}
Squashed 'includes/libraries/action-scheduler/' changes from bd0277d..963b006 73e9082 Merge pull request #196 from Prospress/version_2_1_0 d9d2a29 Merge pull request #202 from Prospress/issue_179_redux b876d8c Convert DateTime to ActionScheduler_DateTime 3f90172 Use ActionScheduler_DateTime objects rather than DateTime 5843134 Add test for a DateTime object b095094 Merge pull request #201 from Prospress/as_unschedule_all_actions 70e76ab Improve unit tests for as_unschedule_action() c934f4f Add as_unschedule_all_actions() d693b02 Return a value from as_unschedule_action() fb7c07f Update docblock on as_unschedule_action() aef2fce Remove test_local_timezone_offsets_utc() 2d35840 Deprecate get_local_timezone() APIs 3512ad9 Add TimezoneHelper::set_local_timezone() 5024f5c Add TimezoneHelper::get_local_timezone_string() 8e8bffb Add TimezoneHelper::get_local_timezone_offset() a73ccfe Merge pull request #152 from Prospress/handle_bad_args f539880 Add more helper methods to ActionScheduler_DateTime class 7485262 Include last-ditch attempt to find correct timezone mapping c3fb3e5 Update timezone string check b452722 Add Timezone unit tests a6dd57d Handle args that cannot be decoded properly d940ec5 Create Exception interface and InvalidAction exception 959c951 Merge pull request #198 from Prospress/docs_followup 3619fab Fix typos and minor wording tweaks 682bd47 Merge pull request #197 from Prospress/install_docs 09ecfd1 Add Usage docs 3ee8fed Update version to 2.1.0 e8d9073 Merge pull request #194 from Prospress/issue_193 bf377e1 Fix calls to remove_action() 29f5901 Merge pull request #191 from Prospress/issue_176 2ca3735 Merge pull request #192 from Prospress/issue_184 f48341e Only process pending actions b509c89 Add Compatibility::raise_memory_limit() 53ee32c Restore batch processing loop b0347fe Add memory APIs to Abstract_QueueRunner 324e734 Improve ActionScheduler_Logger abstraction be43437 Add Compatibility::convert_hr_to_bytes() 0b33c26 Merge pull request #190 from Prospress/issue_189 00b1d06 Use var_export() for admin list table args column 84ba9b3 Move timing methods to Abstract_QueueRunner 7a93e55 Merge pull request #187 from Prospress/issue_185 e9c3e01 Add ActionScheduler_wpPostStore::validate_action 8dcc262 Merge pull request #186 from Prospress/remove_composer_version 439a1c3 Remove the version from composer.json 2c3c555 Merge pull request #183 from Prospress/issue_182 a57830d Use sanitize_text_field() instead of wc_clean() 354e74c Merge pull request #181 from Prospress/change_function_prefix 93b4ded Use as_ prefix not wc_ prefix for public APIs 350f3ac Merge pull request #177 from Prospress/mention_dependencies_in_readme 850e4d5 Add cautionary note on action dependencies 771e34c Minor readme tweaks git-subtree-dir: includes/libraries/action-scheduler git-subtree-split: 963b00614af83a047724f48bea7d4ee787b48d5b
2018-09-20 02:16:26 +00:00
ActionScheduler_TimezoneHelper::set_local_timezone( $next );
return $next->format( 'Y-m-d H:i:s' );
}
/**
* @return array
*/
public function get_status_labels() {
return array(
self::STATUS_COMPLETE => __( 'Complete', 'action-scheduler' ),
self::STATUS_PENDING => __( 'Pending', 'action-scheduler' ),
self::STATUS_RUNNING => __( 'In-progress', 'action-scheduler' ),
self::STATUS_FAILED => __( 'Failed', 'action-scheduler' ),
self::STATUS_CANCELED => __( 'Canceled', 'action-scheduler' ),
);
}
public function init() {}
/**
* @return ActionScheduler_Store
*/
public static function instance() {
if ( empty(self::$store) ) {
$class = apply_filters('action_scheduler_store_class', 'ActionScheduler_wpPostStore');
self::$store = new $class();
}
return self::$store;
}
Squashed 'includes/libraries/action-scheduler/' changes from bd0277d..963b006 73e9082 Merge pull request #196 from Prospress/version_2_1_0 d9d2a29 Merge pull request #202 from Prospress/issue_179_redux b876d8c Convert DateTime to ActionScheduler_DateTime 3f90172 Use ActionScheduler_DateTime objects rather than DateTime 5843134 Add test for a DateTime object b095094 Merge pull request #201 from Prospress/as_unschedule_all_actions 70e76ab Improve unit tests for as_unschedule_action() c934f4f Add as_unschedule_all_actions() d693b02 Return a value from as_unschedule_action() fb7c07f Update docblock on as_unschedule_action() aef2fce Remove test_local_timezone_offsets_utc() 2d35840 Deprecate get_local_timezone() APIs 3512ad9 Add TimezoneHelper::set_local_timezone() 5024f5c Add TimezoneHelper::get_local_timezone_string() 8e8bffb Add TimezoneHelper::get_local_timezone_offset() a73ccfe Merge pull request #152 from Prospress/handle_bad_args f539880 Add more helper methods to ActionScheduler_DateTime class 7485262 Include last-ditch attempt to find correct timezone mapping c3fb3e5 Update timezone string check b452722 Add Timezone unit tests a6dd57d Handle args that cannot be decoded properly d940ec5 Create Exception interface and InvalidAction exception 959c951 Merge pull request #198 from Prospress/docs_followup 3619fab Fix typos and minor wording tweaks 682bd47 Merge pull request #197 from Prospress/install_docs 09ecfd1 Add Usage docs 3ee8fed Update version to 2.1.0 e8d9073 Merge pull request #194 from Prospress/issue_193 bf377e1 Fix calls to remove_action() 29f5901 Merge pull request #191 from Prospress/issue_176 2ca3735 Merge pull request #192 from Prospress/issue_184 f48341e Only process pending actions b509c89 Add Compatibility::raise_memory_limit() 53ee32c Restore batch processing loop b0347fe Add memory APIs to Abstract_QueueRunner 324e734 Improve ActionScheduler_Logger abstraction be43437 Add Compatibility::convert_hr_to_bytes() 0b33c26 Merge pull request #190 from Prospress/issue_189 00b1d06 Use var_export() for admin list table args column 84ba9b3 Move timing methods to Abstract_QueueRunner 7a93e55 Merge pull request #187 from Prospress/issue_185 e9c3e01 Add ActionScheduler_wpPostStore::validate_action 8dcc262 Merge pull request #186 from Prospress/remove_composer_version 439a1c3 Remove the version from composer.json 2c3c555 Merge pull request #183 from Prospress/issue_182 a57830d Use sanitize_text_field() instead of wc_clean() 354e74c Merge pull request #181 from Prospress/change_function_prefix 93b4ded Use as_ prefix not wc_ prefix for public APIs 350f3ac Merge pull request #177 from Prospress/mention_dependencies_in_readme 850e4d5 Add cautionary note on action dependencies 771e34c Minor readme tweaks git-subtree-dir: includes/libraries/action-scheduler git-subtree-split: 963b00614af83a047724f48bea7d4ee787b48d5b
2018-09-20 02:16:26 +00:00
/**
* Get the site's local time.
*
* @deprecated 2.1.0
* @return DateTimeZone
*/
protected function get_local_timezone() {
_deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
return ActionScheduler_TimezoneHelper::get_local_timezone();
}
}