@@ -5,25 +5,25 @@ |
||
5 | 5 | */ |
6 | 6 | abstract class ActionScheduler_Schedule_Deprecated implements ActionScheduler_Schedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Get the date & time this schedule was created to run, or calculate when it should be run |
|
10 | - * after a given date & time. |
|
11 | - * |
|
12 | - * @param DateTime $after |
|
13 | - * |
|
14 | - * @return DateTime|null |
|
15 | - */ |
|
16 | - public function next( DateTime $after = NULL ) { |
|
17 | - if ( empty( $after ) ) { |
|
18 | - $return_value = $this->get_date(); |
|
19 | - $replacement_method = 'get_date()'; |
|
20 | - } else { |
|
21 | - $return_value = $this->get_next( $after ); |
|
22 | - $replacement_method = 'get_next( $after )'; |
|
23 | - } |
|
8 | + /** |
|
9 | + * Get the date & time this schedule was created to run, or calculate when it should be run |
|
10 | + * after a given date & time. |
|
11 | + * |
|
12 | + * @param DateTime $after |
|
13 | + * |
|
14 | + * @return DateTime|null |
|
15 | + */ |
|
16 | + public function next( DateTime $after = NULL ) { |
|
17 | + if ( empty( $after ) ) { |
|
18 | + $return_value = $this->get_date(); |
|
19 | + $replacement_method = 'get_date()'; |
|
20 | + } else { |
|
21 | + $return_value = $this->get_next( $after ); |
|
22 | + $replacement_method = 'get_next( $after )'; |
|
23 | + } |
|
24 | 24 | |
25 | - _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); |
|
25 | + _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); |
|
26 | 26 | |
27 | - return $return_value; |
|
28 | - } |
|
27 | + return $return_value; |
|
28 | + } |
|
29 | 29 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | * |
14 | 14 | * @return DateTime|null |
15 | 15 | */ |
16 | - public function next( DateTime $after = NULL ) { |
|
17 | - if ( empty( $after ) ) { |
|
16 | + public function next(DateTime $after = NULL) { |
|
17 | + if (empty($after)) { |
|
18 | 18 | $return_value = $this->get_date(); |
19 | 19 | $replacement_method = 'get_date()'; |
20 | 20 | } else { |
21 | - $return_value = $this->get_next( $after ); |
|
21 | + $return_value = $this->get_next($after); |
|
22 | 22 | $replacement_method = 'get_next( $after )'; |
23 | 23 | } |
24 | 24 | |
25 | - _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); |
|
25 | + _deprecated_function(__METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method); |
|
26 | 26 | |
27 | 27 | return $return_value; |
28 | 28 | } |
@@ -6,44 +6,44 @@ |
||
6 | 6 | */ |
7 | 7 | abstract class ActionScheduler_Store_Deprecated { |
8 | 8 | |
9 | - /** |
|
10 | - * Mark an action that failed to fetch correctly as failed. |
|
11 | - * |
|
12 | - * @since 2.2.6 |
|
13 | - * |
|
14 | - * @param int $action_id The ID of the action. |
|
15 | - */ |
|
16 | - public function mark_failed_fetch_action( $action_id ) { |
|
17 | - _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | - self::$store->mark_failure( $action_id ); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Mark an action that failed to fetch correctly as failed. |
|
11 | + * |
|
12 | + * @since 2.2.6 |
|
13 | + * |
|
14 | + * @param int $action_id The ID of the action. |
|
15 | + */ |
|
16 | + public function mark_failed_fetch_action( $action_id ) { |
|
17 | + _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | + self::$store->mark_failure( $action_id ); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Add base hooks |
|
23 | - * |
|
24 | - * @since 2.2.6 |
|
25 | - */ |
|
26 | - protected static function hook() { |
|
27 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
28 | - } |
|
21 | + /** |
|
22 | + * Add base hooks |
|
23 | + * |
|
24 | + * @since 2.2.6 |
|
25 | + */ |
|
26 | + protected static function hook() { |
|
27 | + _deprecated_function( __METHOD__, '3.0.0' ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Remove base hooks |
|
32 | - * |
|
33 | - * @since 2.2.6 |
|
34 | - */ |
|
35 | - protected static function unhook() { |
|
36 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
37 | - } |
|
30 | + /** |
|
31 | + * Remove base hooks |
|
32 | + * |
|
33 | + * @since 2.2.6 |
|
34 | + */ |
|
35 | + protected static function unhook() { |
|
36 | + _deprecated_function( __METHOD__, '3.0.0' ); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the site's local time. |
|
41 | - * |
|
42 | - * @deprecated 2.1.0 |
|
43 | - * @return DateTimeZone |
|
44 | - */ |
|
45 | - protected function get_local_timezone() { |
|
46 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
47 | - return ActionScheduler_TimezoneHelper::get_local_timezone(); |
|
48 | - } |
|
39 | + /** |
|
40 | + * Get the site's local time. |
|
41 | + * |
|
42 | + * @deprecated 2.1.0 |
|
43 | + * @return DateTimeZone |
|
44 | + */ |
|
45 | + protected function get_local_timezone() { |
|
46 | + _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
47 | + return ActionScheduler_TimezoneHelper::get_local_timezone(); |
|
48 | + } |
|
49 | 49 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @param int $action_id The ID of the action. |
15 | 15 | */ |
16 | - public function mark_failed_fetch_action( $action_id ) { |
|
17 | - _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | - self::$store->mark_failure( $action_id ); |
|
16 | + public function mark_failed_fetch_action($action_id) { |
|
17 | + _deprecated_function(__METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()'); |
|
18 | + self::$store->mark_failure($action_id); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @since 2.2.6 |
25 | 25 | */ |
26 | 26 | protected static function hook() { |
27 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
27 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @since 2.2.6 |
34 | 34 | */ |
35 | 35 | protected static function unhook() { |
36 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
36 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return DateTimeZone |
44 | 44 | */ |
45 | 45 | protected function get_local_timezone() { |
46 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
46 | + _deprecated_function(__FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()'); |
|
47 | 47 | return ActionScheduler_TimezoneHelper::get_local_timezone(); |
48 | 48 | } |
49 | 49 | } |
@@ -5,23 +5,23 @@ |
||
5 | 5 | */ |
6 | 6 | abstract class ActionScheduler_Abstract_QueueRunner_Deprecated { |
7 | 7 | |
8 | - /** |
|
9 | - * Get the maximum number of seconds a batch can run for. |
|
10 | - * |
|
11 | - * @deprecated 2.1.1 |
|
12 | - * @return int The number of seconds. |
|
13 | - */ |
|
14 | - protected function get_maximum_execution_time() { |
|
15 | - _deprecated_function( __METHOD__, '2.1.1', 'ActionScheduler_Abstract_QueueRunner::get_time_limit()' ); |
|
8 | + /** |
|
9 | + * Get the maximum number of seconds a batch can run for. |
|
10 | + * |
|
11 | + * @deprecated 2.1.1 |
|
12 | + * @return int The number of seconds. |
|
13 | + */ |
|
14 | + protected function get_maximum_execution_time() { |
|
15 | + _deprecated_function( __METHOD__, '2.1.1', 'ActionScheduler_Abstract_QueueRunner::get_time_limit()' ); |
|
16 | 16 | |
17 | - $maximum_execution_time = 30; |
|
17 | + $maximum_execution_time = 30; |
|
18 | 18 | |
19 | - // Apply deprecated filter |
|
20 | - if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { |
|
21 | - _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); |
|
22 | - $maximum_execution_time = apply_filters( 'action_scheduler_maximum_execution_time', $maximum_execution_time ); |
|
23 | - } |
|
19 | + // Apply deprecated filter |
|
20 | + if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { |
|
21 | + _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); |
|
22 | + $maximum_execution_time = apply_filters( 'action_scheduler_maximum_execution_time', $maximum_execution_time ); |
|
23 | + } |
|
24 | 24 | |
25 | - return absint( $maximum_execution_time ); |
|
26 | - } |
|
25 | + return absint( $maximum_execution_time ); |
|
26 | + } |
|
27 | 27 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | * @return int The number of seconds. |
13 | 13 | */ |
14 | 14 | protected function get_maximum_execution_time() { |
15 | - _deprecated_function( __METHOD__, '2.1.1', 'ActionScheduler_Abstract_QueueRunner::get_time_limit()' ); |
|
15 | + _deprecated_function(__METHOD__, '2.1.1', 'ActionScheduler_Abstract_QueueRunner::get_time_limit()'); |
|
16 | 16 | |
17 | 17 | $maximum_execution_time = 30; |
18 | 18 | |
19 | 19 | // Apply deprecated filter |
20 | - if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) { |
|
21 | - _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' ); |
|
22 | - $maximum_execution_time = apply_filters( 'action_scheduler_maximum_execution_time', $maximum_execution_time ); |
|
20 | + if (has_filter('action_scheduler_maximum_execution_time')) { |
|
21 | + _deprecated_function('action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit'); |
|
22 | + $maximum_execution_time = apply_filters('action_scheduler_maximum_execution_time', $maximum_execution_time); |
|
23 | 23 | } |
24 | 24 | |
25 | - return absint( $maximum_execution_time ); |
|
25 | + return absint($maximum_execution_time); |
|
26 | 26 | } |
27 | 27 | } |
@@ -27,27 +27,27 @@ |
||
27 | 27 | |
28 | 28 | if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_4' ) ) { |
29 | 29 | |
30 | - if ( ! class_exists( 'ActionScheduler_Versions' ) ) { |
|
31 | - require_once( 'classes/ActionScheduler_Versions.php' ); |
|
32 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
33 | - } |
|
30 | + if ( ! class_exists( 'ActionScheduler_Versions' ) ) { |
|
31 | + require_once( 'classes/ActionScheduler_Versions.php' ); |
|
32 | + add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
33 | + } |
|
34 | 34 | |
35 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_4', 0, 0 ); |
|
35 | + add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_4', 0, 0 ); |
|
36 | 36 | |
37 | - function action_scheduler_register_3_dot_1_dot_4() { |
|
38 | - $versions = ActionScheduler_Versions::instance(); |
|
39 | - $versions->register( '3.1.4', 'action_scheduler_initialize_3_dot_1_dot_4' ); |
|
40 | - } |
|
37 | + function action_scheduler_register_3_dot_1_dot_4() { |
|
38 | + $versions = ActionScheduler_Versions::instance(); |
|
39 | + $versions->register( '3.1.4', 'action_scheduler_initialize_3_dot_1_dot_4' ); |
|
40 | + } |
|
41 | 41 | |
42 | - function action_scheduler_initialize_3_dot_1_dot_4() { |
|
43 | - require_once( 'classes/abstracts/ActionScheduler.php' ); |
|
44 | - ActionScheduler::init( __FILE__ ); |
|
45 | - } |
|
42 | + function action_scheduler_initialize_3_dot_1_dot_4() { |
|
43 | + require_once( 'classes/abstracts/ActionScheduler.php' ); |
|
44 | + ActionScheduler::init( __FILE__ ); |
|
45 | + } |
|
46 | 46 | |
47 | - // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
48 | - if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) { |
|
49 | - action_scheduler_initialize_3_dot_1_dot_4(); |
|
50 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
51 | - ActionScheduler_Versions::initialize_latest_version(); |
|
52 | - } |
|
47 | + // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
48 | + if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) { |
|
49 | + action_scheduler_initialize_3_dot_1_dot_4(); |
|
50 | + do_action( 'action_scheduler_pre_theme_init' ); |
|
51 | + ActionScheduler_Versions::initialize_latest_version(); |
|
52 | + } |
|
53 | 53 | } |
@@ -25,29 +25,29 @@ |
||
25 | 25 | * |
26 | 26 | */ |
27 | 27 | |
28 | -if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_4' ) ) { |
|
28 | +if (!function_exists('action_scheduler_register_3_dot_1_dot_4')) { |
|
29 | 29 | |
30 | - if ( ! class_exists( 'ActionScheduler_Versions' ) ) { |
|
31 | - require_once( 'classes/ActionScheduler_Versions.php' ); |
|
32 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
30 | + if (!class_exists('ActionScheduler_Versions')) { |
|
31 | + require_once('classes/ActionScheduler_Versions.php'); |
|
32 | + add_action('plugins_loaded', array('ActionScheduler_Versions', 'initialize_latest_version'), 1, 0); |
|
33 | 33 | } |
34 | 34 | |
35 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_4', 0, 0 ); |
|
35 | + add_action('plugins_loaded', 'action_scheduler_register_3_dot_1_dot_4', 0, 0); |
|
36 | 36 | |
37 | 37 | function action_scheduler_register_3_dot_1_dot_4() { |
38 | 38 | $versions = ActionScheduler_Versions::instance(); |
39 | - $versions->register( '3.1.4', 'action_scheduler_initialize_3_dot_1_dot_4' ); |
|
39 | + $versions->register('3.1.4', 'action_scheduler_initialize_3_dot_1_dot_4'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | function action_scheduler_initialize_3_dot_1_dot_4() { |
43 | - require_once( 'classes/abstracts/ActionScheduler.php' ); |
|
44 | - ActionScheduler::init( __FILE__ ); |
|
43 | + require_once('classes/abstracts/ActionScheduler.php'); |
|
44 | + ActionScheduler::init(__FILE__); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | // Support usage in themes - load this version if no plugin has loaded a version yet. |
48 | - if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) { |
|
48 | + if (did_action('plugins_loaded') && !class_exists('ActionScheduler')) { |
|
49 | 49 | action_scheduler_initialize_3_dot_1_dot_4(); |
50 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
50 | + do_action('action_scheduler_pre_theme_init'); |
|
51 | 51 | ActionScheduler_Versions::initialize_latest_version(); |
52 | 52 | } |
53 | 53 | } |
@@ -4,52 +4,52 @@ |
||
4 | 4 | * Class ActionScheduler_FatalErrorMonitor |
5 | 5 | */ |
6 | 6 | class ActionScheduler_FatalErrorMonitor { |
7 | - /** @var ActionScheduler_ActionClaim */ |
|
8 | - private $claim = NULL; |
|
9 | - /** @var ActionScheduler_Store */ |
|
10 | - private $store = NULL; |
|
11 | - private $action_id = 0; |
|
7 | + /** @var ActionScheduler_ActionClaim */ |
|
8 | + private $claim = NULL; |
|
9 | + /** @var ActionScheduler_Store */ |
|
10 | + private $store = NULL; |
|
11 | + private $action_id = 0; |
|
12 | 12 | |
13 | - public function __construct( ActionScheduler_Store $store ) { |
|
14 | - $this->store = $store; |
|
15 | - } |
|
13 | + public function __construct( ActionScheduler_Store $store ) { |
|
14 | + $this->store = $store; |
|
15 | + } |
|
16 | 16 | |
17 | - public function attach( ActionScheduler_ActionClaim $claim ) { |
|
18 | - $this->claim = $claim; |
|
19 | - add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
20 | - add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); |
|
21 | - add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); |
|
22 | - add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); |
|
23 | - add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 ); |
|
24 | - } |
|
17 | + public function attach( ActionScheduler_ActionClaim $claim ) { |
|
18 | + $this->claim = $claim; |
|
19 | + add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
20 | + add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); |
|
21 | + add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); |
|
22 | + add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); |
|
23 | + add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 ); |
|
24 | + } |
|
25 | 25 | |
26 | - public function detach() { |
|
27 | - $this->claim = NULL; |
|
28 | - $this->untrack_action(); |
|
29 | - remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
30 | - remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); |
|
31 | - remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); |
|
32 | - remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); |
|
33 | - remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 ); |
|
34 | - } |
|
26 | + public function detach() { |
|
27 | + $this->claim = NULL; |
|
28 | + $this->untrack_action(); |
|
29 | + remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
30 | + remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); |
|
31 | + remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); |
|
32 | + remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); |
|
33 | + remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function track_current_action( $action_id ) { |
|
37 | - $this->action_id = $action_id; |
|
38 | - } |
|
36 | + public function track_current_action( $action_id ) { |
|
37 | + $this->action_id = $action_id; |
|
38 | + } |
|
39 | 39 | |
40 | - public function untrack_action() { |
|
41 | - $this->action_id = 0; |
|
42 | - } |
|
40 | + public function untrack_action() { |
|
41 | + $this->action_id = 0; |
|
42 | + } |
|
43 | 43 | |
44 | - public function handle_unexpected_shutdown() { |
|
45 | - if ( $error = error_get_last() ) { |
|
46 | - if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { |
|
47 | - if ( !empty($this->action_id) ) { |
|
48 | - $this->store->mark_failure( $this->action_id ); |
|
49 | - do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); |
|
50 | - } |
|
51 | - } |
|
52 | - $this->store->release_claim( $this->claim ); |
|
53 | - } |
|
54 | - } |
|
44 | + public function handle_unexpected_shutdown() { |
|
45 | + if ( $error = error_get_last() ) { |
|
46 | + if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { |
|
47 | + if ( !empty($this->action_id) ) { |
|
48 | + $this->store->mark_failure( $this->action_id ); |
|
49 | + do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); |
|
50 | + } |
|
51 | + } |
|
52 | + $this->store->release_claim( $this->claim ); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | private $store = NULL; |
11 | 11 | private $action_id = 0; |
12 | 12 | |
13 | - public function __construct( ActionScheduler_Store $store ) { |
|
13 | + public function __construct(ActionScheduler_Store $store) { |
|
14 | 14 | $this->store = $store; |
15 | 15 | } |
16 | 16 | |
17 | - public function attach( ActionScheduler_ActionClaim $claim ) { |
|
17 | + public function attach(ActionScheduler_ActionClaim $claim) { |
|
18 | 18 | $this->claim = $claim; |
19 | - add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
20 | - add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 ); |
|
21 | - add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 ); |
|
22 | - add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 ); |
|
23 | - add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 ); |
|
19 | + add_action('shutdown', array($this, 'handle_unexpected_shutdown')); |
|
20 | + add_action('action_scheduler_before_execute', array($this, 'track_current_action'), 0, 1); |
|
21 | + add_action('action_scheduler_after_execute', array($this, 'untrack_action'), 0, 0); |
|
22 | + add_action('action_scheduler_execution_ignored', array($this, 'untrack_action'), 0, 0); |
|
23 | + add_action('action_scheduler_failed_execution', array($this, 'untrack_action'), 0, 0); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function detach() { |
27 | 27 | $this->claim = NULL; |
28 | 28 | $this->untrack_action(); |
29 | - remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) ); |
|
30 | - remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 ); |
|
31 | - remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 ); |
|
32 | - remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 ); |
|
33 | - remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 ); |
|
29 | + remove_action('shutdown', array($this, 'handle_unexpected_shutdown')); |
|
30 | + remove_action('action_scheduler_before_execute', array($this, 'track_current_action'), 0); |
|
31 | + remove_action('action_scheduler_after_execute', array($this, 'untrack_action'), 0); |
|
32 | + remove_action('action_scheduler_execution_ignored', array($this, 'untrack_action'), 0); |
|
33 | + remove_action('action_scheduler_failed_execution', array($this, 'untrack_action'), 0); |
|
34 | 34 | } |
35 | 35 | |
36 | - public function track_current_action( $action_id ) { |
|
36 | + public function track_current_action($action_id) { |
|
37 | 37 | $this->action_id = $action_id; |
38 | 38 | } |
39 | 39 | |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | public function handle_unexpected_shutdown() { |
45 | - if ( $error = error_get_last() ) { |
|
46 | - if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { |
|
47 | - if ( !empty($this->action_id) ) { |
|
48 | - $this->store->mark_failure( $this->action_id ); |
|
49 | - do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error ); |
|
45 | + if ($error = error_get_last()) { |
|
46 | + if (in_array($error['type'], array(E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR))) { |
|
47 | + if (!empty($this->action_id)) { |
|
48 | + $this->store->mark_failure($this->action_id); |
|
49 | + do_action('action_scheduler_unexpected_shutdown', $this->action_id, $error); |
|
50 | 50 | } |
51 | 51 | } |
52 | - $this->store->release_claim( $this->claim ); |
|
52 | + $this->store->release_claim($this->claim); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -5,95 +5,95 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_wcSystemStatus { |
7 | 7 | |
8 | - /** |
|
9 | - * The active data stores |
|
10 | - * |
|
11 | - * @var ActionScheduler_Store |
|
12 | - */ |
|
13 | - protected $store; |
|
14 | - |
|
15 | - function __construct( $store ) { |
|
16 | - $this->store = $store; |
|
17 | - } |
|
18 | - |
|
19 | - /** |
|
20 | - * Display action data, including number of actions grouped by status and the oldest & newest action in each status. |
|
21 | - * |
|
22 | - * Helpful to identify issues, like a clogged queue. |
|
23 | - */ |
|
24 | - public function render() { |
|
25 | - $action_counts = $this->store->action_counts(); |
|
26 | - $status_labels = $this->store->get_status_labels(); |
|
27 | - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
28 | - |
|
29 | - $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Get oldest and newest scheduled dates for a given set of statuses. |
|
34 | - * |
|
35 | - * @param array $status_keys Set of statuses to find oldest & newest action for. |
|
36 | - * @return array |
|
37 | - */ |
|
38 | - protected function get_oldest_and_newest( $status_keys ) { |
|
39 | - |
|
40 | - $oldest_and_newest = array(); |
|
41 | - |
|
42 | - foreach ( $status_keys as $status ) { |
|
43 | - $oldest_and_newest[ $status ] = array( |
|
44 | - 'oldest' => '–', |
|
45 | - 'newest' => '–', |
|
46 | - ); |
|
47 | - |
|
48 | - if ( 'in-progress' === $status ) { |
|
49 | - continue; |
|
50 | - } |
|
51 | - |
|
52 | - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
53 | - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
54 | - } |
|
55 | - |
|
56 | - return $oldest_and_newest; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Get oldest or newest scheduled date for a given status. |
|
61 | - * |
|
62 | - * @param string $status Action status label/name string. |
|
63 | - * @param string $date_type Oldest or Newest. |
|
64 | - * @return DateTime |
|
65 | - */ |
|
66 | - protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
67 | - |
|
68 | - $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
|
69 | - |
|
70 | - $action = $this->store->query_actions( array( |
|
71 | - 'claimed' => false, |
|
72 | - 'status' => $status, |
|
73 | - 'per_page' => 1, |
|
74 | - 'order' => $order, |
|
75 | - ) ); |
|
76 | - |
|
77 | - if ( ! empty( $action ) ) { |
|
78 | - $date_object = $this->store->get_date( $action[0] ); |
|
79 | - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
80 | - } else { |
|
81 | - $action_date = '–'; |
|
82 | - } |
|
83 | - |
|
84 | - return $action_date; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get oldest or newest scheduled date for a given status. |
|
89 | - * |
|
90 | - * @param array $status_labels Set of statuses to find oldest & newest action for. |
|
91 | - * @param array $action_counts Number of actions grouped by status. |
|
92 | - * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
|
93 | - */ |
|
94 | - protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
95 | - $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
96 | - ?> |
|
8 | + /** |
|
9 | + * The active data stores |
|
10 | + * |
|
11 | + * @var ActionScheduler_Store |
|
12 | + */ |
|
13 | + protected $store; |
|
14 | + |
|
15 | + function __construct( $store ) { |
|
16 | + $this->store = $store; |
|
17 | + } |
|
18 | + |
|
19 | + /** |
|
20 | + * Display action data, including number of actions grouped by status and the oldest & newest action in each status. |
|
21 | + * |
|
22 | + * Helpful to identify issues, like a clogged queue. |
|
23 | + */ |
|
24 | + public function render() { |
|
25 | + $action_counts = $this->store->action_counts(); |
|
26 | + $status_labels = $this->store->get_status_labels(); |
|
27 | + $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
28 | + |
|
29 | + $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Get oldest and newest scheduled dates for a given set of statuses. |
|
34 | + * |
|
35 | + * @param array $status_keys Set of statuses to find oldest & newest action for. |
|
36 | + * @return array |
|
37 | + */ |
|
38 | + protected function get_oldest_and_newest( $status_keys ) { |
|
39 | + |
|
40 | + $oldest_and_newest = array(); |
|
41 | + |
|
42 | + foreach ( $status_keys as $status ) { |
|
43 | + $oldest_and_newest[ $status ] = array( |
|
44 | + 'oldest' => '–', |
|
45 | + 'newest' => '–', |
|
46 | + ); |
|
47 | + |
|
48 | + if ( 'in-progress' === $status ) { |
|
49 | + continue; |
|
50 | + } |
|
51 | + |
|
52 | + $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
53 | + $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
54 | + } |
|
55 | + |
|
56 | + return $oldest_and_newest; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Get oldest or newest scheduled date for a given status. |
|
61 | + * |
|
62 | + * @param string $status Action status label/name string. |
|
63 | + * @param string $date_type Oldest or Newest. |
|
64 | + * @return DateTime |
|
65 | + */ |
|
66 | + protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
67 | + |
|
68 | + $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
|
69 | + |
|
70 | + $action = $this->store->query_actions( array( |
|
71 | + 'claimed' => false, |
|
72 | + 'status' => $status, |
|
73 | + 'per_page' => 1, |
|
74 | + 'order' => $order, |
|
75 | + ) ); |
|
76 | + |
|
77 | + if ( ! empty( $action ) ) { |
|
78 | + $date_object = $this->store->get_date( $action[0] ); |
|
79 | + $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
80 | + } else { |
|
81 | + $action_date = '–'; |
|
82 | + } |
|
83 | + |
|
84 | + return $action_date; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get oldest or newest scheduled date for a given status. |
|
89 | + * |
|
90 | + * @param array $status_labels Set of statuses to find oldest & newest action for. |
|
91 | + * @param array $action_counts Number of actions grouped by status. |
|
92 | + * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
|
93 | + */ |
|
94 | + protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
95 | + $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | <table class="wc_status_table widefat" cellspacing="0"> |
99 | 99 | <thead> |
@@ -114,39 +114,39 @@ discard block |
||
114 | 114 | </thead> |
115 | 115 | <tbody> |
116 | 116 | <?php |
117 | - foreach ( $action_counts as $status => $count ) { |
|
118 | - // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
|
119 | - printf( |
|
120 | - '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
|
121 | - esc_html( $status_labels[ $status ] ), |
|
122 | - number_format_i18n( $count ), |
|
123 | - $oldest_and_newest[ $status ]['oldest'], |
|
124 | - $oldest_and_newest[ $status ]['newest'] |
|
125 | - ); |
|
126 | - } |
|
127 | - ?> |
|
117 | + foreach ( $action_counts as $status => $count ) { |
|
118 | + // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
|
119 | + printf( |
|
120 | + '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
|
121 | + esc_html( $status_labels[ $status ] ), |
|
122 | + number_format_i18n( $count ), |
|
123 | + $oldest_and_newest[ $status ]['oldest'], |
|
124 | + $oldest_and_newest[ $status ]['newest'] |
|
125 | + ); |
|
126 | + } |
|
127 | + ?> |
|
128 | 128 | </tbody> |
129 | 129 | </table> |
130 | 130 | |
131 | 131 | <?php |
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * is triggered when invoking inaccessible methods in an object context. |
|
136 | - * |
|
137 | - * @param string $name |
|
138 | - * @param array $arguments |
|
139 | - * |
|
140 | - * @return mixed |
|
141 | - * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
|
142 | - */ |
|
143 | - public function __call( $name, $arguments ) { |
|
144 | - switch ( $name ) { |
|
145 | - case 'print': |
|
146 | - _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
147 | - return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
148 | - } |
|
149 | - |
|
150 | - return null; |
|
151 | - } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * is triggered when invoking inaccessible methods in an object context. |
|
136 | + * |
|
137 | + * @param string $name |
|
138 | + * @param array $arguments |
|
139 | + * |
|
140 | + * @return mixed |
|
141 | + * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
|
142 | + */ |
|
143 | + public function __call( $name, $arguments ) { |
|
144 | + switch ( $name ) { |
|
145 | + case 'print': |
|
146 | + _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
147 | + return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
148 | + } |
|
149 | + |
|
150 | + return null; |
|
151 | + } |
|
152 | 152 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | protected $store; |
14 | 14 | |
15 | - function __construct( $store ) { |
|
15 | + function __construct($store) { |
|
16 | 16 | $this->store = $store; |
17 | 17 | } |
18 | 18 | |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | public function render() { |
25 | 25 | $action_counts = $this->store->action_counts(); |
26 | 26 | $status_labels = $this->store->get_status_labels(); |
27 | - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
27 | + $oldest_and_newest = $this->get_oldest_and_newest(array_keys($status_labels)); |
|
28 | 28 | |
29 | - $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
29 | + $this->get_template($status_labels, $action_counts, $oldest_and_newest); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,22 +35,22 @@ discard block |
||
35 | 35 | * @param array $status_keys Set of statuses to find oldest & newest action for. |
36 | 36 | * @return array |
37 | 37 | */ |
38 | - protected function get_oldest_and_newest( $status_keys ) { |
|
38 | + protected function get_oldest_and_newest($status_keys) { |
|
39 | 39 | |
40 | 40 | $oldest_and_newest = array(); |
41 | 41 | |
42 | - foreach ( $status_keys as $status ) { |
|
43 | - $oldest_and_newest[ $status ] = array( |
|
42 | + foreach ($status_keys as $status) { |
|
43 | + $oldest_and_newest[$status] = array( |
|
44 | 44 | 'oldest' => '–', |
45 | 45 | 'newest' => '–', |
46 | 46 | ); |
47 | 47 | |
48 | - if ( 'in-progress' === $status ) { |
|
48 | + if ('in-progress' === $status) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 | |
52 | - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
53 | - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
52 | + $oldest_and_newest[$status]['oldest'] = $this->get_action_status_date($status, 'oldest'); |
|
53 | + $oldest_and_newest[$status]['newest'] = $this->get_action_status_date($status, 'newest'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $oldest_and_newest; |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | * @param string $date_type Oldest or Newest. |
64 | 64 | * @return DateTime |
65 | 65 | */ |
66 | - protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
66 | + protected function get_action_status_date($status, $date_type = 'oldest') { |
|
67 | 67 | |
68 | 68 | $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
69 | 69 | |
70 | - $action = $this->store->query_actions( array( |
|
70 | + $action = $this->store->query_actions(array( |
|
71 | 71 | 'claimed' => false, |
72 | 72 | 'status' => $status, |
73 | 73 | 'per_page' => 1, |
74 | 74 | 'order' => $order, |
75 | - ) ); |
|
75 | + )); |
|
76 | 76 | |
77 | - if ( ! empty( $action ) ) { |
|
78 | - $date_object = $this->store->get_date( $action[0] ); |
|
79 | - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
77 | + if (!empty($action)) { |
|
78 | + $date_object = $this->store->get_date($action[0]); |
|
79 | + $action_date = $date_object->format('Y-m-d H:i:s O'); |
|
80 | 80 | } else { |
81 | 81 | $action_date = '–'; |
82 | 82 | } |
@@ -91,37 +91,37 @@ discard block |
||
91 | 91 | * @param array $action_counts Number of actions grouped by status. |
92 | 92 | * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
93 | 93 | */ |
94 | - protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
94 | + protected function get_template($status_labels, $action_counts, $oldest_and_newest) { |
|
95 | 95 | $as_version = ActionScheduler_Versions::instance()->latest_version(); |
96 | 96 | ?> |
97 | 97 | |
98 | 98 | <table class="wc_status_table widefat" cellspacing="0"> |
99 | 99 | <thead> |
100 | 100 | <tr> |
101 | - <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows scheduled action counts.', 'action-scheduler' ) ); ?></h2></th> |
|
101 | + <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e('Action Scheduler', 'action-scheduler'); ?><?php echo wc_help_tip(esc_html__('This section shows scheduled action counts.', 'action-scheduler')); ?></h2></th> |
|
102 | 102 | </tr> |
103 | 103 | <tr> |
104 | - <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'action-scheduler' ); ?></td> |
|
105 | - <td colspan="3"><?php echo esc_html( $as_version ); ?></td> |
|
104 | + <td colspan="2" data-export-label="Version"><?php esc_html_e('Version:', 'action-scheduler'); ?></td> |
|
105 | + <td colspan="3"><?php echo esc_html($as_version); ?></td> |
|
106 | 106 | </tr> |
107 | 107 | <tr> |
108 | - <td><strong><?php esc_html_e( 'Action Status', 'action-scheduler' ); ?></strong></td> |
|
108 | + <td><strong><?php esc_html_e('Action Status', 'action-scheduler'); ?></strong></td> |
|
109 | 109 | <td class="help"> </td> |
110 | - <td><strong><?php esc_html_e( 'Count', 'action-scheduler' ); ?></strong></td> |
|
111 | - <td><strong><?php esc_html_e( 'Oldest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
|
112 | - <td><strong><?php esc_html_e( 'Newest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
|
110 | + <td><strong><?php esc_html_e('Count', 'action-scheduler'); ?></strong></td> |
|
111 | + <td><strong><?php esc_html_e('Oldest Scheduled Date', 'action-scheduler'); ?></strong></td> |
|
112 | + <td><strong><?php esc_html_e('Newest Scheduled Date', 'action-scheduler'); ?></strong></td> |
|
113 | 113 | </tr> |
114 | 114 | </thead> |
115 | 115 | <tbody> |
116 | 116 | <?php |
117 | - foreach ( $action_counts as $status => $count ) { |
|
117 | + foreach ($action_counts as $status => $count) { |
|
118 | 118 | // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
119 | 119 | printf( |
120 | 120 | '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
121 | - esc_html( $status_labels[ $status ] ), |
|
122 | - number_format_i18n( $count ), |
|
123 | - $oldest_and_newest[ $status ]['oldest'], |
|
124 | - $oldest_and_newest[ $status ]['newest'] |
|
121 | + esc_html($status_labels[$status]), |
|
122 | + number_format_i18n($count), |
|
123 | + $oldest_and_newest[$status]['oldest'], |
|
124 | + $oldest_and_newest[$status]['newest'] |
|
125 | 125 | ); |
126 | 126 | } |
127 | 127 | ?> |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | * @return mixed |
141 | 141 | * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
142 | 142 | */ |
143 | - public function __call( $name, $arguments ) { |
|
144 | - switch ( $name ) { |
|
143 | + public function __call($name, $arguments) { |
|
144 | + switch ($name) { |
|
145 | 145 | case 'print': |
146 | - _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
147 | - return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
146 | + _deprecated_function(__CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()'); |
|
147 | + return call_user_func_array(array($this, 'render'), $arguments); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return null; |
@@ -5,54 +5,54 @@ |
||
5 | 5 | * @codeCoverageIgnore |
6 | 6 | */ |
7 | 7 | class ActionScheduler_wpPostStore_PostStatusRegistrar { |
8 | - public function register() { |
|
9 | - register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | - register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
11 | - } |
|
8 | + public function register() { |
|
9 | + register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | + register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
11 | + } |
|
12 | 12 | |
13 | - /** |
|
14 | - * Build the args array for the post type definition |
|
15 | - * |
|
16 | - * @return array |
|
17 | - */ |
|
18 | - protected function post_status_args() { |
|
19 | - $args = array( |
|
20 | - 'public' => false, |
|
21 | - 'exclude_from_search' => false, |
|
22 | - 'show_in_admin_all_list' => true, |
|
23 | - 'show_in_admin_status_list' => true, |
|
24 | - ); |
|
13 | + /** |
|
14 | + * Build the args array for the post type definition |
|
15 | + * |
|
16 | + * @return array |
|
17 | + */ |
|
18 | + protected function post_status_args() { |
|
19 | + $args = array( |
|
20 | + 'public' => false, |
|
21 | + 'exclude_from_search' => false, |
|
22 | + 'show_in_admin_all_list' => true, |
|
23 | + 'show_in_admin_status_list' => true, |
|
24 | + ); |
|
25 | 25 | |
26 | - return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
27 | - } |
|
26 | + return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Build the args array for the post type definition |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - protected function post_status_failed_labels() { |
|
35 | - $labels = array( |
|
36 | - 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
37 | - /* translators: %s: count */ |
|
38 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
39 | - ); |
|
29 | + /** |
|
30 | + * Build the args array for the post type definition |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + protected function post_status_failed_labels() { |
|
35 | + $labels = array( |
|
36 | + 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
37 | + /* translators: %s: count */ |
|
38 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
39 | + ); |
|
40 | 40 | |
41 | - return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
42 | - } |
|
41 | + return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Build the args array for the post type definition |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - protected function post_status_running_labels() { |
|
50 | - $labels = array( |
|
51 | - 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
52 | - /* translators: %s: count */ |
|
53 | - 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
54 | - ); |
|
44 | + /** |
|
45 | + * Build the args array for the post type definition |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + protected function post_status_running_labels() { |
|
50 | + $labels = array( |
|
51 | + 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
52 | + /* translators: %s: count */ |
|
53 | + 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
54 | + ); |
|
55 | 55 | |
56 | - return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
57 | - } |
|
56 | + return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
57 | + } |
|
58 | 58 | } |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | */ |
7 | 7 | class ActionScheduler_wpPostStore_PostStatusRegistrar { |
8 | 8 | public function register() { |
9 | - register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | - register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
9 | + register_post_status(ActionScheduler_Store::STATUS_RUNNING, array_merge($this->post_status_args(), $this->post_status_running_labels())); |
|
10 | + register_post_status(ActionScheduler_Store::STATUS_FAILED, array_merge($this->post_status_args(), $this->post_status_failed_labels())); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | 'show_in_admin_status_list' => true, |
24 | 24 | ); |
25 | 25 | |
26 | - return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
26 | + return apply_filters('action_scheduler_post_status_args', $args); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function post_status_failed_labels() { |
35 | 35 | $labels = array( |
36 | - 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
36 | + 'label' => _x('Failed', 'post', 'action-scheduler'), |
|
37 | 37 | /* translators: %s: count */ |
38 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
38 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler'), |
|
39 | 39 | ); |
40 | 40 | |
41 | - return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
41 | + return apply_filters('action_scheduler_post_status_failed_labels', $labels); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function post_status_running_labels() { |
50 | 50 | $labels = array( |
51 | - 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
51 | + 'label' => _x('In-Progress', 'post', 'action-scheduler'), |
|
52 | 52 | /* translators: %s: count */ |
53 | - 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
53 | + 'label_count' => _n_noop('In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler'), |
|
54 | 54 | ); |
55 | 55 | |
56 | - return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
56 | + return apply_filters('action_scheduler_post_status_running_labels', $labels); |
|
57 | 57 | } |
58 | 58 | } |
@@ -13,368 +13,368 @@ |
||
13 | 13 | * @since 3.0.0 |
14 | 14 | */ |
15 | 15 | class ActionScheduler_HybridStore extends Store { |
16 | - const DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation'; |
|
17 | - |
|
18 | - private $primary_store; |
|
19 | - private $secondary_store; |
|
20 | - private $migration_runner; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var int The dividing line between IDs of actions created |
|
24 | - * by the primary and secondary stores. |
|
25 | - * |
|
26 | - * Methods that accept an action ID will compare the ID against |
|
27 | - * this to determine which store will contain that ID. In almost |
|
28 | - * all cases, the ID should come from the primary store, but if |
|
29 | - * client code is bypassing the API functions and fetching IDs |
|
30 | - * from elsewhere, then there is a chance that an unmigrated ID |
|
31 | - * might be requested. |
|
32 | - */ |
|
33 | - private $demarkation_id = 0; |
|
34 | - |
|
35 | - /** |
|
36 | - * ActionScheduler_HybridStore constructor. |
|
37 | - * |
|
38 | - * @param Config $config Migration config object. |
|
39 | - */ |
|
40 | - public function __construct( Config $config = null ) { |
|
41 | - $this->demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 ); |
|
42 | - if ( empty( $config ) ) { |
|
43 | - $config = Controller::instance()->get_migration_config_object(); |
|
44 | - } |
|
45 | - $this->primary_store = $config->get_destination_store(); |
|
46 | - $this->secondary_store = $config->get_source_store(); |
|
47 | - $this->migration_runner = new Runner( $config ); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Initialize the table data store tables. |
|
52 | - * |
|
53 | - * @codeCoverageIgnore |
|
54 | - */ |
|
55 | - public function init() { |
|
56 | - add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 ); |
|
57 | - $this->primary_store->init(); |
|
58 | - $this->secondary_store->init(); |
|
59 | - remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 ); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * When the actions table is created, set its autoincrement |
|
64 | - * value to be one higher than the posts table to ensure that |
|
65 | - * there are no ID collisions. |
|
66 | - * |
|
67 | - * @param string $table_name |
|
68 | - * @param string $table_suffix |
|
69 | - * |
|
70 | - * @return void |
|
71 | - * @codeCoverageIgnore |
|
72 | - */ |
|
73 | - public function set_autoincrement( $table_name, $table_suffix ) { |
|
74 | - if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) { |
|
75 | - if ( empty( $this->demarkation_id ) ) { |
|
76 | - $this->demarkation_id = $this->set_demarkation_id(); |
|
77 | - } |
|
78 | - /** @var \wpdb $wpdb */ |
|
79 | - global $wpdb; |
|
80 | - $wpdb->insert( |
|
81 | - $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, |
|
82 | - [ |
|
83 | - 'action_id' => $this->demarkation_id, |
|
84 | - 'hook' => '', |
|
85 | - 'status' => '', |
|
86 | - ] |
|
87 | - ); |
|
88 | - $wpdb->delete( |
|
89 | - $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, |
|
90 | - [ 'action_id' => $this->demarkation_id ] |
|
91 | - ); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Store the demarkation id in WP options. |
|
97 | - * |
|
98 | - * @param int $id The ID to set as the demarkation point between the two stores |
|
99 | - * Leave null to use the next ID from the WP posts table. |
|
100 | - * |
|
101 | - * @return int The new ID. |
|
102 | - * |
|
103 | - * @codeCoverageIgnore |
|
104 | - */ |
|
105 | - private function set_demarkation_id( $id = null ) { |
|
106 | - if ( empty( $id ) ) { |
|
107 | - /** @var \wpdb $wpdb */ |
|
108 | - global $wpdb; |
|
109 | - $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ); |
|
110 | - $id ++; |
|
111 | - } |
|
112 | - update_option( self::DEMARKATION_OPTION, $id ); |
|
113 | - |
|
114 | - return $id; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Find the first matching action from the secondary store. |
|
119 | - * If it exists, migrate it to the primary store immediately. |
|
120 | - * After it migrates, the secondary store will logically contain |
|
121 | - * the next matching action, so return the result thence. |
|
122 | - * |
|
123 | - * @param string $hook |
|
124 | - * @param array $params |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function find_action( $hook, $params = [] ) { |
|
129 | - $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params ); |
|
130 | - if ( ! empty( $found_unmigrated_action ) ) { |
|
131 | - $this->migrate( [ $found_unmigrated_action ] ); |
|
132 | - } |
|
133 | - |
|
134 | - return $this->primary_store->find_action( $hook, $params ); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Find actions matching the query in the secondary source first. |
|
139 | - * If any are found, migrate them immediately. Then the secondary |
|
140 | - * store will contain the canonical results. |
|
141 | - * |
|
142 | - * @param array $query |
|
143 | - * @param string $query_type Whether to select or count the results. Default, select. |
|
144 | - * |
|
145 | - * @return int[] |
|
146 | - */ |
|
147 | - public function query_actions( $query = [], $query_type = 'select' ) { |
|
148 | - $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' ); |
|
149 | - if ( ! empty( $found_unmigrated_actions ) ) { |
|
150 | - $this->migrate( $found_unmigrated_actions ); |
|
151 | - } |
|
152 | - |
|
153 | - return $this->primary_store->query_actions( $query, $query_type ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get a count of all actions in the store, grouped by status |
|
158 | - * |
|
159 | - * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status. |
|
160 | - */ |
|
161 | - public function action_counts() { |
|
162 | - $unmigrated_actions_count = $this->secondary_store->action_counts(); |
|
163 | - $migrated_actions_count = $this->primary_store->action_counts(); |
|
164 | - $actions_count_by_status = array(); |
|
165 | - |
|
166 | - foreach ( $this->get_status_labels() as $status_key => $status_label ) { |
|
167 | - |
|
168 | - $count = 0; |
|
169 | - |
|
170 | - if ( isset( $unmigrated_actions_count[ $status_key ] ) ) { |
|
171 | - $count += $unmigrated_actions_count[ $status_key ]; |
|
172 | - } |
|
173 | - |
|
174 | - if ( isset( $migrated_actions_count[ $status_key ] ) ) { |
|
175 | - $count += $migrated_actions_count[ $status_key ]; |
|
176 | - } |
|
177 | - |
|
178 | - $actions_count_by_status[ $status_key ] = $count; |
|
179 | - } |
|
180 | - |
|
181 | - $actions_count_by_status = array_filter( $actions_count_by_status ); |
|
182 | - |
|
183 | - return $actions_count_by_status; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * If any actions would have been claimed by the secondary store, |
|
188 | - * migrate them immediately, then ask the primary store for the |
|
189 | - * canonical claim. |
|
190 | - * |
|
191 | - * @param int $max_actions |
|
192 | - * @param DateTime|null $before_date |
|
193 | - * |
|
194 | - * @return ActionScheduler_ActionClaim |
|
195 | - */ |
|
196 | - public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { |
|
197 | - $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
198 | - |
|
199 | - $claimed_actions = $claim->get_actions(); |
|
200 | - if ( ! empty( $claimed_actions ) ) { |
|
201 | - $this->migrate( $claimed_actions ); |
|
202 | - } |
|
203 | - |
|
204 | - $this->secondary_store->release_claim( $claim ); |
|
205 | - |
|
206 | - return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Migrate a list of actions to the table data store. |
|
211 | - * |
|
212 | - * @param array $action_ids List of action IDs. |
|
213 | - */ |
|
214 | - private function migrate( $action_ids ) { |
|
215 | - $this->migration_runner->migrate_actions( $action_ids ); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Save an action to the primary store. |
|
220 | - * |
|
221 | - * @param ActionScheduler_Action $action Action object to be saved. |
|
222 | - * @param DateTime $date Optional. Schedule date. Default null. |
|
223 | - */ |
|
224 | - public function save_action( ActionScheduler_Action $action, DateTime $date = null ) { |
|
225 | - return $this->primary_store->save_action( $action, $date ); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Retrieve an existing action whether migrated or not. |
|
230 | - * |
|
231 | - * @param int $action_id Action ID. |
|
232 | - */ |
|
233 | - public function fetch_action( $action_id ) { |
|
234 | - if ( $action_id < $this->demarkation_id ) { |
|
235 | - return $this->secondary_store->fetch_action( $action_id ); |
|
236 | - } else { |
|
237 | - return $this->primary_store->fetch_action( $action_id ); |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Cancel an existing action whether migrated or not. |
|
243 | - * |
|
244 | - * @param int $action_id Action ID. |
|
245 | - */ |
|
246 | - public function cancel_action( $action_id ) { |
|
247 | - if ( $action_id < $this->demarkation_id ) { |
|
248 | - $this->secondary_store->cancel_action( $action_id ); |
|
249 | - } else { |
|
250 | - $this->primary_store->cancel_action( $action_id ); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Delete an existing action whether migrated or not. |
|
256 | - * |
|
257 | - * @param int $action_id Action ID. |
|
258 | - */ |
|
259 | - public function delete_action( $action_id ) { |
|
260 | - if ( $action_id < $this->demarkation_id ) { |
|
261 | - $this->secondary_store->delete_action( $action_id ); |
|
262 | - } else { |
|
263 | - $this->primary_store->delete_action( $action_id ); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Get the schedule date an existing action whether migrated or not. |
|
269 | - * |
|
270 | - * @param int $action_id Action ID. |
|
271 | - */ |
|
272 | - public function get_date( $action_id ) { |
|
273 | - if ( $action_id < $this->demarkation_id ) { |
|
274 | - return $this->secondary_store->get_date( $action_id ); |
|
275 | - } else { |
|
276 | - return $this->primary_store->get_date( $action_id ); |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Mark an existing action as failed whether migrated or not. |
|
282 | - * |
|
283 | - * @param int $action_id Action ID. |
|
284 | - */ |
|
285 | - public function mark_failure( $action_id ) { |
|
286 | - if ( $action_id < $this->demarkation_id ) { |
|
287 | - $this->secondary_store->mark_failure( $action_id ); |
|
288 | - } else { |
|
289 | - $this->primary_store->mark_failure( $action_id ); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Log the execution of an existing action whether migrated or not. |
|
295 | - * |
|
296 | - * @param int $action_id Action ID. |
|
297 | - */ |
|
298 | - public function log_execution( $action_id ) { |
|
299 | - if ( $action_id < $this->demarkation_id ) { |
|
300 | - $this->secondary_store->log_execution( $action_id ); |
|
301 | - } else { |
|
302 | - $this->primary_store->log_execution( $action_id ); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Mark an existing action complete whether migrated or not. |
|
308 | - * |
|
309 | - * @param int $action_id Action ID. |
|
310 | - */ |
|
311 | - public function mark_complete( $action_id ) { |
|
312 | - if ( $action_id < $this->demarkation_id ) { |
|
313 | - $this->secondary_store->mark_complete( $action_id ); |
|
314 | - } else { |
|
315 | - $this->primary_store->mark_complete( $action_id ); |
|
316 | - } |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Get an existing action status whether migrated or not. |
|
321 | - * |
|
322 | - * @param int $action_id Action ID. |
|
323 | - */ |
|
324 | - public function get_status( $action_id ) { |
|
325 | - if ( $action_id < $this->demarkation_id ) { |
|
326 | - return $this->secondary_store->get_status( $action_id ); |
|
327 | - } else { |
|
328 | - return $this->primary_store->get_status( $action_id ); |
|
329 | - } |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /* * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
16 | + const DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation'; |
|
17 | + |
|
18 | + private $primary_store; |
|
19 | + private $secondary_store; |
|
20 | + private $migration_runner; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var int The dividing line between IDs of actions created |
|
24 | + * by the primary and secondary stores. |
|
25 | + * |
|
26 | + * Methods that accept an action ID will compare the ID against |
|
27 | + * this to determine which store will contain that ID. In almost |
|
28 | + * all cases, the ID should come from the primary store, but if |
|
29 | + * client code is bypassing the API functions and fetching IDs |
|
30 | + * from elsewhere, then there is a chance that an unmigrated ID |
|
31 | + * might be requested. |
|
32 | + */ |
|
33 | + private $demarkation_id = 0; |
|
34 | + |
|
35 | + /** |
|
36 | + * ActionScheduler_HybridStore constructor. |
|
37 | + * |
|
38 | + * @param Config $config Migration config object. |
|
39 | + */ |
|
40 | + public function __construct( Config $config = null ) { |
|
41 | + $this->demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 ); |
|
42 | + if ( empty( $config ) ) { |
|
43 | + $config = Controller::instance()->get_migration_config_object(); |
|
44 | + } |
|
45 | + $this->primary_store = $config->get_destination_store(); |
|
46 | + $this->secondary_store = $config->get_source_store(); |
|
47 | + $this->migration_runner = new Runner( $config ); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Initialize the table data store tables. |
|
52 | + * |
|
53 | + * @codeCoverageIgnore |
|
54 | + */ |
|
55 | + public function init() { |
|
56 | + add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 ); |
|
57 | + $this->primary_store->init(); |
|
58 | + $this->secondary_store->init(); |
|
59 | + remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 ); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * When the actions table is created, set its autoincrement |
|
64 | + * value to be one higher than the posts table to ensure that |
|
65 | + * there are no ID collisions. |
|
66 | + * |
|
67 | + * @param string $table_name |
|
68 | + * @param string $table_suffix |
|
69 | + * |
|
70 | + * @return void |
|
71 | + * @codeCoverageIgnore |
|
72 | + */ |
|
73 | + public function set_autoincrement( $table_name, $table_suffix ) { |
|
74 | + if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) { |
|
75 | + if ( empty( $this->demarkation_id ) ) { |
|
76 | + $this->demarkation_id = $this->set_demarkation_id(); |
|
77 | + } |
|
78 | + /** @var \wpdb $wpdb */ |
|
79 | + global $wpdb; |
|
80 | + $wpdb->insert( |
|
81 | + $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, |
|
82 | + [ |
|
83 | + 'action_id' => $this->demarkation_id, |
|
84 | + 'hook' => '', |
|
85 | + 'status' => '', |
|
86 | + ] |
|
87 | + ); |
|
88 | + $wpdb->delete( |
|
89 | + $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, |
|
90 | + [ 'action_id' => $this->demarkation_id ] |
|
91 | + ); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Store the demarkation id in WP options. |
|
97 | + * |
|
98 | + * @param int $id The ID to set as the demarkation point between the two stores |
|
99 | + * Leave null to use the next ID from the WP posts table. |
|
100 | + * |
|
101 | + * @return int The new ID. |
|
102 | + * |
|
103 | + * @codeCoverageIgnore |
|
104 | + */ |
|
105 | + private function set_demarkation_id( $id = null ) { |
|
106 | + if ( empty( $id ) ) { |
|
107 | + /** @var \wpdb $wpdb */ |
|
108 | + global $wpdb; |
|
109 | + $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ); |
|
110 | + $id ++; |
|
111 | + } |
|
112 | + update_option( self::DEMARKATION_OPTION, $id ); |
|
113 | + |
|
114 | + return $id; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Find the first matching action from the secondary store. |
|
119 | + * If it exists, migrate it to the primary store immediately. |
|
120 | + * After it migrates, the secondary store will logically contain |
|
121 | + * the next matching action, so return the result thence. |
|
122 | + * |
|
123 | + * @param string $hook |
|
124 | + * @param array $params |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function find_action( $hook, $params = [] ) { |
|
129 | + $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params ); |
|
130 | + if ( ! empty( $found_unmigrated_action ) ) { |
|
131 | + $this->migrate( [ $found_unmigrated_action ] ); |
|
132 | + } |
|
133 | + |
|
134 | + return $this->primary_store->find_action( $hook, $params ); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Find actions matching the query in the secondary source first. |
|
139 | + * If any are found, migrate them immediately. Then the secondary |
|
140 | + * store will contain the canonical results. |
|
141 | + * |
|
142 | + * @param array $query |
|
143 | + * @param string $query_type Whether to select or count the results. Default, select. |
|
144 | + * |
|
145 | + * @return int[] |
|
146 | + */ |
|
147 | + public function query_actions( $query = [], $query_type = 'select' ) { |
|
148 | + $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' ); |
|
149 | + if ( ! empty( $found_unmigrated_actions ) ) { |
|
150 | + $this->migrate( $found_unmigrated_actions ); |
|
151 | + } |
|
152 | + |
|
153 | + return $this->primary_store->query_actions( $query, $query_type ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get a count of all actions in the store, grouped by status |
|
158 | + * |
|
159 | + * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status. |
|
160 | + */ |
|
161 | + public function action_counts() { |
|
162 | + $unmigrated_actions_count = $this->secondary_store->action_counts(); |
|
163 | + $migrated_actions_count = $this->primary_store->action_counts(); |
|
164 | + $actions_count_by_status = array(); |
|
165 | + |
|
166 | + foreach ( $this->get_status_labels() as $status_key => $status_label ) { |
|
167 | + |
|
168 | + $count = 0; |
|
169 | + |
|
170 | + if ( isset( $unmigrated_actions_count[ $status_key ] ) ) { |
|
171 | + $count += $unmigrated_actions_count[ $status_key ]; |
|
172 | + } |
|
173 | + |
|
174 | + if ( isset( $migrated_actions_count[ $status_key ] ) ) { |
|
175 | + $count += $migrated_actions_count[ $status_key ]; |
|
176 | + } |
|
177 | + |
|
178 | + $actions_count_by_status[ $status_key ] = $count; |
|
179 | + } |
|
180 | + |
|
181 | + $actions_count_by_status = array_filter( $actions_count_by_status ); |
|
182 | + |
|
183 | + return $actions_count_by_status; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * If any actions would have been claimed by the secondary store, |
|
188 | + * migrate them immediately, then ask the primary store for the |
|
189 | + * canonical claim. |
|
190 | + * |
|
191 | + * @param int $max_actions |
|
192 | + * @param DateTime|null $before_date |
|
193 | + * |
|
194 | + * @return ActionScheduler_ActionClaim |
|
195 | + */ |
|
196 | + public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { |
|
197 | + $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
198 | + |
|
199 | + $claimed_actions = $claim->get_actions(); |
|
200 | + if ( ! empty( $claimed_actions ) ) { |
|
201 | + $this->migrate( $claimed_actions ); |
|
202 | + } |
|
203 | + |
|
204 | + $this->secondary_store->release_claim( $claim ); |
|
205 | + |
|
206 | + return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Migrate a list of actions to the table data store. |
|
211 | + * |
|
212 | + * @param array $action_ids List of action IDs. |
|
213 | + */ |
|
214 | + private function migrate( $action_ids ) { |
|
215 | + $this->migration_runner->migrate_actions( $action_ids ); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Save an action to the primary store. |
|
220 | + * |
|
221 | + * @param ActionScheduler_Action $action Action object to be saved. |
|
222 | + * @param DateTime $date Optional. Schedule date. Default null. |
|
223 | + */ |
|
224 | + public function save_action( ActionScheduler_Action $action, DateTime $date = null ) { |
|
225 | + return $this->primary_store->save_action( $action, $date ); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Retrieve an existing action whether migrated or not. |
|
230 | + * |
|
231 | + * @param int $action_id Action ID. |
|
232 | + */ |
|
233 | + public function fetch_action( $action_id ) { |
|
234 | + if ( $action_id < $this->demarkation_id ) { |
|
235 | + return $this->secondary_store->fetch_action( $action_id ); |
|
236 | + } else { |
|
237 | + return $this->primary_store->fetch_action( $action_id ); |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Cancel an existing action whether migrated or not. |
|
243 | + * |
|
244 | + * @param int $action_id Action ID. |
|
245 | + */ |
|
246 | + public function cancel_action( $action_id ) { |
|
247 | + if ( $action_id < $this->demarkation_id ) { |
|
248 | + $this->secondary_store->cancel_action( $action_id ); |
|
249 | + } else { |
|
250 | + $this->primary_store->cancel_action( $action_id ); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Delete an existing action whether migrated or not. |
|
256 | + * |
|
257 | + * @param int $action_id Action ID. |
|
258 | + */ |
|
259 | + public function delete_action( $action_id ) { |
|
260 | + if ( $action_id < $this->demarkation_id ) { |
|
261 | + $this->secondary_store->delete_action( $action_id ); |
|
262 | + } else { |
|
263 | + $this->primary_store->delete_action( $action_id ); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Get the schedule date an existing action whether migrated or not. |
|
269 | + * |
|
270 | + * @param int $action_id Action ID. |
|
271 | + */ |
|
272 | + public function get_date( $action_id ) { |
|
273 | + if ( $action_id < $this->demarkation_id ) { |
|
274 | + return $this->secondary_store->get_date( $action_id ); |
|
275 | + } else { |
|
276 | + return $this->primary_store->get_date( $action_id ); |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Mark an existing action as failed whether migrated or not. |
|
282 | + * |
|
283 | + * @param int $action_id Action ID. |
|
284 | + */ |
|
285 | + public function mark_failure( $action_id ) { |
|
286 | + if ( $action_id < $this->demarkation_id ) { |
|
287 | + $this->secondary_store->mark_failure( $action_id ); |
|
288 | + } else { |
|
289 | + $this->primary_store->mark_failure( $action_id ); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Log the execution of an existing action whether migrated or not. |
|
295 | + * |
|
296 | + * @param int $action_id Action ID. |
|
297 | + */ |
|
298 | + public function log_execution( $action_id ) { |
|
299 | + if ( $action_id < $this->demarkation_id ) { |
|
300 | + $this->secondary_store->log_execution( $action_id ); |
|
301 | + } else { |
|
302 | + $this->primary_store->log_execution( $action_id ); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Mark an existing action complete whether migrated or not. |
|
308 | + * |
|
309 | + * @param int $action_id Action ID. |
|
310 | + */ |
|
311 | + public function mark_complete( $action_id ) { |
|
312 | + if ( $action_id < $this->demarkation_id ) { |
|
313 | + $this->secondary_store->mark_complete( $action_id ); |
|
314 | + } else { |
|
315 | + $this->primary_store->mark_complete( $action_id ); |
|
316 | + } |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Get an existing action status whether migrated or not. |
|
321 | + * |
|
322 | + * @param int $action_id Action ID. |
|
323 | + */ |
|
324 | + public function get_status( $action_id ) { |
|
325 | + if ( $action_id < $this->demarkation_id ) { |
|
326 | + return $this->secondary_store->get_status( $action_id ); |
|
327 | + } else { |
|
328 | + return $this->primary_store->get_status( $action_id ); |
|
329 | + } |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /* * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
334 | 334 | * All claim-related functions should operate solely |
335 | 335 | * on the primary store. |
336 | 336 | * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
337 | 337 | |
338 | - /** |
|
339 | - * Get the claim count from the table data store. |
|
340 | - */ |
|
341 | - public function get_claim_count() { |
|
342 | - return $this->primary_store->get_claim_count(); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Retrieve the claim ID for an action from the table data store. |
|
347 | - * |
|
348 | - * @param int $action_id Action ID. |
|
349 | - */ |
|
350 | - public function get_claim_id( $action_id ) { |
|
351 | - return $this->primary_store->get_claim_id( $action_id ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Release a claim in the table data store. |
|
356 | - * |
|
357 | - * @param ActionScheduler_ActionClaim $claim Claim object. |
|
358 | - */ |
|
359 | - public function release_claim( ActionScheduler_ActionClaim $claim ) { |
|
360 | - $this->primary_store->release_claim( $claim ); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Release claims on an action in the table data store. |
|
365 | - * |
|
366 | - * @param int $action_id Action ID. |
|
367 | - */ |
|
368 | - public function unclaim_action( $action_id ) { |
|
369 | - $this->primary_store->unclaim_action( $action_id ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Retrieve a list of action IDs by claim. |
|
374 | - * |
|
375 | - * @param int $claim_id Claim ID. |
|
376 | - */ |
|
377 | - public function find_actions_by_claim_id( $claim_id ) { |
|
378 | - return $this->primary_store->find_actions_by_claim_id( $claim_id ); |
|
379 | - } |
|
338 | + /** |
|
339 | + * Get the claim count from the table data store. |
|
340 | + */ |
|
341 | + public function get_claim_count() { |
|
342 | + return $this->primary_store->get_claim_count(); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Retrieve the claim ID for an action from the table data store. |
|
347 | + * |
|
348 | + * @param int $action_id Action ID. |
|
349 | + */ |
|
350 | + public function get_claim_id( $action_id ) { |
|
351 | + return $this->primary_store->get_claim_id( $action_id ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Release a claim in the table data store. |
|
356 | + * |
|
357 | + * @param ActionScheduler_ActionClaim $claim Claim object. |
|
358 | + */ |
|
359 | + public function release_claim( ActionScheduler_ActionClaim $claim ) { |
|
360 | + $this->primary_store->release_claim( $claim ); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Release claims on an action in the table data store. |
|
365 | + * |
|
366 | + * @param int $action_id Action ID. |
|
367 | + */ |
|
368 | + public function unclaim_action( $action_id ) { |
|
369 | + $this->primary_store->unclaim_action( $action_id ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Retrieve a list of action IDs by claim. |
|
374 | + * |
|
375 | + * @param int $claim_id Claim ID. |
|
376 | + */ |
|
377 | + public function find_actions_by_claim_id( $claim_id ) { |
|
378 | + return $this->primary_store->find_actions_by_claim_id( $claim_id ); |
|
379 | + } |
|
380 | 380 | } |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param Config $config Migration config object. |
39 | 39 | */ |
40 | - public function __construct( Config $config = null ) { |
|
41 | - $this->demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 ); |
|
42 | - if ( empty( $config ) ) { |
|
40 | + public function __construct(Config $config = null) { |
|
41 | + $this->demarkation_id = (int) get_option(self::DEMARKATION_OPTION, 0); |
|
42 | + if (empty($config)) { |
|
43 | 43 | $config = Controller::instance()->get_migration_config_object(); |
44 | 44 | } |
45 | 45 | $this->primary_store = $config->get_destination_store(); |
46 | 46 | $this->secondary_store = $config->get_source_store(); |
47 | - $this->migration_runner = new Runner( $config ); |
|
47 | + $this->migration_runner = new Runner($config); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @codeCoverageIgnore |
54 | 54 | */ |
55 | 55 | public function init() { |
56 | - add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 ); |
|
56 | + add_action('action_scheduler/created_table', [$this, 'set_autoincrement'], 10, 2); |
|
57 | 57 | $this->primary_store->init(); |
58 | 58 | $this->secondary_store->init(); |
59 | - remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 ); |
|
59 | + remove_action('action_scheduler/created_table', [$this, 'set_autoincrement'], 10); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @return void |
71 | 71 | * @codeCoverageIgnore |
72 | 72 | */ |
73 | - public function set_autoincrement( $table_name, $table_suffix ) { |
|
74 | - if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) { |
|
75 | - if ( empty( $this->demarkation_id ) ) { |
|
73 | + public function set_autoincrement($table_name, $table_suffix) { |
|
74 | + if (ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix) { |
|
75 | + if (empty($this->demarkation_id)) { |
|
76 | 76 | $this->demarkation_id = $this->set_demarkation_id(); |
77 | 77 | } |
78 | 78 | /** @var \wpdb $wpdb */ |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ); |
88 | 88 | $wpdb->delete( |
89 | 89 | $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE}, |
90 | - [ 'action_id' => $this->demarkation_id ] |
|
90 | + ['action_id' => $this->demarkation_id] |
|
91 | 91 | ); |
92 | 92 | } |
93 | 93 | } |
@@ -102,14 +102,14 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @codeCoverageIgnore |
104 | 104 | */ |
105 | - private function set_demarkation_id( $id = null ) { |
|
106 | - if ( empty( $id ) ) { |
|
105 | + private function set_demarkation_id($id = null) { |
|
106 | + if (empty($id)) { |
|
107 | 107 | /** @var \wpdb $wpdb */ |
108 | 108 | global $wpdb; |
109 | - $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ); |
|
110 | - $id ++; |
|
109 | + $id = (int) $wpdb->get_var("SELECT MAX(ID) FROM $wpdb->posts"); |
|
110 | + $id++; |
|
111 | 111 | } |
112 | - update_option( self::DEMARKATION_OPTION, $id ); |
|
112 | + update_option(self::DEMARKATION_OPTION, $id); |
|
113 | 113 | |
114 | 114 | return $id; |
115 | 115 | } |
@@ -125,13 +125,13 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public function find_action( $hook, $params = [] ) { |
|
129 | - $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params ); |
|
130 | - if ( ! empty( $found_unmigrated_action ) ) { |
|
131 | - $this->migrate( [ $found_unmigrated_action ] ); |
|
128 | + public function find_action($hook, $params = []) { |
|
129 | + $found_unmigrated_action = $this->secondary_store->find_action($hook, $params); |
|
130 | + if (!empty($found_unmigrated_action)) { |
|
131 | + $this->migrate([$found_unmigrated_action]); |
|
132 | 132 | } |
133 | 133 | |
134 | - return $this->primary_store->find_action( $hook, $params ); |
|
134 | + return $this->primary_store->find_action($hook, $params); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return int[] |
146 | 146 | */ |
147 | - public function query_actions( $query = [], $query_type = 'select' ) { |
|
148 | - $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' ); |
|
149 | - if ( ! empty( $found_unmigrated_actions ) ) { |
|
150 | - $this->migrate( $found_unmigrated_actions ); |
|
147 | + public function query_actions($query = [], $query_type = 'select') { |
|
148 | + $found_unmigrated_actions = $this->secondary_store->query_actions($query, 'select'); |
|
149 | + if (!empty($found_unmigrated_actions)) { |
|
150 | + $this->migrate($found_unmigrated_actions); |
|
151 | 151 | } |
152 | 152 | |
153 | - return $this->primary_store->query_actions( $query, $query_type ); |
|
153 | + return $this->primary_store->query_actions($query, $query_type); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -163,22 +163,22 @@ discard block |
||
163 | 163 | $migrated_actions_count = $this->primary_store->action_counts(); |
164 | 164 | $actions_count_by_status = array(); |
165 | 165 | |
166 | - foreach ( $this->get_status_labels() as $status_key => $status_label ) { |
|
166 | + foreach ($this->get_status_labels() as $status_key => $status_label) { |
|
167 | 167 | |
168 | 168 | $count = 0; |
169 | 169 | |
170 | - if ( isset( $unmigrated_actions_count[ $status_key ] ) ) { |
|
171 | - $count += $unmigrated_actions_count[ $status_key ]; |
|
170 | + if (isset($unmigrated_actions_count[$status_key])) { |
|
171 | + $count += $unmigrated_actions_count[$status_key]; |
|
172 | 172 | } |
173 | 173 | |
174 | - if ( isset( $migrated_actions_count[ $status_key ] ) ) { |
|
175 | - $count += $migrated_actions_count[ $status_key ]; |
|
174 | + if (isset($migrated_actions_count[$status_key])) { |
|
175 | + $count += $migrated_actions_count[$status_key]; |
|
176 | 176 | } |
177 | 177 | |
178 | - $actions_count_by_status[ $status_key ] = $count; |
|
178 | + $actions_count_by_status[$status_key] = $count; |
|
179 | 179 | } |
180 | 180 | |
181 | - $actions_count_by_status = array_filter( $actions_count_by_status ); |
|
181 | + $actions_count_by_status = array_filter($actions_count_by_status); |
|
182 | 182 | |
183 | 183 | return $actions_count_by_status; |
184 | 184 | } |
@@ -193,17 +193,17 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return ActionScheduler_ActionClaim |
195 | 195 | */ |
196 | - public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { |
|
197 | - $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
196 | + public function stake_claim($max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '') { |
|
197 | + $claim = $this->secondary_store->stake_claim($max_actions, $before_date, $hooks, $group); |
|
198 | 198 | |
199 | 199 | $claimed_actions = $claim->get_actions(); |
200 | - if ( ! empty( $claimed_actions ) ) { |
|
201 | - $this->migrate( $claimed_actions ); |
|
200 | + if (!empty($claimed_actions)) { |
|
201 | + $this->migrate($claimed_actions); |
|
202 | 202 | } |
203 | 203 | |
204 | - $this->secondary_store->release_claim( $claim ); |
|
204 | + $this->secondary_store->release_claim($claim); |
|
205 | 205 | |
206 | - return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group ); |
|
206 | + return $this->primary_store->stake_claim($max_actions, $before_date, $hooks, $group); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @param array $action_ids List of action IDs. |
213 | 213 | */ |
214 | - private function migrate( $action_ids ) { |
|
215 | - $this->migration_runner->migrate_actions( $action_ids ); |
|
214 | + private function migrate($action_ids) { |
|
215 | + $this->migration_runner->migrate_actions($action_ids); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @param ActionScheduler_Action $action Action object to be saved. |
222 | 222 | * @param DateTime $date Optional. Schedule date. Default null. |
223 | 223 | */ |
224 | - public function save_action( ActionScheduler_Action $action, DateTime $date = null ) { |
|
225 | - return $this->primary_store->save_action( $action, $date ); |
|
224 | + public function save_action(ActionScheduler_Action $action, DateTime $date = null) { |
|
225 | + return $this->primary_store->save_action($action, $date); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @param int $action_id Action ID. |
232 | 232 | */ |
233 | - public function fetch_action( $action_id ) { |
|
234 | - if ( $action_id < $this->demarkation_id ) { |
|
235 | - return $this->secondary_store->fetch_action( $action_id ); |
|
233 | + public function fetch_action($action_id) { |
|
234 | + if ($action_id < $this->demarkation_id) { |
|
235 | + return $this->secondary_store->fetch_action($action_id); |
|
236 | 236 | } else { |
237 | - return $this->primary_store->fetch_action( $action_id ); |
|
237 | + return $this->primary_store->fetch_action($action_id); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
@@ -243,11 +243,11 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @param int $action_id Action ID. |
245 | 245 | */ |
246 | - public function cancel_action( $action_id ) { |
|
247 | - if ( $action_id < $this->demarkation_id ) { |
|
248 | - $this->secondary_store->cancel_action( $action_id ); |
|
246 | + public function cancel_action($action_id) { |
|
247 | + if ($action_id < $this->demarkation_id) { |
|
248 | + $this->secondary_store->cancel_action($action_id); |
|
249 | 249 | } else { |
250 | - $this->primary_store->cancel_action( $action_id ); |
|
250 | + $this->primary_store->cancel_action($action_id); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @param int $action_id Action ID. |
258 | 258 | */ |
259 | - public function delete_action( $action_id ) { |
|
260 | - if ( $action_id < $this->demarkation_id ) { |
|
261 | - $this->secondary_store->delete_action( $action_id ); |
|
259 | + public function delete_action($action_id) { |
|
260 | + if ($action_id < $this->demarkation_id) { |
|
261 | + $this->secondary_store->delete_action($action_id); |
|
262 | 262 | } else { |
263 | - $this->primary_store->delete_action( $action_id ); |
|
263 | + $this->primary_store->delete_action($action_id); |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @param int $action_id Action ID. |
271 | 271 | */ |
272 | - public function get_date( $action_id ) { |
|
273 | - if ( $action_id < $this->demarkation_id ) { |
|
274 | - return $this->secondary_store->get_date( $action_id ); |
|
272 | + public function get_date($action_id) { |
|
273 | + if ($action_id < $this->demarkation_id) { |
|
274 | + return $this->secondary_store->get_date($action_id); |
|
275 | 275 | } else { |
276 | - return $this->primary_store->get_date( $action_id ); |
|
276 | + return $this->primary_store->get_date($action_id); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -282,11 +282,11 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @param int $action_id Action ID. |
284 | 284 | */ |
285 | - public function mark_failure( $action_id ) { |
|
286 | - if ( $action_id < $this->demarkation_id ) { |
|
287 | - $this->secondary_store->mark_failure( $action_id ); |
|
285 | + public function mark_failure($action_id) { |
|
286 | + if ($action_id < $this->demarkation_id) { |
|
287 | + $this->secondary_store->mark_failure($action_id); |
|
288 | 288 | } else { |
289 | - $this->primary_store->mark_failure( $action_id ); |
|
289 | + $this->primary_store->mark_failure($action_id); |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
@@ -295,11 +295,11 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @param int $action_id Action ID. |
297 | 297 | */ |
298 | - public function log_execution( $action_id ) { |
|
299 | - if ( $action_id < $this->demarkation_id ) { |
|
300 | - $this->secondary_store->log_execution( $action_id ); |
|
298 | + public function log_execution($action_id) { |
|
299 | + if ($action_id < $this->demarkation_id) { |
|
300 | + $this->secondary_store->log_execution($action_id); |
|
301 | 301 | } else { |
302 | - $this->primary_store->log_execution( $action_id ); |
|
302 | + $this->primary_store->log_execution($action_id); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param int $action_id Action ID. |
310 | 310 | */ |
311 | - public function mark_complete( $action_id ) { |
|
312 | - if ( $action_id < $this->demarkation_id ) { |
|
313 | - $this->secondary_store->mark_complete( $action_id ); |
|
311 | + public function mark_complete($action_id) { |
|
312 | + if ($action_id < $this->demarkation_id) { |
|
313 | + $this->secondary_store->mark_complete($action_id); |
|
314 | 314 | } else { |
315 | - $this->primary_store->mark_complete( $action_id ); |
|
315 | + $this->primary_store->mark_complete($action_id); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param int $action_id Action ID. |
323 | 323 | */ |
324 | - public function get_status( $action_id ) { |
|
325 | - if ( $action_id < $this->demarkation_id ) { |
|
326 | - return $this->secondary_store->get_status( $action_id ); |
|
324 | + public function get_status($action_id) { |
|
325 | + if ($action_id < $this->demarkation_id) { |
|
326 | + return $this->secondary_store->get_status($action_id); |
|
327 | 327 | } else { |
328 | - return $this->primary_store->get_status( $action_id ); |
|
328 | + return $this->primary_store->get_status($action_id); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @param int $action_id Action ID. |
349 | 349 | */ |
350 | - public function get_claim_id( $action_id ) { |
|
351 | - return $this->primary_store->get_claim_id( $action_id ); |
|
350 | + public function get_claim_id($action_id) { |
|
351 | + return $this->primary_store->get_claim_id($action_id); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @param ActionScheduler_ActionClaim $claim Claim object. |
358 | 358 | */ |
359 | - public function release_claim( ActionScheduler_ActionClaim $claim ) { |
|
360 | - $this->primary_store->release_claim( $claim ); |
|
359 | + public function release_claim(ActionScheduler_ActionClaim $claim) { |
|
360 | + $this->primary_store->release_claim($claim); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @param int $action_id Action ID. |
367 | 367 | */ |
368 | - public function unclaim_action( $action_id ) { |
|
369 | - $this->primary_store->unclaim_action( $action_id ); |
|
368 | + public function unclaim_action($action_id) { |
|
369 | + $this->primary_store->unclaim_action($action_id); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * |
375 | 375 | * @param int $claim_id Claim ID. |
376 | 376 | */ |
377 | - public function find_actions_by_claim_id( $claim_id ) { |
|
378 | - return $this->primary_store->find_actions_by_claim_id( $claim_id ); |
|
377 | + public function find_actions_by_claim_id($claim_id) { |
|
378 | + return $this->primary_store->find_actions_by_claim_id($claim_id); |
|
379 | 379 | } |
380 | 380 | } |
@@ -9,138 +9,138 @@ |
||
9 | 9 | */ |
10 | 10 | class ActionScheduler_DBLogger extends ActionScheduler_Logger { |
11 | 11 | |
12 | - /** |
|
13 | - * Add a record to an action log. |
|
14 | - * |
|
15 | - * @param int $action_id Action ID. |
|
16 | - * @param string $message Message to be saved in the log entry. |
|
17 | - * @param DateTime $date Timestamp of the log entry. |
|
18 | - * |
|
19 | - * @return int The log entry ID. |
|
20 | - */ |
|
21 | - public function log( $action_id, $message, DateTime $date = null ) { |
|
22 | - if ( empty( $date ) ) { |
|
23 | - $date = as_get_datetime_object(); |
|
24 | - } else { |
|
25 | - $date = clone $date; |
|
26 | - } |
|
27 | - |
|
28 | - $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
29 | - ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
30 | - $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
31 | - |
|
32 | - /** @var \wpdb $wpdb */ |
|
33 | - global $wpdb; |
|
34 | - $wpdb->insert( $wpdb->actionscheduler_logs, [ |
|
35 | - 'action_id' => $action_id, |
|
36 | - 'message' => $message, |
|
37 | - 'log_date_gmt' => $date_gmt, |
|
38 | - 'log_date_local' => $date_local, |
|
39 | - ], [ '%d', '%s', '%s', '%s' ] ); |
|
40 | - |
|
41 | - return $wpdb->insert_id; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Retrieve an action log entry. |
|
46 | - * |
|
47 | - * @param int $entry_id Log entry ID. |
|
48 | - * |
|
49 | - * @return ActionScheduler_LogEntry |
|
50 | - */ |
|
51 | - public function get_entry( $entry_id ) { |
|
52 | - /** @var \wpdb $wpdb */ |
|
53 | - global $wpdb; |
|
54 | - $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) ); |
|
55 | - |
|
56 | - return $this->create_entry_from_db_record( $entry ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Create an action log entry from a database record. |
|
61 | - * |
|
62 | - * @param object $record Log entry database record object. |
|
63 | - * |
|
64 | - * @return ActionScheduler_LogEntry |
|
65 | - */ |
|
66 | - private function create_entry_from_db_record( $record ) { |
|
67 | - if ( empty( $record ) ) { |
|
68 | - return new ActionScheduler_NullLogEntry(); |
|
69 | - } |
|
70 | - |
|
71 | - $date = as_get_datetime_object( $record->log_date_gmt ); |
|
72 | - |
|
73 | - return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Retrieve the an action's log entries from the database. |
|
78 | - * |
|
79 | - * @param int $action_id Action ID. |
|
80 | - * |
|
81 | - * @return ActionScheduler_LogEntry[] |
|
82 | - */ |
|
83 | - public function get_logs( $action_id ) { |
|
84 | - /** @var \wpdb $wpdb */ |
|
85 | - global $wpdb; |
|
86 | - |
|
87 | - $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) ); |
|
88 | - |
|
89 | - return array_map( [ $this, 'create_entry_from_db_record' ], $records ); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Initialize the data store. |
|
94 | - * |
|
95 | - * @codeCoverageIgnore |
|
96 | - */ |
|
97 | - public function init() { |
|
98 | - |
|
99 | - $table_maker = new ActionScheduler_LoggerSchema(); |
|
100 | - $table_maker->register_tables(); |
|
101 | - |
|
102 | - parent::init(); |
|
103 | - |
|
104 | - add_action( 'action_scheduler_deleted_action', [ $this, 'clear_deleted_action_logs' ], 10, 1 ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Delete the action logs for an action. |
|
109 | - * |
|
110 | - * @param int $action_id Action ID. |
|
111 | - */ |
|
112 | - public function clear_deleted_action_logs( $action_id ) { |
|
113 | - /** @var \wpdb $wpdb */ |
|
114 | - global $wpdb; |
|
115 | - $wpdb->delete( $wpdb->actionscheduler_logs, [ 'action_id' => $action_id, ], [ '%d' ] ); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Bulk add cancel action log entries. |
|
120 | - * |
|
121 | - * @param array $action_ids List of action ID. |
|
122 | - */ |
|
123 | - public function bulk_log_cancel_actions( $action_ids ) { |
|
124 | - if ( empty( $action_ids ) ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - /** @var \wpdb $wpdb */ |
|
129 | - global $wpdb; |
|
130 | - $date = as_get_datetime_object(); |
|
131 | - $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
132 | - ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
133 | - $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
134 | - $message = __( 'action canceled', 'action-scheduler' ); |
|
135 | - $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')'; |
|
136 | - $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES "; |
|
137 | - $value_rows = []; |
|
138 | - |
|
139 | - foreach ( $action_ids as $action_id ) { |
|
140 | - $value_rows[] = $wpdb->prepare( $format, $action_id ); |
|
141 | - } |
|
142 | - $sql_query .= implode( ',', $value_rows ); |
|
143 | - |
|
144 | - $wpdb->query( $sql_query ); |
|
145 | - } |
|
12 | + /** |
|
13 | + * Add a record to an action log. |
|
14 | + * |
|
15 | + * @param int $action_id Action ID. |
|
16 | + * @param string $message Message to be saved in the log entry. |
|
17 | + * @param DateTime $date Timestamp of the log entry. |
|
18 | + * |
|
19 | + * @return int The log entry ID. |
|
20 | + */ |
|
21 | + public function log( $action_id, $message, DateTime $date = null ) { |
|
22 | + if ( empty( $date ) ) { |
|
23 | + $date = as_get_datetime_object(); |
|
24 | + } else { |
|
25 | + $date = clone $date; |
|
26 | + } |
|
27 | + |
|
28 | + $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
29 | + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
30 | + $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
31 | + |
|
32 | + /** @var \wpdb $wpdb */ |
|
33 | + global $wpdb; |
|
34 | + $wpdb->insert( $wpdb->actionscheduler_logs, [ |
|
35 | + 'action_id' => $action_id, |
|
36 | + 'message' => $message, |
|
37 | + 'log_date_gmt' => $date_gmt, |
|
38 | + 'log_date_local' => $date_local, |
|
39 | + ], [ '%d', '%s', '%s', '%s' ] ); |
|
40 | + |
|
41 | + return $wpdb->insert_id; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Retrieve an action log entry. |
|
46 | + * |
|
47 | + * @param int $entry_id Log entry ID. |
|
48 | + * |
|
49 | + * @return ActionScheduler_LogEntry |
|
50 | + */ |
|
51 | + public function get_entry( $entry_id ) { |
|
52 | + /** @var \wpdb $wpdb */ |
|
53 | + global $wpdb; |
|
54 | + $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) ); |
|
55 | + |
|
56 | + return $this->create_entry_from_db_record( $entry ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Create an action log entry from a database record. |
|
61 | + * |
|
62 | + * @param object $record Log entry database record object. |
|
63 | + * |
|
64 | + * @return ActionScheduler_LogEntry |
|
65 | + */ |
|
66 | + private function create_entry_from_db_record( $record ) { |
|
67 | + if ( empty( $record ) ) { |
|
68 | + return new ActionScheduler_NullLogEntry(); |
|
69 | + } |
|
70 | + |
|
71 | + $date = as_get_datetime_object( $record->log_date_gmt ); |
|
72 | + |
|
73 | + return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Retrieve the an action's log entries from the database. |
|
78 | + * |
|
79 | + * @param int $action_id Action ID. |
|
80 | + * |
|
81 | + * @return ActionScheduler_LogEntry[] |
|
82 | + */ |
|
83 | + public function get_logs( $action_id ) { |
|
84 | + /** @var \wpdb $wpdb */ |
|
85 | + global $wpdb; |
|
86 | + |
|
87 | + $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) ); |
|
88 | + |
|
89 | + return array_map( [ $this, 'create_entry_from_db_record' ], $records ); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Initialize the data store. |
|
94 | + * |
|
95 | + * @codeCoverageIgnore |
|
96 | + */ |
|
97 | + public function init() { |
|
98 | + |
|
99 | + $table_maker = new ActionScheduler_LoggerSchema(); |
|
100 | + $table_maker->register_tables(); |
|
101 | + |
|
102 | + parent::init(); |
|
103 | + |
|
104 | + add_action( 'action_scheduler_deleted_action', [ $this, 'clear_deleted_action_logs' ], 10, 1 ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Delete the action logs for an action. |
|
109 | + * |
|
110 | + * @param int $action_id Action ID. |
|
111 | + */ |
|
112 | + public function clear_deleted_action_logs( $action_id ) { |
|
113 | + /** @var \wpdb $wpdb */ |
|
114 | + global $wpdb; |
|
115 | + $wpdb->delete( $wpdb->actionscheduler_logs, [ 'action_id' => $action_id, ], [ '%d' ] ); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Bulk add cancel action log entries. |
|
120 | + * |
|
121 | + * @param array $action_ids List of action ID. |
|
122 | + */ |
|
123 | + public function bulk_log_cancel_actions( $action_ids ) { |
|
124 | + if ( empty( $action_ids ) ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + /** @var \wpdb $wpdb */ |
|
129 | + global $wpdb; |
|
130 | + $date = as_get_datetime_object(); |
|
131 | + $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
132 | + ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
133 | + $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
134 | + $message = __( 'action canceled', 'action-scheduler' ); |
|
135 | + $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')'; |
|
136 | + $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES "; |
|
137 | + $value_rows = []; |
|
138 | + |
|
139 | + foreach ( $action_ids as $action_id ) { |
|
140 | + $value_rows[] = $wpdb->prepare( $format, $action_id ); |
|
141 | + } |
|
142 | + $sql_query .= implode( ',', $value_rows ); |
|
143 | + |
|
144 | + $wpdb->query( $sql_query ); |
|
145 | + } |
|
146 | 146 | } |
@@ -18,25 +18,25 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return int The log entry ID. |
20 | 20 | */ |
21 | - public function log( $action_id, $message, DateTime $date = null ) { |
|
22 | - if ( empty( $date ) ) { |
|
21 | + public function log($action_id, $message, DateTime $date = null) { |
|
22 | + if (empty($date)) { |
|
23 | 23 | $date = as_get_datetime_object(); |
24 | 24 | } else { |
25 | 25 | $date = clone $date; |
26 | 26 | } |
27 | 27 | |
28 | - $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
29 | - ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
30 | - $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
28 | + $date_gmt = $date->format('Y-m-d H:i:s'); |
|
29 | + ActionScheduler_TimezoneHelper::set_local_timezone($date); |
|
30 | + $date_local = $date->format('Y-m-d H:i:s'); |
|
31 | 31 | |
32 | 32 | /** @var \wpdb $wpdb */ |
33 | 33 | global $wpdb; |
34 | - $wpdb->insert( $wpdb->actionscheduler_logs, [ |
|
34 | + $wpdb->insert($wpdb->actionscheduler_logs, [ |
|
35 | 35 | 'action_id' => $action_id, |
36 | 36 | 'message' => $message, |
37 | 37 | 'log_date_gmt' => $date_gmt, |
38 | 38 | 'log_date_local' => $date_local, |
39 | - ], [ '%d', '%s', '%s', '%s' ] ); |
|
39 | + ], ['%d', '%s', '%s', '%s']); |
|
40 | 40 | |
41 | 41 | return $wpdb->insert_id; |
42 | 42 | } |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return ActionScheduler_LogEntry |
50 | 50 | */ |
51 | - public function get_entry( $entry_id ) { |
|
51 | + public function get_entry($entry_id) { |
|
52 | 52 | /** @var \wpdb $wpdb */ |
53 | 53 | global $wpdb; |
54 | - $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) ); |
|
54 | + $entry = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id)); |
|
55 | 55 | |
56 | - return $this->create_entry_from_db_record( $entry ); |
|
56 | + return $this->create_entry_from_db_record($entry); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return ActionScheduler_LogEntry |
65 | 65 | */ |
66 | - private function create_entry_from_db_record( $record ) { |
|
67 | - if ( empty( $record ) ) { |
|
66 | + private function create_entry_from_db_record($record) { |
|
67 | + if (empty($record)) { |
|
68 | 68 | return new ActionScheduler_NullLogEntry(); |
69 | 69 | } |
70 | 70 | |
71 | - $date = as_get_datetime_object( $record->log_date_gmt ); |
|
71 | + $date = as_get_datetime_object($record->log_date_gmt); |
|
72 | 72 | |
73 | - return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date ); |
|
73 | + return new ActionScheduler_LogEntry($record->action_id, $record->message, $date); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return ActionScheduler_LogEntry[] |
82 | 82 | */ |
83 | - public function get_logs( $action_id ) { |
|
83 | + public function get_logs($action_id) { |
|
84 | 84 | /** @var \wpdb $wpdb */ |
85 | 85 | global $wpdb; |
86 | 86 | |
87 | - $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) ); |
|
87 | + $records = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id)); |
|
88 | 88 | |
89 | - return array_map( [ $this, 'create_entry_from_db_record' ], $records ); |
|
89 | + return array_map([$this, 'create_entry_from_db_record'], $records); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | parent::init(); |
103 | 103 | |
104 | - add_action( 'action_scheduler_deleted_action', [ $this, 'clear_deleted_action_logs' ], 10, 1 ); |
|
104 | + add_action('action_scheduler_deleted_action', [$this, 'clear_deleted_action_logs'], 10, 1); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param int $action_id Action ID. |
111 | 111 | */ |
112 | - public function clear_deleted_action_logs( $action_id ) { |
|
112 | + public function clear_deleted_action_logs($action_id) { |
|
113 | 113 | /** @var \wpdb $wpdb */ |
114 | 114 | global $wpdb; |
115 | - $wpdb->delete( $wpdb->actionscheduler_logs, [ 'action_id' => $action_id, ], [ '%d' ] ); |
|
115 | + $wpdb->delete($wpdb->actionscheduler_logs, ['action_id' => $action_id, ], ['%d']); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,27 +120,27 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @param array $action_ids List of action ID. |
122 | 122 | */ |
123 | - public function bulk_log_cancel_actions( $action_ids ) { |
|
124 | - if ( empty( $action_ids ) ) { |
|
123 | + public function bulk_log_cancel_actions($action_ids) { |
|
124 | + if (empty($action_ids)) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | 128 | /** @var \wpdb $wpdb */ |
129 | 129 | global $wpdb; |
130 | 130 | $date = as_get_datetime_object(); |
131 | - $date_gmt = $date->format( 'Y-m-d H:i:s' ); |
|
132 | - ActionScheduler_TimezoneHelper::set_local_timezone( $date ); |
|
133 | - $date_local = $date->format( 'Y-m-d H:i:s' ); |
|
134 | - $message = __( 'action canceled', 'action-scheduler' ); |
|
135 | - $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')'; |
|
131 | + $date_gmt = $date->format('Y-m-d H:i:s'); |
|
132 | + ActionScheduler_TimezoneHelper::set_local_timezone($date); |
|
133 | + $date_local = $date->format('Y-m-d H:i:s'); |
|
134 | + $message = __('action canceled', 'action-scheduler'); |
|
135 | + $format = '(%d, ' . $wpdb->prepare('%s, %s, %s', $message, $date_gmt, $date_local) . ')'; |
|
136 | 136 | $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES "; |
137 | 137 | $value_rows = []; |
138 | 138 | |
139 | - foreach ( $action_ids as $action_id ) { |
|
140 | - $value_rows[] = $wpdb->prepare( $format, $action_id ); |
|
139 | + foreach ($action_ids as $action_id) { |
|
140 | + $value_rows[] = $wpdb->prepare($format, $action_id); |
|
141 | 141 | } |
142 | - $sql_query .= implode( ',', $value_rows ); |
|
142 | + $sql_query .= implode(',', $value_rows); |
|
143 | 143 | |
144 | - $wpdb->query( $sql_query ); |
|
144 | + $wpdb->query($sql_query); |
|
145 | 145 | } |
146 | 146 | } |