@@ -6,22 +6,22 @@ |
||
6 | 6 | * @codeCoverageIgnore |
7 | 7 | */ |
8 | 8 | class ActionScheduler_wpPostStore_TaxonomyRegistrar { |
9 | - public function register() { |
|
10 | - register_taxonomy( ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args() ); |
|
11 | - } |
|
9 | + public function register() { |
|
10 | + register_taxonomy( ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args() ); |
|
11 | + } |
|
12 | 12 | |
13 | - protected function taxonomy_args() { |
|
14 | - $args = array( |
|
15 | - 'label' => __( 'Action Group', 'action-scheduler' ), |
|
16 | - 'public' => false, |
|
17 | - 'hierarchical' => false, |
|
18 | - 'show_admin_column' => true, |
|
19 | - 'query_var' => false, |
|
20 | - 'rewrite' => false, |
|
21 | - ); |
|
13 | + protected function taxonomy_args() { |
|
14 | + $args = array( |
|
15 | + 'label' => __( 'Action Group', 'action-scheduler' ), |
|
16 | + 'public' => false, |
|
17 | + 'hierarchical' => false, |
|
18 | + 'show_admin_column' => true, |
|
19 | + 'query_var' => false, |
|
20 | + 'rewrite' => false, |
|
21 | + ); |
|
22 | 22 | |
23 | - $args = apply_filters( 'action_scheduler_taxonomy_args', $args ); |
|
24 | - return $args; |
|
25 | - } |
|
23 | + $args = apply_filters( 'action_scheduler_taxonomy_args', $args ); |
|
24 | + return $args; |
|
25 | + } |
|
26 | 26 | } |
27 | 27 |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class ActionScheduler_wpPostStore_TaxonomyRegistrar { |
9 | 9 | public function register() { |
10 | - register_taxonomy( ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args() ); |
|
10 | + register_taxonomy(ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args()); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | protected function taxonomy_args() { |
14 | 14 | $args = array( |
15 | - 'label' => __( 'Action Group', 'action-scheduler' ), |
|
15 | + 'label' => __('Action Group', 'action-scheduler'), |
|
16 | 16 | 'public' => false, |
17 | 17 | 'hierarchical' => false, |
18 | 18 | 'show_admin_column' => true, |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | 'rewrite' => false, |
21 | 21 | ); |
22 | 22 | |
23 | - $args = apply_filters( 'action_scheduler_taxonomy_args', $args ); |
|
23 | + $args = apply_filters('action_scheduler_taxonomy_args', $args); |
|
24 | 24 | return $args; |
25 | 25 | } |
26 | 26 | } |
@@ -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,160 +5,160 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_QueueCleaner { |
7 | 7 | |
8 | - /** @var int */ |
|
9 | - protected $batch_size; |
|
10 | - |
|
11 | - /** @var ActionScheduler_Store */ |
|
12 | - private $store = null; |
|
13 | - |
|
14 | - /** |
|
15 | - * 31 days in seconds. |
|
16 | - * |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - private $month_in_seconds = 2678400; |
|
20 | - |
|
21 | - /** |
|
22 | - * ActionScheduler_QueueCleaner constructor. |
|
23 | - * |
|
24 | - * @param ActionScheduler_Store $store The store instance. |
|
25 | - * @param int $batch_size The batch size. |
|
26 | - */ |
|
27 | - public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
28 | - $this->store = $store ? $store : ActionScheduler_Store::instance(); |
|
29 | - $this->batch_size = $batch_size; |
|
30 | - } |
|
31 | - |
|
32 | - public function delete_old_actions() { |
|
33 | - $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
34 | - $cutoff = as_get_datetime_object( $lifespan . ' seconds ago' ); |
|
35 | - |
|
36 | - $statuses_to_purge = array( |
|
37 | - ActionScheduler_Store::STATUS_COMPLETE, |
|
38 | - ActionScheduler_Store::STATUS_CANCELED, |
|
39 | - ); |
|
40 | - |
|
41 | - foreach ( $statuses_to_purge as $status ) { |
|
42 | - $actions_to_delete = $this->store->query_actions( |
|
43 | - array( |
|
44 | - 'status' => $status, |
|
45 | - 'modified' => $cutoff, |
|
46 | - 'modified_compare' => '<=', |
|
47 | - 'per_page' => $this->get_batch_size(), |
|
48 | - 'orderby' => 'none', |
|
49 | - ) |
|
50 | - ); |
|
51 | - |
|
52 | - foreach ( $actions_to_delete as $action_id ) { |
|
53 | - try { |
|
54 | - $this->store->delete_action( $action_id ); |
|
55 | - } catch ( Exception $e ) { |
|
56 | - |
|
57 | - /** |
|
58 | - * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
|
59 | - * |
|
60 | - * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their |
|
61 | - * actions. |
|
62 | - * |
|
63 | - * @since 2.0.0 |
|
64 | - * |
|
65 | - * @param int $action_id The scheduled actions ID in the data store |
|
66 | - * @param Exception $e The exception thrown when attempting to delete the action from the data store |
|
67 | - * @param int $lifespan The retention period, in seconds, for old actions |
|
68 | - * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
|
69 | - */ |
|
70 | - do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Unclaim pending actions that have not been run within a given time limit. |
|
78 | - * |
|
79 | - * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
80 | - * as a parameter is 10x the time limit used for queue processing. |
|
81 | - * |
|
82 | - * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
|
83 | - */ |
|
84 | - public function reset_timeouts( $time_limit = 300 ) { |
|
85 | - $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
86 | - if ( $timeout < 0 ) { |
|
87 | - return; |
|
88 | - } |
|
89 | - $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
90 | - $actions_to_reset = $this->store->query_actions( |
|
91 | - array( |
|
92 | - 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
93 | - 'modified' => $cutoff, |
|
94 | - 'modified_compare' => '<=', |
|
95 | - 'claimed' => true, |
|
96 | - 'per_page' => $this->get_batch_size(), |
|
97 | - 'orderby' => 'none', |
|
98 | - ) |
|
99 | - ); |
|
100 | - |
|
101 | - foreach ( $actions_to_reset as $action_id ) { |
|
102 | - $this->store->unclaim_action( $action_id ); |
|
103 | - do_action( 'action_scheduler_reset_action', $action_id ); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Mark actions that have been running for more than a given time limit as failed, based on |
|
109 | - * the assumption some uncatachable and unloggable fatal error occurred during processing. |
|
110 | - * |
|
111 | - * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
112 | - * as a parameter is 10x the time limit used for queue processing. |
|
113 | - * |
|
114 | - * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
|
115 | - */ |
|
116 | - public function mark_failures( $time_limit = 300 ) { |
|
117 | - $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
118 | - if ( $timeout < 0 ) { |
|
119 | - return; |
|
120 | - } |
|
121 | - $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
122 | - $actions_to_reset = $this->store->query_actions( |
|
123 | - array( |
|
124 | - 'status' => ActionScheduler_Store::STATUS_RUNNING, |
|
125 | - 'modified' => $cutoff, |
|
126 | - 'modified_compare' => '<=', |
|
127 | - 'per_page' => $this->get_batch_size(), |
|
128 | - 'orderby' => 'none', |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - foreach ( $actions_to_reset as $action_id ) { |
|
133 | - $this->store->mark_failure( $action_id ); |
|
134 | - do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Do all of the cleaning actions. |
|
140 | - * |
|
141 | - * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
|
142 | - * @author Jeremy Pry |
|
143 | - */ |
|
144 | - public function clean( $time_limit = 300 ) { |
|
145 | - $this->delete_old_actions(); |
|
146 | - $this->reset_timeouts( $time_limit ); |
|
147 | - $this->mark_failures( $time_limit ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Get the batch size for cleaning the queue. |
|
152 | - * |
|
153 | - * @author Jeremy Pry |
|
154 | - * @return int |
|
155 | - */ |
|
156 | - protected function get_batch_size() { |
|
157 | - /** |
|
158 | - * Filter the batch size when cleaning the queue. |
|
159 | - * |
|
160 | - * @param int $batch_size The number of actions to clean in one batch. |
|
161 | - */ |
|
162 | - return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
163 | - } |
|
8 | + /** @var int */ |
|
9 | + protected $batch_size; |
|
10 | + |
|
11 | + /** @var ActionScheduler_Store */ |
|
12 | + private $store = null; |
|
13 | + |
|
14 | + /** |
|
15 | + * 31 days in seconds. |
|
16 | + * |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + private $month_in_seconds = 2678400; |
|
20 | + |
|
21 | + /** |
|
22 | + * ActionScheduler_QueueCleaner constructor. |
|
23 | + * |
|
24 | + * @param ActionScheduler_Store $store The store instance. |
|
25 | + * @param int $batch_size The batch size. |
|
26 | + */ |
|
27 | + public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
28 | + $this->store = $store ? $store : ActionScheduler_Store::instance(); |
|
29 | + $this->batch_size = $batch_size; |
|
30 | + } |
|
31 | + |
|
32 | + public function delete_old_actions() { |
|
33 | + $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
34 | + $cutoff = as_get_datetime_object( $lifespan . ' seconds ago' ); |
|
35 | + |
|
36 | + $statuses_to_purge = array( |
|
37 | + ActionScheduler_Store::STATUS_COMPLETE, |
|
38 | + ActionScheduler_Store::STATUS_CANCELED, |
|
39 | + ); |
|
40 | + |
|
41 | + foreach ( $statuses_to_purge as $status ) { |
|
42 | + $actions_to_delete = $this->store->query_actions( |
|
43 | + array( |
|
44 | + 'status' => $status, |
|
45 | + 'modified' => $cutoff, |
|
46 | + 'modified_compare' => '<=', |
|
47 | + 'per_page' => $this->get_batch_size(), |
|
48 | + 'orderby' => 'none', |
|
49 | + ) |
|
50 | + ); |
|
51 | + |
|
52 | + foreach ( $actions_to_delete as $action_id ) { |
|
53 | + try { |
|
54 | + $this->store->delete_action( $action_id ); |
|
55 | + } catch ( Exception $e ) { |
|
56 | + |
|
57 | + /** |
|
58 | + * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
|
59 | + * |
|
60 | + * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their |
|
61 | + * actions. |
|
62 | + * |
|
63 | + * @since 2.0.0 |
|
64 | + * |
|
65 | + * @param int $action_id The scheduled actions ID in the data store |
|
66 | + * @param Exception $e The exception thrown when attempting to delete the action from the data store |
|
67 | + * @param int $lifespan The retention period, in seconds, for old actions |
|
68 | + * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
|
69 | + */ |
|
70 | + do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Unclaim pending actions that have not been run within a given time limit. |
|
78 | + * |
|
79 | + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
80 | + * as a parameter is 10x the time limit used for queue processing. |
|
81 | + * |
|
82 | + * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
|
83 | + */ |
|
84 | + public function reset_timeouts( $time_limit = 300 ) { |
|
85 | + $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
86 | + if ( $timeout < 0 ) { |
|
87 | + return; |
|
88 | + } |
|
89 | + $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
90 | + $actions_to_reset = $this->store->query_actions( |
|
91 | + array( |
|
92 | + 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
93 | + 'modified' => $cutoff, |
|
94 | + 'modified_compare' => '<=', |
|
95 | + 'claimed' => true, |
|
96 | + 'per_page' => $this->get_batch_size(), |
|
97 | + 'orderby' => 'none', |
|
98 | + ) |
|
99 | + ); |
|
100 | + |
|
101 | + foreach ( $actions_to_reset as $action_id ) { |
|
102 | + $this->store->unclaim_action( $action_id ); |
|
103 | + do_action( 'action_scheduler_reset_action', $action_id ); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Mark actions that have been running for more than a given time limit as failed, based on |
|
109 | + * the assumption some uncatachable and unloggable fatal error occurred during processing. |
|
110 | + * |
|
111 | + * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed |
|
112 | + * as a parameter is 10x the time limit used for queue processing. |
|
113 | + * |
|
114 | + * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
|
115 | + */ |
|
116 | + public function mark_failures( $time_limit = 300 ) { |
|
117 | + $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
118 | + if ( $timeout < 0 ) { |
|
119 | + return; |
|
120 | + } |
|
121 | + $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
122 | + $actions_to_reset = $this->store->query_actions( |
|
123 | + array( |
|
124 | + 'status' => ActionScheduler_Store::STATUS_RUNNING, |
|
125 | + 'modified' => $cutoff, |
|
126 | + 'modified_compare' => '<=', |
|
127 | + 'per_page' => $this->get_batch_size(), |
|
128 | + 'orderby' => 'none', |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + foreach ( $actions_to_reset as $action_id ) { |
|
133 | + $this->store->mark_failure( $action_id ); |
|
134 | + do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Do all of the cleaning actions. |
|
140 | + * |
|
141 | + * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
|
142 | + * @author Jeremy Pry |
|
143 | + */ |
|
144 | + public function clean( $time_limit = 300 ) { |
|
145 | + $this->delete_old_actions(); |
|
146 | + $this->reset_timeouts( $time_limit ); |
|
147 | + $this->mark_failures( $time_limit ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Get the batch size for cleaning the queue. |
|
152 | + * |
|
153 | + * @author Jeremy Pry |
|
154 | + * @return int |
|
155 | + */ |
|
156 | + protected function get_batch_size() { |
|
157 | + /** |
|
158 | + * Filter the batch size when cleaning the queue. |
|
159 | + * |
|
160 | + * @param int $batch_size The number of actions to clean in one batch. |
|
161 | + */ |
|
162 | + return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
163 | + } |
|
164 | 164 | } |
@@ -24,21 +24,21 @@ discard block |
||
24 | 24 | * @param ActionScheduler_Store $store The store instance. |
25 | 25 | * @param int $batch_size The batch size. |
26 | 26 | */ |
27 | - public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { |
|
27 | + public function __construct(ActionScheduler_Store $store = null, $batch_size = 20) { |
|
28 | 28 | $this->store = $store ? $store : ActionScheduler_Store::instance(); |
29 | 29 | $this->batch_size = $batch_size; |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function delete_old_actions() { |
33 | - $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); |
|
34 | - $cutoff = as_get_datetime_object( $lifespan . ' seconds ago' ); |
|
33 | + $lifespan = apply_filters('action_scheduler_retention_period', $this->month_in_seconds); |
|
34 | + $cutoff = as_get_datetime_object($lifespan.' seconds ago'); |
|
35 | 35 | |
36 | 36 | $statuses_to_purge = array( |
37 | 37 | ActionScheduler_Store::STATUS_COMPLETE, |
38 | 38 | ActionScheduler_Store::STATUS_CANCELED, |
39 | 39 | ); |
40 | 40 | |
41 | - foreach ( $statuses_to_purge as $status ) { |
|
41 | + foreach ($statuses_to_purge as $status) { |
|
42 | 42 | $actions_to_delete = $this->store->query_actions( |
43 | 43 | array( |
44 | 44 | 'status' => $status, |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | |
52 | - foreach ( $actions_to_delete as $action_id ) { |
|
52 | + foreach ($actions_to_delete as $action_id) { |
|
53 | 53 | try { |
54 | - $this->store->delete_action( $action_id ); |
|
55 | - } catch ( Exception $e ) { |
|
54 | + $this->store->delete_action($action_id); |
|
55 | + } catch (Exception $e) { |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Notify 3rd party code of exceptions when deleting a completed action older than the retention period |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param int $lifespan The retention period, in seconds, for old actions |
68 | 68 | * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch |
69 | 69 | */ |
70 | - do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); |
|
70 | + do_action('action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count($actions_to_delete)); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | } |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes). |
83 | 83 | */ |
84 | - public function reset_timeouts( $time_limit = 300 ) { |
|
85 | - $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit ); |
|
86 | - if ( $timeout < 0 ) { |
|
84 | + public function reset_timeouts($time_limit = 300) { |
|
85 | + $timeout = apply_filters('action_scheduler_timeout_period', $time_limit); |
|
86 | + if ($timeout < 0) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | - $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
89 | + $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
90 | 90 | $actions_to_reset = $this->store->query_actions( |
91 | 91 | array( |
92 | 92 | 'status' => ActionScheduler_Store::STATUS_PENDING, |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | ) |
99 | 99 | ); |
100 | 100 | |
101 | - foreach ( $actions_to_reset as $action_id ) { |
|
102 | - $this->store->unclaim_action( $action_id ); |
|
103 | - do_action( 'action_scheduler_reset_action', $action_id ); |
|
101 | + foreach ($actions_to_reset as $action_id) { |
|
102 | + $this->store->unclaim_action($action_id); |
|
103 | + do_action('action_scheduler_reset_action', $action_id); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes). |
115 | 115 | */ |
116 | - public function mark_failures( $time_limit = 300 ) { |
|
117 | - $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit ); |
|
118 | - if ( $timeout < 0 ) { |
|
116 | + public function mark_failures($time_limit = 300) { |
|
117 | + $timeout = apply_filters('action_scheduler_failure_period', $time_limit); |
|
118 | + if ($timeout < 0) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | - $cutoff = as_get_datetime_object( $timeout . ' seconds ago' ); |
|
121 | + $cutoff = as_get_datetime_object($timeout.' seconds ago'); |
|
122 | 122 | $actions_to_reset = $this->store->query_actions( |
123 | 123 | array( |
124 | 124 | 'status' => ActionScheduler_Store::STATUS_RUNNING, |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | ) |
130 | 130 | ); |
131 | 131 | |
132 | - foreach ( $actions_to_reset as $action_id ) { |
|
133 | - $this->store->mark_failure( $action_id ); |
|
134 | - do_action( 'action_scheduler_failed_action', $action_id, $timeout ); |
|
132 | + foreach ($actions_to_reset as $action_id) { |
|
133 | + $this->store->mark_failure($action_id); |
|
134 | + do_action('action_scheduler_failed_action', $action_id, $timeout); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes). |
142 | 142 | * @author Jeremy Pry |
143 | 143 | */ |
144 | - public function clean( $time_limit = 300 ) { |
|
144 | + public function clean($time_limit = 300) { |
|
145 | 145 | $this->delete_old_actions(); |
146 | - $this->reset_timeouts( $time_limit ); |
|
147 | - $this->mark_failures( $time_limit ); |
|
146 | + $this->reset_timeouts($time_limit); |
|
147 | + $this->mark_failures($time_limit); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -159,6 +159,6 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @param int $batch_size The number of actions to clean in one batch. |
161 | 161 | */ |
162 | - return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); |
|
162 | + return absint(apply_filters('action_scheduler_cleanup_batch_size', $this->batch_size)); |
|
163 | 163 | } |
164 | 164 | } |
@@ -7,242 +7,242 @@ |
||
7 | 7 | */ |
8 | 8 | class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated { |
9 | 9 | |
10 | - private static $admin_view = null; |
|
11 | - |
|
12 | - private static $screen_id = 'tools_page_action-scheduler'; |
|
13 | - |
|
14 | - /** @var ActionScheduler_ListTable */ |
|
15 | - protected $list_table; |
|
16 | - |
|
17 | - /** |
|
18 | - * @return ActionScheduler_AdminView |
|
19 | - * @codeCoverageIgnore |
|
20 | - */ |
|
21 | - public static function instance() { |
|
22 | - |
|
23 | - if ( empty( self::$admin_view ) ) { |
|
24 | - $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' ); |
|
25 | - self::$admin_view = new $class(); |
|
26 | - } |
|
27 | - |
|
28 | - return self::$admin_view; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @codeCoverageIgnore |
|
33 | - */ |
|
34 | - public function init() { |
|
35 | - if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) { |
|
36 | - |
|
37 | - if ( class_exists( 'WooCommerce' ) ) { |
|
38 | - add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) ); |
|
39 | - add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) ); |
|
40 | - add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) ); |
|
41 | - } |
|
42 | - |
|
43 | - add_action( 'admin_menu', array( $this, 'register_menu' ) ); |
|
44 | - add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) ); |
|
45 | - add_action( 'current_screen', array( $this, 'add_help_tabs' ) ); |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - public function system_status_report() { |
|
50 | - $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() ); |
|
51 | - $table->render(); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Registers action-scheduler into WooCommerce > System status. |
|
56 | - * |
|
57 | - * @param array $tabs An associative array of tab key => label. |
|
58 | - * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs |
|
59 | - */ |
|
60 | - public function register_system_status_tab( array $tabs ) { |
|
61 | - $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' ); |
|
62 | - |
|
63 | - return $tabs; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Include Action Scheduler's administration under the Tools menu. |
|
68 | - * |
|
69 | - * A menu under the Tools menu is important for backward compatibility (as that's |
|
70 | - * where it started), and also provides more convenient access than the WooCommerce |
|
71 | - * System Status page, and for sites where WooCommerce isn't active. |
|
72 | - */ |
|
73 | - public function register_menu() { |
|
74 | - $hook_suffix = add_submenu_page( |
|
75 | - 'tools.php', |
|
76 | - __( 'Scheduled Actions', 'action-scheduler' ), |
|
77 | - __( 'Scheduled Actions', 'action-scheduler' ), |
|
78 | - 'manage_options', |
|
79 | - 'action-scheduler', |
|
80 | - array( $this, 'render_admin_ui' ) |
|
81 | - ); |
|
82 | - add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Triggers processing of any pending actions. |
|
87 | - */ |
|
88 | - public function process_admin_ui() { |
|
89 | - $this->get_list_table(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Renders the Admin UI |
|
94 | - */ |
|
95 | - public function render_admin_ui() { |
|
96 | - $table = $this->get_list_table(); |
|
97 | - $table->display_page(); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get the admin UI object and process any requested actions. |
|
102 | - * |
|
103 | - * @return ActionScheduler_ListTable |
|
104 | - */ |
|
105 | - protected function get_list_table() { |
|
106 | - if ( null === $this->list_table ) { |
|
107 | - $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); |
|
108 | - $this->list_table->process_actions(); |
|
109 | - } |
|
110 | - |
|
111 | - return $this->list_table; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Action: admin_notices |
|
116 | - * |
|
117 | - * Maybe check past-due actions, and print notice. |
|
118 | - * |
|
119 | - * @uses $this->check_pastdue_actions() |
|
120 | - */ |
|
121 | - public function maybe_check_pastdue_actions() { |
|
122 | - |
|
123 | - // Filter to prevent checking actions (ex: inappropriate user). |
|
124 | - if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - // Get last check transient. |
|
129 | - $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' ); |
|
130 | - |
|
131 | - // If transient exists, we're within interval, so bail. |
|
132 | - if ( ! empty( $last_check ) ) { |
|
133 | - return; |
|
134 | - } |
|
135 | - |
|
136 | - // Perform the check. |
|
137 | - $this->check_pastdue_actions(); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Check past-due actions, and print notice. |
|
142 | - * |
|
143 | - * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511) |
|
144 | - */ |
|
145 | - protected function check_pastdue_actions() { |
|
146 | - |
|
147 | - // Set thresholds. |
|
148 | - $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS ); |
|
149 | - $threshhold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 ); |
|
150 | - |
|
151 | - // Allow third-parties to preempt the default check logic. |
|
152 | - $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null ); |
|
153 | - |
|
154 | - // Scheduled actions query arguments. |
|
155 | - $query_args = array( |
|
156 | - 'date' => as_get_datetime_object( time() - $threshold_seconds ), |
|
157 | - 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
158 | - 'per_page' => $threshhold_min, |
|
159 | - ); |
|
160 | - |
|
161 | - // If no third-party preempted, run default check. |
|
162 | - if ( $check === null ) { |
|
163 | - $store = ActionScheduler_Store::instance(); |
|
164 | - $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' ); |
|
165 | - |
|
166 | - // Check if past-due actions count is greater than or equal to threshold. |
|
167 | - $check = ( $num_pastdue_actions >= $threshhold_min ); |
|
168 | - $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min ); |
|
169 | - } |
|
170 | - |
|
171 | - // If check failed, set transient and abort. |
|
172 | - if ( ! boolval( $check ) ) { |
|
173 | - $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds ); |
|
174 | - set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval ); |
|
175 | - |
|
176 | - return; |
|
177 | - } |
|
178 | - |
|
179 | - $actions_url = add_query_arg( |
|
180 | - array( |
|
181 | - 'page' => 'action-scheduler', |
|
182 | - 'status' => 'past-due', |
|
183 | - 'order' => 'asc', |
|
184 | - ), |
|
185 | - admin_url( 'tools.php' ) |
|
186 | - ); |
|
187 | - |
|
188 | - // Print notice. |
|
189 | - echo '<div class="notice notice-warning"><p>'; |
|
190 | - printf( |
|
191 | - _n( |
|
192 | - // translators: 1) is the number of affected actions, 2) is a link to an admin screen. |
|
193 | - '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>', |
|
194 | - '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>', |
|
195 | - $num_pastdue_actions, |
|
196 | - 'action-scheduler' |
|
197 | - ), |
|
198 | - $num_pastdue_actions, |
|
199 | - esc_attr( esc_url( $actions_url ) ) |
|
200 | - ); |
|
201 | - echo '</p></div>'; |
|
202 | - |
|
203 | - // Facilitate third-parties to evaluate and print notices. |
|
204 | - do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Provide more information about the screen and its data in the help tab. |
|
209 | - */ |
|
210 | - public function add_help_tabs() { |
|
211 | - $screen = get_current_screen(); |
|
212 | - |
|
213 | - if ( ! $screen || self::$screen_id != $screen->id ) { |
|
214 | - return; |
|
215 | - } |
|
216 | - |
|
217 | - $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
218 | - $screen->add_help_tab( |
|
219 | - array( |
|
220 | - 'id' => 'action_scheduler_about', |
|
221 | - 'title' => __( 'About', 'action-scheduler' ), |
|
222 | - 'content' => |
|
223 | - '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' . |
|
224 | - '<p>' . |
|
225 | - __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) . |
|
226 | - '</p>', |
|
227 | - ) |
|
228 | - ); |
|
229 | - |
|
230 | - $screen->add_help_tab( |
|
231 | - array( |
|
232 | - 'id' => 'action_scheduler_columns', |
|
233 | - 'title' => __( 'Columns', 'action-scheduler' ), |
|
234 | - 'content' => |
|
235 | - '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' . |
|
236 | - '<ul>' . |
|
237 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) . |
|
238 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) . |
|
239 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) . |
|
240 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) . |
|
241 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) . |
|
242 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) . |
|
243 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) . |
|
244 | - '</ul>', |
|
245 | - ) |
|
246 | - ); |
|
247 | - } |
|
10 | + private static $admin_view = null; |
|
11 | + |
|
12 | + private static $screen_id = 'tools_page_action-scheduler'; |
|
13 | + |
|
14 | + /** @var ActionScheduler_ListTable */ |
|
15 | + protected $list_table; |
|
16 | + |
|
17 | + /** |
|
18 | + * @return ActionScheduler_AdminView |
|
19 | + * @codeCoverageIgnore |
|
20 | + */ |
|
21 | + public static function instance() { |
|
22 | + |
|
23 | + if ( empty( self::$admin_view ) ) { |
|
24 | + $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' ); |
|
25 | + self::$admin_view = new $class(); |
|
26 | + } |
|
27 | + |
|
28 | + return self::$admin_view; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @codeCoverageIgnore |
|
33 | + */ |
|
34 | + public function init() { |
|
35 | + if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) { |
|
36 | + |
|
37 | + if ( class_exists( 'WooCommerce' ) ) { |
|
38 | + add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) ); |
|
39 | + add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) ); |
|
40 | + add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) ); |
|
41 | + } |
|
42 | + |
|
43 | + add_action( 'admin_menu', array( $this, 'register_menu' ) ); |
|
44 | + add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) ); |
|
45 | + add_action( 'current_screen', array( $this, 'add_help_tabs' ) ); |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + public function system_status_report() { |
|
50 | + $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() ); |
|
51 | + $table->render(); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Registers action-scheduler into WooCommerce > System status. |
|
56 | + * |
|
57 | + * @param array $tabs An associative array of tab key => label. |
|
58 | + * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs |
|
59 | + */ |
|
60 | + public function register_system_status_tab( array $tabs ) { |
|
61 | + $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' ); |
|
62 | + |
|
63 | + return $tabs; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Include Action Scheduler's administration under the Tools menu. |
|
68 | + * |
|
69 | + * A menu under the Tools menu is important for backward compatibility (as that's |
|
70 | + * where it started), and also provides more convenient access than the WooCommerce |
|
71 | + * System Status page, and for sites where WooCommerce isn't active. |
|
72 | + */ |
|
73 | + public function register_menu() { |
|
74 | + $hook_suffix = add_submenu_page( |
|
75 | + 'tools.php', |
|
76 | + __( 'Scheduled Actions', 'action-scheduler' ), |
|
77 | + __( 'Scheduled Actions', 'action-scheduler' ), |
|
78 | + 'manage_options', |
|
79 | + 'action-scheduler', |
|
80 | + array( $this, 'render_admin_ui' ) |
|
81 | + ); |
|
82 | + add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Triggers processing of any pending actions. |
|
87 | + */ |
|
88 | + public function process_admin_ui() { |
|
89 | + $this->get_list_table(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Renders the Admin UI |
|
94 | + */ |
|
95 | + public function render_admin_ui() { |
|
96 | + $table = $this->get_list_table(); |
|
97 | + $table->display_page(); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get the admin UI object and process any requested actions. |
|
102 | + * |
|
103 | + * @return ActionScheduler_ListTable |
|
104 | + */ |
|
105 | + protected function get_list_table() { |
|
106 | + if ( null === $this->list_table ) { |
|
107 | + $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); |
|
108 | + $this->list_table->process_actions(); |
|
109 | + } |
|
110 | + |
|
111 | + return $this->list_table; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Action: admin_notices |
|
116 | + * |
|
117 | + * Maybe check past-due actions, and print notice. |
|
118 | + * |
|
119 | + * @uses $this->check_pastdue_actions() |
|
120 | + */ |
|
121 | + public function maybe_check_pastdue_actions() { |
|
122 | + |
|
123 | + // Filter to prevent checking actions (ex: inappropriate user). |
|
124 | + if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + // Get last check transient. |
|
129 | + $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' ); |
|
130 | + |
|
131 | + // If transient exists, we're within interval, so bail. |
|
132 | + if ( ! empty( $last_check ) ) { |
|
133 | + return; |
|
134 | + } |
|
135 | + |
|
136 | + // Perform the check. |
|
137 | + $this->check_pastdue_actions(); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Check past-due actions, and print notice. |
|
142 | + * |
|
143 | + * @todo update $link_url to "Past-due" filter when released (see issue #510, PR #511) |
|
144 | + */ |
|
145 | + protected function check_pastdue_actions() { |
|
146 | + |
|
147 | + // Set thresholds. |
|
148 | + $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS ); |
|
149 | + $threshhold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 ); |
|
150 | + |
|
151 | + // Allow third-parties to preempt the default check logic. |
|
152 | + $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null ); |
|
153 | + |
|
154 | + // Scheduled actions query arguments. |
|
155 | + $query_args = array( |
|
156 | + 'date' => as_get_datetime_object( time() - $threshold_seconds ), |
|
157 | + 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
158 | + 'per_page' => $threshhold_min, |
|
159 | + ); |
|
160 | + |
|
161 | + // If no third-party preempted, run default check. |
|
162 | + if ( $check === null ) { |
|
163 | + $store = ActionScheduler_Store::instance(); |
|
164 | + $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' ); |
|
165 | + |
|
166 | + // Check if past-due actions count is greater than or equal to threshold. |
|
167 | + $check = ( $num_pastdue_actions >= $threshhold_min ); |
|
168 | + $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min ); |
|
169 | + } |
|
170 | + |
|
171 | + // If check failed, set transient and abort. |
|
172 | + if ( ! boolval( $check ) ) { |
|
173 | + $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds ); |
|
174 | + set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval ); |
|
175 | + |
|
176 | + return; |
|
177 | + } |
|
178 | + |
|
179 | + $actions_url = add_query_arg( |
|
180 | + array( |
|
181 | + 'page' => 'action-scheduler', |
|
182 | + 'status' => 'past-due', |
|
183 | + 'order' => 'asc', |
|
184 | + ), |
|
185 | + admin_url( 'tools.php' ) |
|
186 | + ); |
|
187 | + |
|
188 | + // Print notice. |
|
189 | + echo '<div class="notice notice-warning"><p>'; |
|
190 | + printf( |
|
191 | + _n( |
|
192 | + // translators: 1) is the number of affected actions, 2) is a link to an admin screen. |
|
193 | + '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due action</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>', |
|
194 | + '<strong>Action Scheduler:</strong> %1$d <a href="%2$s">past-due actions</a> found; something may be wrong. <a href="https://actionscheduler.org/faq/#my-site-has-past-due-actions-what-can-i-do" target="_blank">Read documentation »</a>', |
|
195 | + $num_pastdue_actions, |
|
196 | + 'action-scheduler' |
|
197 | + ), |
|
198 | + $num_pastdue_actions, |
|
199 | + esc_attr( esc_url( $actions_url ) ) |
|
200 | + ); |
|
201 | + echo '</p></div>'; |
|
202 | + |
|
203 | + // Facilitate third-parties to evaluate and print notices. |
|
204 | + do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Provide more information about the screen and its data in the help tab. |
|
209 | + */ |
|
210 | + public function add_help_tabs() { |
|
211 | + $screen = get_current_screen(); |
|
212 | + |
|
213 | + if ( ! $screen || self::$screen_id != $screen->id ) { |
|
214 | + return; |
|
215 | + } |
|
216 | + |
|
217 | + $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
218 | + $screen->add_help_tab( |
|
219 | + array( |
|
220 | + 'id' => 'action_scheduler_about', |
|
221 | + 'title' => __( 'About', 'action-scheduler' ), |
|
222 | + 'content' => |
|
223 | + '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' . |
|
224 | + '<p>' . |
|
225 | + __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) . |
|
226 | + '</p>', |
|
227 | + ) |
|
228 | + ); |
|
229 | + |
|
230 | + $screen->add_help_tab( |
|
231 | + array( |
|
232 | + 'id' => 'action_scheduler_columns', |
|
233 | + 'title' => __( 'Columns', 'action-scheduler' ), |
|
234 | + 'content' => |
|
235 | + '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' . |
|
236 | + '<ul>' . |
|
237 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) . |
|
238 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) . |
|
239 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) . |
|
240 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) . |
|
241 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) . |
|
242 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) . |
|
243 | + sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) . |
|
244 | + '</ul>', |
|
245 | + ) |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public static function instance() { |
22 | 22 | |
23 | - if ( empty( self::$admin_view ) ) { |
|
24 | - $class = apply_filters( 'action_scheduler_admin_view_class', 'ActionScheduler_AdminView' ); |
|
23 | + if (empty(self::$admin_view)) { |
|
24 | + $class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView'); |
|
25 | 25 | self::$admin_view = new $class(); |
26 | 26 | } |
27 | 27 | |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | * @codeCoverageIgnore |
33 | 33 | */ |
34 | 34 | public function init() { |
35 | - if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) { |
|
35 | + if (is_admin() && ( ! defined('DOING_AJAX') || false == DOING_AJAX)) { |
|
36 | 36 | |
37 | - if ( class_exists( 'WooCommerce' ) ) { |
|
38 | - add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) ); |
|
39 | - add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) ); |
|
40 | - add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) ); |
|
37 | + if (class_exists('WooCommerce')) { |
|
38 | + add_action('woocommerce_admin_status_content_action-scheduler', array($this, 'render_admin_ui')); |
|
39 | + add_action('woocommerce_system_status_report', array($this, 'system_status_report')); |
|
40 | + add_filter('woocommerce_admin_status_tabs', array($this, 'register_system_status_tab')); |
|
41 | 41 | } |
42 | 42 | |
43 | - add_action( 'admin_menu', array( $this, 'register_menu' ) ); |
|
44 | - add_action( 'admin_notices', array( $this, 'maybe_check_pastdue_actions' ) ); |
|
45 | - add_action( 'current_screen', array( $this, 'add_help_tabs' ) ); |
|
43 | + add_action('admin_menu', array($this, 'register_menu')); |
|
44 | + add_action('admin_notices', array($this, 'maybe_check_pastdue_actions')); |
|
45 | + add_action('current_screen', array($this, 'add_help_tabs')); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | 49 | public function system_status_report() { |
50 | - $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() ); |
|
50 | + $table = new ActionScheduler_wcSystemStatus(ActionScheduler::store()); |
|
51 | 51 | $table->render(); |
52 | 52 | } |
53 | 53 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param array $tabs An associative array of tab key => label. |
58 | 58 | * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs |
59 | 59 | */ |
60 | - public function register_system_status_tab( array $tabs ) { |
|
61 | - $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' ); |
|
60 | + public function register_system_status_tab(array $tabs) { |
|
61 | + $tabs['action-scheduler'] = __('Scheduled Actions', 'action-scheduler'); |
|
62 | 62 | |
63 | 63 | return $tabs; |
64 | 64 | } |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | public function register_menu() { |
74 | 74 | $hook_suffix = add_submenu_page( |
75 | 75 | 'tools.php', |
76 | - __( 'Scheduled Actions', 'action-scheduler' ), |
|
77 | - __( 'Scheduled Actions', 'action-scheduler' ), |
|
76 | + __('Scheduled Actions', 'action-scheduler'), |
|
77 | + __('Scheduled Actions', 'action-scheduler'), |
|
78 | 78 | 'manage_options', |
79 | 79 | 'action-scheduler', |
80 | - array( $this, 'render_admin_ui' ) |
|
80 | + array($this, 'render_admin_ui') |
|
81 | 81 | ); |
82 | - add_action( 'load-' . $hook_suffix, array( $this, 'process_admin_ui' ) ); |
|
82 | + add_action('load-'.$hook_suffix, array($this, 'process_admin_ui')); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @return ActionScheduler_ListTable |
104 | 104 | */ |
105 | 105 | protected function get_list_table() { |
106 | - if ( null === $this->list_table ) { |
|
107 | - $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); |
|
106 | + if (null === $this->list_table) { |
|
107 | + $this->list_table = new ActionScheduler_ListTable(ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner()); |
|
108 | 108 | $this->list_table->process_actions(); |
109 | 109 | } |
110 | 110 | |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | public function maybe_check_pastdue_actions() { |
122 | 122 | |
123 | 123 | // Filter to prevent checking actions (ex: inappropriate user). |
124 | - if ( ! apply_filters( 'action_scheduler_check_pastdue_actions', current_user_can( 'manage_options' ) ) ) { |
|
124 | + if ( ! apply_filters('action_scheduler_check_pastdue_actions', current_user_can('manage_options'))) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | 128 | // Get last check transient. |
129 | - $last_check = get_transient( 'action_scheduler_last_pastdue_actions_check' ); |
|
129 | + $last_check = get_transient('action_scheduler_last_pastdue_actions_check'); |
|
130 | 130 | |
131 | 131 | // If transient exists, we're within interval, so bail. |
132 | - if ( ! empty( $last_check ) ) { |
|
132 | + if ( ! empty($last_check)) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
@@ -145,33 +145,33 @@ discard block |
||
145 | 145 | protected function check_pastdue_actions() { |
146 | 146 | |
147 | 147 | // Set thresholds. |
148 | - $threshold_seconds = (int) apply_filters( 'action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS ); |
|
149 | - $threshhold_min = (int) apply_filters( 'action_scheduler_pastdue_actions_min', 1 ); |
|
148 | + $threshold_seconds = (int) apply_filters('action_scheduler_pastdue_actions_seconds', DAY_IN_SECONDS); |
|
149 | + $threshhold_min = (int) apply_filters('action_scheduler_pastdue_actions_min', 1); |
|
150 | 150 | |
151 | 151 | // Allow third-parties to preempt the default check logic. |
152 | - $check = apply_filters( 'action_scheduler_pastdue_actions_check_pre', null ); |
|
152 | + $check = apply_filters('action_scheduler_pastdue_actions_check_pre', null); |
|
153 | 153 | |
154 | 154 | // Scheduled actions query arguments. |
155 | 155 | $query_args = array( |
156 | - 'date' => as_get_datetime_object( time() - $threshold_seconds ), |
|
156 | + 'date' => as_get_datetime_object(time() - $threshold_seconds), |
|
157 | 157 | 'status' => ActionScheduler_Store::STATUS_PENDING, |
158 | 158 | 'per_page' => $threshhold_min, |
159 | 159 | ); |
160 | 160 | |
161 | 161 | // If no third-party preempted, run default check. |
162 | - if ( $check === null ) { |
|
162 | + if ($check === null) { |
|
163 | 163 | $store = ActionScheduler_Store::instance(); |
164 | - $num_pastdue_actions = (int) $store->query_actions( $query_args, 'count' ); |
|
164 | + $num_pastdue_actions = (int) $store->query_actions($query_args, 'count'); |
|
165 | 165 | |
166 | 166 | // Check if past-due actions count is greater than or equal to threshold. |
167 | - $check = ( $num_pastdue_actions >= $threshhold_min ); |
|
168 | - $check = (bool) apply_filters( 'action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min ); |
|
167 | + $check = ($num_pastdue_actions >= $threshhold_min); |
|
168 | + $check = (bool) apply_filters('action_scheduler_pastdue_actions_check', $check, $num_pastdue_actions, $threshold_seconds, $threshhold_min); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // If check failed, set transient and abort. |
172 | - if ( ! boolval( $check ) ) { |
|
173 | - $interval = apply_filters( 'action_scheduler_pastdue_actions_check_interval', round( $threshold_seconds / 4 ), $threshold_seconds ); |
|
174 | - set_transient( 'action_scheduler_last_pastdue_actions_check', time(), $interval ); |
|
172 | + if ( ! boolval($check)) { |
|
173 | + $interval = apply_filters('action_scheduler_pastdue_actions_check_interval', round($threshold_seconds / 4), $threshold_seconds); |
|
174 | + set_transient('action_scheduler_last_pastdue_actions_check', time(), $interval); |
|
175 | 175 | |
176 | 176 | return; |
177 | 177 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | 'status' => 'past-due', |
183 | 183 | 'order' => 'asc', |
184 | 184 | ), |
185 | - admin_url( 'tools.php' ) |
|
185 | + admin_url('tools.php') |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | // Print notice. |
@@ -196,12 +196,12 @@ discard block |
||
196 | 196 | 'action-scheduler' |
197 | 197 | ), |
198 | 198 | $num_pastdue_actions, |
199 | - esc_attr( esc_url( $actions_url ) ) |
|
199 | + esc_attr(esc_url($actions_url)) |
|
200 | 200 | ); |
201 | 201 | echo '</p></div>'; |
202 | 202 | |
203 | 203 | // Facilitate third-parties to evaluate and print notices. |
204 | - do_action( 'action_scheduler_pastdue_actions_extra_notices', $query_args ); |
|
204 | + do_action('action_scheduler_pastdue_actions_extra_notices', $query_args); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | public function add_help_tabs() { |
211 | 211 | $screen = get_current_screen(); |
212 | 212 | |
213 | - if ( ! $screen || self::$screen_id != $screen->id ) { |
|
213 | + if ( ! $screen || self::$screen_id != $screen->id) { |
|
214 | 214 | return; |
215 | 215 | } |
216 | 216 | |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | $screen->add_help_tab( |
219 | 219 | array( |
220 | 220 | 'id' => 'action_scheduler_about', |
221 | - 'title' => __( 'About', 'action-scheduler' ), |
|
221 | + 'title' => __('About', 'action-scheduler'), |
|
222 | 222 | 'content' => |
223 | - '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' . |
|
224 | - '<p>' . |
|
225 | - __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) . |
|
223 | + '<h2>'.sprintf(__('About Action Scheduler %s', 'action-scheduler'), $as_version).'</h2>'. |
|
224 | + '<p>'. |
|
225 | + __('Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler'). |
|
226 | 226 | '</p>', |
227 | 227 | ) |
228 | 228 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | $screen->add_help_tab( |
231 | 231 | array( |
232 | 232 | 'id' => 'action_scheduler_columns', |
233 | - 'title' => __( 'Columns', 'action-scheduler' ), |
|
233 | + 'title' => __('Columns', 'action-scheduler'), |
|
234 | 234 | 'content' => |
235 | - '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' . |
|
236 | - '<ul>' . |
|
237 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) . |
|
238 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) . |
|
239 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) . |
|
240 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) . |
|
241 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) . |
|
242 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) . |
|
243 | - sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) . |
|
235 | + '<h2>'.__('Scheduled Action Columns', 'action-scheduler').'</h2>'. |
|
236 | + '<ul>'. |
|
237 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Hook', 'action-scheduler'), __('Name of the action hook that will be triggered.', 'action-scheduler')). |
|
238 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Status', 'action-scheduler'), __('Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler')). |
|
239 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Arguments', 'action-scheduler'), __('Optional data array passed to the action hook.', 'action-scheduler')). |
|
240 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Group', 'action-scheduler'), __('Optional action group.', 'action-scheduler')). |
|
241 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Recurrence', 'action-scheduler'), __('The action\'s schedule frequency.', 'action-scheduler')). |
|
242 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Scheduled', 'action-scheduler'), __('The date/time the action is/was scheduled to run.', 'action-scheduler')). |
|
243 | + sprintf('<li><strong>%1$s</strong>: %2$s</li>', __('Log', 'action-scheduler'), __('Activity log for the action.', 'action-scheduler')). |
|
244 | 244 | '</ul>', |
245 | 245 | ) |
246 | 246 | ); |
@@ -20,87 +20,87 @@ |
||
20 | 20 | */ |
21 | 21 | class CronExpression_DayOfMonthField extends CronExpression_AbstractField { |
22 | 22 | |
23 | - /** |
|
24 | - * Get the nearest day of the week for a given day in a month |
|
25 | - * |
|
26 | - * @param int $currentYear Current year |
|
27 | - * @param int $currentMonth Current month |
|
28 | - * @param int $targetDay Target day of the month |
|
29 | - * |
|
30 | - * @return DateTime Returns the nearest date |
|
31 | - */ |
|
32 | - private static function getNearestWeekday( $currentYear, $currentMonth, $targetDay ) { |
|
33 | - $tday = str_pad( $targetDay, 2, '0', STR_PAD_LEFT ); |
|
34 | - $target = new DateTime( "$currentYear-$currentMonth-$tday" ); |
|
35 | - $currentWeekday = (int) $target->format( 'N' ); |
|
23 | + /** |
|
24 | + * Get the nearest day of the week for a given day in a month |
|
25 | + * |
|
26 | + * @param int $currentYear Current year |
|
27 | + * @param int $currentMonth Current month |
|
28 | + * @param int $targetDay Target day of the month |
|
29 | + * |
|
30 | + * @return DateTime Returns the nearest date |
|
31 | + */ |
|
32 | + private static function getNearestWeekday( $currentYear, $currentMonth, $targetDay ) { |
|
33 | + $tday = str_pad( $targetDay, 2, '0', STR_PAD_LEFT ); |
|
34 | + $target = new DateTime( "$currentYear-$currentMonth-$tday" ); |
|
35 | + $currentWeekday = (int) $target->format( 'N' ); |
|
36 | 36 | |
37 | - if ( $currentWeekday < 6 ) { |
|
38 | - return $target; |
|
39 | - } |
|
37 | + if ( $currentWeekday < 6 ) { |
|
38 | + return $target; |
|
39 | + } |
|
40 | 40 | |
41 | - $lastDayOfMonth = $target->format( 't' ); |
|
41 | + $lastDayOfMonth = $target->format( 't' ); |
|
42 | 42 | |
43 | - foreach ( array( -1, 1, -2, 2 ) as $i ) { |
|
44 | - $adjusted = $targetDay + $i; |
|
45 | - if ( $adjusted > 0 && $adjusted <= $lastDayOfMonth ) { |
|
46 | - $target->setDate( $currentYear, $currentMonth, $adjusted ); |
|
47 | - if ( $target->format( 'N' ) < 6 && $target->format( 'm' ) == $currentMonth ) { |
|
48 | - return $target; |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
43 | + foreach ( array( -1, 1, -2, 2 ) as $i ) { |
|
44 | + $adjusted = $targetDay + $i; |
|
45 | + if ( $adjusted > 0 && $adjusted <= $lastDayOfMonth ) { |
|
46 | + $target->setDate( $currentYear, $currentMonth, $adjusted ); |
|
47 | + if ( $target->format( 'N' ) < 6 && $target->format( 'm' ) == $currentMonth ) { |
|
48 | + return $target; |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
58 | - // ? states that the field value is to be skipped |
|
59 | - if ( $value == '?' ) { |
|
60 | - return true; |
|
61 | - } |
|
54 | + /** |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
58 | + // ? states that the field value is to be skipped |
|
59 | + if ( $value == '?' ) { |
|
60 | + return true; |
|
61 | + } |
|
62 | 62 | |
63 | - $fieldValue = $date->format( 'd' ); |
|
63 | + $fieldValue = $date->format( 'd' ); |
|
64 | 64 | |
65 | - // Check to see if this is the last day of the month |
|
66 | - if ( $value == 'L' ) { |
|
67 | - return $fieldValue == $date->format( 't' ); |
|
68 | - } |
|
65 | + // Check to see if this is the last day of the month |
|
66 | + if ( $value == 'L' ) { |
|
67 | + return $fieldValue == $date->format( 't' ); |
|
68 | + } |
|
69 | 69 | |
70 | - // Check to see if this is the nearest weekday to a particular value |
|
71 | - if ( strpos( $value, 'W' ) ) { |
|
72 | - // Parse the target day |
|
73 | - $targetDay = substr( $value, 0, strpos( $value, 'W' ) ); |
|
74 | - // Find out if the current day is the nearest day of the week |
|
75 | - return $date->format( 'j' ) == self::getNearestWeekday( |
|
76 | - $date->format( 'Y' ), |
|
77 | - $date->format( 'm' ), |
|
78 | - $targetDay |
|
79 | - )->format( 'j' ); |
|
80 | - } |
|
70 | + // Check to see if this is the nearest weekday to a particular value |
|
71 | + if ( strpos( $value, 'W' ) ) { |
|
72 | + // Parse the target day |
|
73 | + $targetDay = substr( $value, 0, strpos( $value, 'W' ) ); |
|
74 | + // Find out if the current day is the nearest day of the week |
|
75 | + return $date->format( 'j' ) == self::getNearestWeekday( |
|
76 | + $date->format( 'Y' ), |
|
77 | + $date->format( 'm' ), |
|
78 | + $targetDay |
|
79 | + )->format( 'j' ); |
|
80 | + } |
|
81 | 81 | |
82 | - return $this->isSatisfied( $date->format( 'd' ), $value ); |
|
83 | - } |
|
82 | + return $this->isSatisfied( $date->format( 'd' ), $value ); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * {@inheritdoc} |
|
87 | - */ |
|
88 | - public function increment( DateTime $date, $invert = false ) { |
|
89 | - if ( $invert ) { |
|
90 | - $date->modify( 'previous day' ); |
|
91 | - $date->setTime( 23, 59 ); |
|
92 | - } else { |
|
93 | - $date->modify( 'next day' ); |
|
94 | - $date->setTime( 0, 0 ); |
|
95 | - } |
|
85 | + /** |
|
86 | + * {@inheritdoc} |
|
87 | + */ |
|
88 | + public function increment( DateTime $date, $invert = false ) { |
|
89 | + if ( $invert ) { |
|
90 | + $date->modify( 'previous day' ); |
|
91 | + $date->setTime( 23, 59 ); |
|
92 | + } else { |
|
93 | + $date->modify( 'next day' ); |
|
94 | + $date->setTime( 0, 0 ); |
|
95 | + } |
|
96 | 96 | |
97 | - return $this; |
|
98 | - } |
|
97 | + return $this; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * {@inheritdoc} |
|
102 | - */ |
|
103 | - public function validate( $value ) { |
|
104 | - return (bool) preg_match( '/[\*,\/\-\?LW0-9A-Za-z]+/', $value ); |
|
105 | - } |
|
100 | + /** |
|
101 | + * {@inheritdoc} |
|
102 | + */ |
|
103 | + public function validate( $value ) { |
|
104 | + return (bool) preg_match( '/[\*,\/\-\?LW0-9A-Za-z]+/', $value ); |
|
105 | + } |
|
106 | 106 | } |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return DateTime Returns the nearest date |
31 | 31 | */ |
32 | - private static function getNearestWeekday( $currentYear, $currentMonth, $targetDay ) { |
|
33 | - $tday = str_pad( $targetDay, 2, '0', STR_PAD_LEFT ); |
|
34 | - $target = new DateTime( "$currentYear-$currentMonth-$tday" ); |
|
35 | - $currentWeekday = (int) $target->format( 'N' ); |
|
32 | + private static function getNearestWeekday($currentYear, $currentMonth, $targetDay) { |
|
33 | + $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT); |
|
34 | + $target = new DateTime("$currentYear-$currentMonth-$tday"); |
|
35 | + $currentWeekday = (int) $target->format('N'); |
|
36 | 36 | |
37 | - if ( $currentWeekday < 6 ) { |
|
37 | + if ($currentWeekday < 6) { |
|
38 | 38 | return $target; |
39 | 39 | } |
40 | 40 | |
41 | - $lastDayOfMonth = $target->format( 't' ); |
|
41 | + $lastDayOfMonth = $target->format('t'); |
|
42 | 42 | |
43 | - foreach ( array( -1, 1, -2, 2 ) as $i ) { |
|
43 | + foreach (array( -1, 1, -2, 2 ) as $i) { |
|
44 | 44 | $adjusted = $targetDay + $i; |
45 | - if ( $adjusted > 0 && $adjusted <= $lastDayOfMonth ) { |
|
46 | - $target->setDate( $currentYear, $currentMonth, $adjusted ); |
|
47 | - if ( $target->format( 'N' ) < 6 && $target->format( 'm' ) == $currentMonth ) { |
|
45 | + if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) { |
|
46 | + $target->setDate($currentYear, $currentMonth, $adjusted); |
|
47 | + if ($target->format('N') < 6 && $target->format('m') == $currentMonth) { |
|
48 | 48 | return $target; |
49 | 49 | } |
50 | 50 | } |
@@ -54,44 +54,44 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * {@inheritdoc} |
56 | 56 | */ |
57 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
57 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
58 | 58 | // ? states that the field value is to be skipped |
59 | - if ( $value == '?' ) { |
|
59 | + if ($value == '?') { |
|
60 | 60 | return true; |
61 | 61 | } |
62 | 62 | |
63 | - $fieldValue = $date->format( 'd' ); |
|
63 | + $fieldValue = $date->format('d'); |
|
64 | 64 | |
65 | 65 | // Check to see if this is the last day of the month |
66 | - if ( $value == 'L' ) { |
|
67 | - return $fieldValue == $date->format( 't' ); |
|
66 | + if ($value == 'L') { |
|
67 | + return $fieldValue == $date->format('t'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Check to see if this is the nearest weekday to a particular value |
71 | - if ( strpos( $value, 'W' ) ) { |
|
71 | + if (strpos($value, 'W')) { |
|
72 | 72 | // Parse the target day |
73 | - $targetDay = substr( $value, 0, strpos( $value, 'W' ) ); |
|
73 | + $targetDay = substr($value, 0, strpos($value, 'W')); |
|
74 | 74 | // Find out if the current day is the nearest day of the week |
75 | - return $date->format( 'j' ) == self::getNearestWeekday( |
|
76 | - $date->format( 'Y' ), |
|
77 | - $date->format( 'm' ), |
|
75 | + return $date->format('j') == self::getNearestWeekday( |
|
76 | + $date->format('Y'), |
|
77 | + $date->format('m'), |
|
78 | 78 | $targetDay |
79 | - )->format( 'j' ); |
|
79 | + )->format('j'); |
|
80 | 80 | } |
81 | 81 | |
82 | - return $this->isSatisfied( $date->format( 'd' ), $value ); |
|
82 | + return $this->isSatisfied($date->format('d'), $value); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * {@inheritdoc} |
87 | 87 | */ |
88 | - public function increment( DateTime $date, $invert = false ) { |
|
89 | - if ( $invert ) { |
|
90 | - $date->modify( 'previous day' ); |
|
91 | - $date->setTime( 23, 59 ); |
|
88 | + public function increment(DateTime $date, $invert = false) { |
|
89 | + if ($invert) { |
|
90 | + $date->modify('previous day'); |
|
91 | + $date->setTime(23, 59); |
|
92 | 92 | } else { |
93 | - $date->modify( 'next day' ); |
|
94 | - $date->setTime( 0, 0 ); |
|
93 | + $date->modify('next day'); |
|
94 | + $date->setTime(0, 0); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return $this; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * {@inheritdoc} |
102 | 102 | */ |
103 | - public function validate( $value ) { |
|
104 | - return (bool) preg_match( '/[\*,\/\-\?LW0-9A-Za-z]+/', $value ); |
|
103 | + public function validate($value) { |
|
104 | + return (bool) preg_match('/[\*,\/\-\?LW0-9A-Za-z]+/', $value); |
|
105 | 105 | } |
106 | 106 | } |
@@ -7,34 +7,34 @@ |
||
7 | 7 | */ |
8 | 8 | class CronExpression_YearField extends CronExpression_AbstractField { |
9 | 9 | |
10 | - /** |
|
11 | - * {@inheritdoc} |
|
12 | - */ |
|
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'Y' ), $value ); |
|
15 | - } |
|
10 | + /** |
|
11 | + * {@inheritdoc} |
|
12 | + */ |
|
13 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | + return $this->isSatisfied( $date->format( 'Y' ), $value ); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public function increment( DateTime $date, $invert = false ) { |
|
21 | - if ( $invert ) { |
|
22 | - $date->modify( '-1 year' ); |
|
23 | - $date->setDate( $date->format( 'Y' ), 12, 31 ); |
|
24 | - $date->setTime( 23, 59, 0 ); |
|
25 | - } else { |
|
26 | - $date->modify( '+1 year' ); |
|
27 | - $date->setDate( $date->format( 'Y' ), 1, 1 ); |
|
28 | - $date->setTime( 0, 0, 0 ); |
|
29 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public function increment( DateTime $date, $invert = false ) { |
|
21 | + if ( $invert ) { |
|
22 | + $date->modify( '-1 year' ); |
|
23 | + $date->setDate( $date->format( 'Y' ), 12, 31 ); |
|
24 | + $date->setTime( 23, 59, 0 ); |
|
25 | + } else { |
|
26 | + $date->modify( '+1 year' ); |
|
27 | + $date->setDate( $date->format( 'Y' ), 1, 1 ); |
|
28 | + $date->setTime( 0, 0, 0 ); |
|
29 | + } |
|
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - public function validate( $value ) { |
|
38 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
39 | - } |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + public function validate( $value ) { |
|
38 | + return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
39 | + } |
|
40 | 40 | } |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * {@inheritdoc} |
12 | 12 | */ |
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'Y' ), $value ); |
|
13 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
14 | + return $this->isSatisfied($date->format('Y'), $value); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |
19 | 19 | */ |
20 | - public function increment( DateTime $date, $invert = false ) { |
|
21 | - if ( $invert ) { |
|
22 | - $date->modify( '-1 year' ); |
|
23 | - $date->setDate( $date->format( 'Y' ), 12, 31 ); |
|
24 | - $date->setTime( 23, 59, 0 ); |
|
20 | + public function increment(DateTime $date, $invert = false) { |
|
21 | + if ($invert) { |
|
22 | + $date->modify('-1 year'); |
|
23 | + $date->setDate($date->format('Y'), 12, 31); |
|
24 | + $date->setTime(23, 59, 0); |
|
25 | 25 | } else { |
26 | - $date->modify( '+1 year' ); |
|
27 | - $date->setDate( $date->format( 'Y' ), 1, 1 ); |
|
28 | - $date->setTime( 0, 0, 0 ); |
|
26 | + $date->modify('+1 year'); |
|
27 | + $date->setDate($date->format('Y'), 1, 1); |
|
28 | + $date->setTime(0, 0, 0); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | return $this; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | - public function validate( $value ) { |
|
38 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
37 | + public function validate($value) { |
|
38 | + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); |
|
39 | 39 | } |
40 | 40 | } |
@@ -7,38 +7,38 @@ |
||
7 | 7 | */ |
8 | 8 | class CronExpression_HoursField extends CronExpression_AbstractField { |
9 | 9 | |
10 | - /** |
|
11 | - * {@inheritdoc} |
|
12 | - */ |
|
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'H' ), $value ); |
|
15 | - } |
|
10 | + /** |
|
11 | + * {@inheritdoc} |
|
12 | + */ |
|
13 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | + return $this->isSatisfied( $date->format( 'H' ), $value ); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public function increment( DateTime $date, $invert = false ) { |
|
21 | - // Change timezone to UTC temporarily. This will |
|
22 | - // allow us to go back or forwards and hour even |
|
23 | - // if DST will be changed between the hours. |
|
24 | - $timezone = $date->getTimezone(); |
|
25 | - $date->setTimezone( new DateTimeZone( 'UTC' ) ); |
|
26 | - if ( $invert ) { |
|
27 | - $date->modify( '-1 hour' ); |
|
28 | - $date->setTime( $date->format( 'H' ), 59 ); |
|
29 | - } else { |
|
30 | - $date->modify( '+1 hour' ); |
|
31 | - $date->setTime( $date->format( 'H' ), 0 ); |
|
32 | - } |
|
33 | - $date->setTimezone( $timezone ); |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public function increment( DateTime $date, $invert = false ) { |
|
21 | + // Change timezone to UTC temporarily. This will |
|
22 | + // allow us to go back or forwards and hour even |
|
23 | + // if DST will be changed between the hours. |
|
24 | + $timezone = $date->getTimezone(); |
|
25 | + $date->setTimezone( new DateTimeZone( 'UTC' ) ); |
|
26 | + if ( $invert ) { |
|
27 | + $date->modify( '-1 hour' ); |
|
28 | + $date->setTime( $date->format( 'H' ), 59 ); |
|
29 | + } else { |
|
30 | + $date->modify( '+1 hour' ); |
|
31 | + $date->setTime( $date->format( 'H' ), 0 ); |
|
32 | + } |
|
33 | + $date->setTimezone( $timezone ); |
|
34 | 34 | |
35 | - return $this; |
|
36 | - } |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritdoc} |
|
40 | - */ |
|
41 | - public function validate( $value ) { |
|
42 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
43 | - } |
|
38 | + /** |
|
39 | + * {@inheritdoc} |
|
40 | + */ |
|
41 | + public function validate( $value ) { |
|
42 | + return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
43 | + } |
|
44 | 44 | } |
@@ -10,27 +10,27 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * {@inheritdoc} |
12 | 12 | */ |
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'H' ), $value ); |
|
13 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
14 | + return $this->isSatisfied($date->format('H'), $value); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |
19 | 19 | */ |
20 | - public function increment( DateTime $date, $invert = false ) { |
|
20 | + public function increment(DateTime $date, $invert = false) { |
|
21 | 21 | // Change timezone to UTC temporarily. This will |
22 | 22 | // allow us to go back or forwards and hour even |
23 | 23 | // if DST will be changed between the hours. |
24 | 24 | $timezone = $date->getTimezone(); |
25 | - $date->setTimezone( new DateTimeZone( 'UTC' ) ); |
|
26 | - if ( $invert ) { |
|
27 | - $date->modify( '-1 hour' ); |
|
28 | - $date->setTime( $date->format( 'H' ), 59 ); |
|
25 | + $date->setTimezone(new DateTimeZone('UTC')); |
|
26 | + if ($invert) { |
|
27 | + $date->modify('-1 hour'); |
|
28 | + $date->setTime($date->format('H'), 59); |
|
29 | 29 | } else { |
30 | - $date->modify( '+1 hour' ); |
|
31 | - $date->setTime( $date->format( 'H' ), 0 ); |
|
30 | + $date->modify('+1 hour'); |
|
31 | + $date->setTime($date->format('H'), 0); |
|
32 | 32 | } |
33 | - $date->setTimezone( $timezone ); |
|
33 | + $date->setTimezone($timezone); |
|
34 | 34 | |
35 | 35 | return $this; |
36 | 36 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * {@inheritdoc} |
40 | 40 | */ |
41 | - public function validate( $value ) { |
|
42 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
41 | + public function validate($value) { |
|
42 | + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); |
|
43 | 43 | } |
44 | 44 | } |
@@ -17,105 +17,105 @@ |
||
17 | 17 | */ |
18 | 18 | class CronExpression_DayOfWeekField extends CronExpression_AbstractField { |
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
24 | - if ( $value == '?' ) { |
|
25 | - return true; |
|
26 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
24 | + if ( $value == '?' ) { |
|
25 | + return true; |
|
26 | + } |
|
27 | 27 | |
28 | - // Convert text day of the week values to integers |
|
29 | - $value = str_ireplace( |
|
30 | - array( 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' ), |
|
31 | - range( 0, 6 ), |
|
32 | - $value |
|
33 | - ); |
|
28 | + // Convert text day of the week values to integers |
|
29 | + $value = str_ireplace( |
|
30 | + array( 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' ), |
|
31 | + range( 0, 6 ), |
|
32 | + $value |
|
33 | + ); |
|
34 | 34 | |
35 | - $currentYear = $date->format( 'Y' ); |
|
36 | - $currentMonth = $date->format( 'm' ); |
|
37 | - $lastDayOfMonth = $date->format( 't' ); |
|
35 | + $currentYear = $date->format( 'Y' ); |
|
36 | + $currentMonth = $date->format( 'm' ); |
|
37 | + $lastDayOfMonth = $date->format( 't' ); |
|
38 | 38 | |
39 | - // Find out if this is the last specific weekday of the month |
|
40 | - if ( strpos( $value, 'L' ) ) { |
|
41 | - $weekday = str_replace( '7', '0', substr( $value, 0, strpos( $value, 'L' ) ) ); |
|
42 | - $tdate = clone $date; |
|
43 | - $tdate->setDate( $currentYear, $currentMonth, $lastDayOfMonth ); |
|
44 | - while ( $tdate->format( 'w' ) != $weekday ) { |
|
45 | - $tdate->setDate( $currentYear, $currentMonth, --$lastDayOfMonth ); |
|
46 | - } |
|
39 | + // Find out if this is the last specific weekday of the month |
|
40 | + if ( strpos( $value, 'L' ) ) { |
|
41 | + $weekday = str_replace( '7', '0', substr( $value, 0, strpos( $value, 'L' ) ) ); |
|
42 | + $tdate = clone $date; |
|
43 | + $tdate->setDate( $currentYear, $currentMonth, $lastDayOfMonth ); |
|
44 | + while ( $tdate->format( 'w' ) != $weekday ) { |
|
45 | + $tdate->setDate( $currentYear, $currentMonth, --$lastDayOfMonth ); |
|
46 | + } |
|
47 | 47 | |
48 | - return $date->format( 'j' ) == $lastDayOfMonth; |
|
49 | - } |
|
48 | + return $date->format( 'j' ) == $lastDayOfMonth; |
|
49 | + } |
|
50 | 50 | |
51 | - // Handle # hash tokens |
|
52 | - if ( strpos( $value, '#' ) ) { |
|
53 | - list($weekday, $nth) = explode( '#', $value ); |
|
54 | - // Validate the hash fields |
|
55 | - if ( $weekday < 1 || $weekday > 5 ) { |
|
56 | - throw new InvalidArgumentException( "Weekday must be a value between 1 and 5. {$weekday} given" ); |
|
57 | - } |
|
58 | - if ( $nth > 5 ) { |
|
59 | - throw new InvalidArgumentException( 'There are never more than 5 of a given weekday in a month' ); |
|
60 | - } |
|
61 | - // The current weekday must match the targeted weekday to proceed |
|
62 | - if ( $date->format( 'N' ) != $weekday ) { |
|
63 | - return false; |
|
64 | - } |
|
51 | + // Handle # hash tokens |
|
52 | + if ( strpos( $value, '#' ) ) { |
|
53 | + list($weekday, $nth) = explode( '#', $value ); |
|
54 | + // Validate the hash fields |
|
55 | + if ( $weekday < 1 || $weekday > 5 ) { |
|
56 | + throw new InvalidArgumentException( "Weekday must be a value between 1 and 5. {$weekday} given" ); |
|
57 | + } |
|
58 | + if ( $nth > 5 ) { |
|
59 | + throw new InvalidArgumentException( 'There are never more than 5 of a given weekday in a month' ); |
|
60 | + } |
|
61 | + // The current weekday must match the targeted weekday to proceed |
|
62 | + if ( $date->format( 'N' ) != $weekday ) { |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | |
66 | - $tdate = clone $date; |
|
67 | - $tdate->setDate( $currentYear, $currentMonth, 1 ); |
|
68 | - $dayCount = 0; |
|
69 | - $currentDay = 1; |
|
70 | - while ( $currentDay < $lastDayOfMonth + 1 ) { |
|
71 | - if ( $tdate->format( 'N' ) == $weekday ) { |
|
72 | - if ( ++$dayCount >= $nth ) { |
|
73 | - break; |
|
74 | - } |
|
75 | - } |
|
76 | - $tdate->setDate( $currentYear, $currentMonth, ++$currentDay ); |
|
77 | - } |
|
66 | + $tdate = clone $date; |
|
67 | + $tdate->setDate( $currentYear, $currentMonth, 1 ); |
|
68 | + $dayCount = 0; |
|
69 | + $currentDay = 1; |
|
70 | + while ( $currentDay < $lastDayOfMonth + 1 ) { |
|
71 | + if ( $tdate->format( 'N' ) == $weekday ) { |
|
72 | + if ( ++$dayCount >= $nth ) { |
|
73 | + break; |
|
74 | + } |
|
75 | + } |
|
76 | + $tdate->setDate( $currentYear, $currentMonth, ++$currentDay ); |
|
77 | + } |
|
78 | 78 | |
79 | - return $date->format( 'j' ) == $currentDay; |
|
80 | - } |
|
79 | + return $date->format( 'j' ) == $currentDay; |
|
80 | + } |
|
81 | 81 | |
82 | - // Handle day of the week values |
|
83 | - if ( strpos( $value, '-' ) ) { |
|
84 | - $parts = explode( '-', $value ); |
|
85 | - if ( $parts[0] == '7' ) { |
|
86 | - $parts[0] = '0'; |
|
87 | - } elseif ( $parts[1] == '0' ) { |
|
88 | - $parts[1] = '7'; |
|
89 | - } |
|
90 | - $value = implode( '-', $parts ); |
|
91 | - } |
|
82 | + // Handle day of the week values |
|
83 | + if ( strpos( $value, '-' ) ) { |
|
84 | + $parts = explode( '-', $value ); |
|
85 | + if ( $parts[0] == '7' ) { |
|
86 | + $parts[0] = '0'; |
|
87 | + } elseif ( $parts[1] == '0' ) { |
|
88 | + $parts[1] = '7'; |
|
89 | + } |
|
90 | + $value = implode( '-', $parts ); |
|
91 | + } |
|
92 | 92 | |
93 | - // Test to see which Sunday to use -- 0 == 7 == Sunday |
|
94 | - $format = in_array( 7, str_split( $value ) ) ? 'N' : 'w'; |
|
95 | - $fieldValue = $date->format( $format ); |
|
93 | + // Test to see which Sunday to use -- 0 == 7 == Sunday |
|
94 | + $format = in_array( 7, str_split( $value ) ) ? 'N' : 'w'; |
|
95 | + $fieldValue = $date->format( $format ); |
|
96 | 96 | |
97 | - return $this->isSatisfied( $fieldValue, $value ); |
|
98 | - } |
|
97 | + return $this->isSatisfied( $fieldValue, $value ); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * {@inheritdoc} |
|
102 | - */ |
|
103 | - public function increment( DateTime $date, $invert = false ) { |
|
104 | - if ( $invert ) { |
|
105 | - $date->modify( '-1 day' ); |
|
106 | - $date->setTime( 23, 59, 0 ); |
|
107 | - } else { |
|
108 | - $date->modify( '+1 day' ); |
|
109 | - $date->setTime( 0, 0, 0 ); |
|
110 | - } |
|
100 | + /** |
|
101 | + * {@inheritdoc} |
|
102 | + */ |
|
103 | + public function increment( DateTime $date, $invert = false ) { |
|
104 | + if ( $invert ) { |
|
105 | + $date->modify( '-1 day' ); |
|
106 | + $date->setTime( 23, 59, 0 ); |
|
107 | + } else { |
|
108 | + $date->modify( '+1 day' ); |
|
109 | + $date->setTime( 0, 0, 0 ); |
|
110 | + } |
|
111 | 111 | |
112 | - return $this; |
|
113 | - } |
|
112 | + return $this; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * {@inheritdoc} |
|
117 | - */ |
|
118 | - public function validate( $value ) { |
|
119 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
120 | - } |
|
115 | + /** |
|
116 | + * {@inheritdoc} |
|
117 | + */ |
|
118 | + public function validate( $value ) { |
|
119 | + return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
120 | + } |
|
121 | 121 | } |
@@ -20,93 +20,93 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * {@inheritdoc} |
22 | 22 | */ |
23 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
24 | - if ( $value == '?' ) { |
|
23 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
24 | + if ($value == '?') { |
|
25 | 25 | return true; |
26 | 26 | } |
27 | 27 | |
28 | 28 | // Convert text day of the week values to integers |
29 | 29 | $value = str_ireplace( |
30 | - array( 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' ), |
|
31 | - range( 0, 6 ), |
|
30 | + array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'), |
|
31 | + range(0, 6), |
|
32 | 32 | $value |
33 | 33 | ); |
34 | 34 | |
35 | - $currentYear = $date->format( 'Y' ); |
|
36 | - $currentMonth = $date->format( 'm' ); |
|
37 | - $lastDayOfMonth = $date->format( 't' ); |
|
35 | + $currentYear = $date->format('Y'); |
|
36 | + $currentMonth = $date->format('m'); |
|
37 | + $lastDayOfMonth = $date->format('t'); |
|
38 | 38 | |
39 | 39 | // Find out if this is the last specific weekday of the month |
40 | - if ( strpos( $value, 'L' ) ) { |
|
41 | - $weekday = str_replace( '7', '0', substr( $value, 0, strpos( $value, 'L' ) ) ); |
|
40 | + if (strpos($value, 'L')) { |
|
41 | + $weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L'))); |
|
42 | 42 | $tdate = clone $date; |
43 | - $tdate->setDate( $currentYear, $currentMonth, $lastDayOfMonth ); |
|
44 | - while ( $tdate->format( 'w' ) != $weekday ) { |
|
45 | - $tdate->setDate( $currentYear, $currentMonth, --$lastDayOfMonth ); |
|
43 | + $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth); |
|
44 | + while ($tdate->format('w') != $weekday) { |
|
45 | + $tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth); |
|
46 | 46 | } |
47 | 47 | |
48 | - return $date->format( 'j' ) == $lastDayOfMonth; |
|
48 | + return $date->format('j') == $lastDayOfMonth; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // Handle # hash tokens |
52 | - if ( strpos( $value, '#' ) ) { |
|
53 | - list($weekday, $nth) = explode( '#', $value ); |
|
52 | + if (strpos($value, '#')) { |
|
53 | + list($weekday, $nth) = explode('#', $value); |
|
54 | 54 | // Validate the hash fields |
55 | - if ( $weekday < 1 || $weekday > 5 ) { |
|
56 | - throw new InvalidArgumentException( "Weekday must be a value between 1 and 5. {$weekday} given" ); |
|
55 | + if ($weekday < 1 || $weekday > 5) { |
|
56 | + throw new InvalidArgumentException("Weekday must be a value between 1 and 5. {$weekday} given"); |
|
57 | 57 | } |
58 | - if ( $nth > 5 ) { |
|
59 | - throw new InvalidArgumentException( 'There are never more than 5 of a given weekday in a month' ); |
|
58 | + if ($nth > 5) { |
|
59 | + throw new InvalidArgumentException('There are never more than 5 of a given weekday in a month'); |
|
60 | 60 | } |
61 | 61 | // The current weekday must match the targeted weekday to proceed |
62 | - if ( $date->format( 'N' ) != $weekday ) { |
|
62 | + if ($date->format('N') != $weekday) { |
|
63 | 63 | return false; |
64 | 64 | } |
65 | 65 | |
66 | 66 | $tdate = clone $date; |
67 | - $tdate->setDate( $currentYear, $currentMonth, 1 ); |
|
67 | + $tdate->setDate($currentYear, $currentMonth, 1); |
|
68 | 68 | $dayCount = 0; |
69 | 69 | $currentDay = 1; |
70 | - while ( $currentDay < $lastDayOfMonth + 1 ) { |
|
71 | - if ( $tdate->format( 'N' ) == $weekday ) { |
|
70 | + while ($currentDay < $lastDayOfMonth + 1) { |
|
71 | + if ($tdate->format('N') == $weekday) { |
|
72 | 72 | if ( ++$dayCount >= $nth ) { |
73 | 73 | break; |
74 | 74 | } |
75 | 75 | } |
76 | - $tdate->setDate( $currentYear, $currentMonth, ++$currentDay ); |
|
76 | + $tdate->setDate($currentYear, $currentMonth, ++$currentDay); |
|
77 | 77 | } |
78 | 78 | |
79 | - return $date->format( 'j' ) == $currentDay; |
|
79 | + return $date->format('j') == $currentDay; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | // Handle day of the week values |
83 | - if ( strpos( $value, '-' ) ) { |
|
84 | - $parts = explode( '-', $value ); |
|
85 | - if ( $parts[0] == '7' ) { |
|
83 | + if (strpos($value, '-')) { |
|
84 | + $parts = explode('-', $value); |
|
85 | + if ($parts[0] == '7') { |
|
86 | 86 | $parts[0] = '0'; |
87 | - } elseif ( $parts[1] == '0' ) { |
|
87 | + } elseif ($parts[1] == '0') { |
|
88 | 88 | $parts[1] = '7'; |
89 | 89 | } |
90 | - $value = implode( '-', $parts ); |
|
90 | + $value = implode('-', $parts); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Test to see which Sunday to use -- 0 == 7 == Sunday |
94 | - $format = in_array( 7, str_split( $value ) ) ? 'N' : 'w'; |
|
95 | - $fieldValue = $date->format( $format ); |
|
94 | + $format = in_array(7, str_split($value)) ? 'N' : 'w'; |
|
95 | + $fieldValue = $date->format($format); |
|
96 | 96 | |
97 | - return $this->isSatisfied( $fieldValue, $value ); |
|
97 | + return $this->isSatisfied($fieldValue, $value); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * {@inheritdoc} |
102 | 102 | */ |
103 | - public function increment( DateTime $date, $invert = false ) { |
|
104 | - if ( $invert ) { |
|
105 | - $date->modify( '-1 day' ); |
|
106 | - $date->setTime( 23, 59, 0 ); |
|
103 | + public function increment(DateTime $date, $invert = false) { |
|
104 | + if ($invert) { |
|
105 | + $date->modify('-1 day'); |
|
106 | + $date->setTime(23, 59, 0); |
|
107 | 107 | } else { |
108 | - $date->modify( '+1 day' ); |
|
109 | - $date->setTime( 0, 0, 0 ); |
|
108 | + $date->modify('+1 day'); |
|
109 | + $date->setTime(0, 0, 0); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return $this; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | /** |
116 | 116 | * {@inheritdoc} |
117 | 117 | */ |
118 | - public function validate( $value ) { |
|
119 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
118 | + public function validate($value) { |
|
119 | + return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value); |
|
120 | 120 | } |
121 | 121 | } |
@@ -7,30 +7,30 @@ |
||
7 | 7 | */ |
8 | 8 | class CronExpression_MinutesField extends CronExpression_AbstractField { |
9 | 9 | |
10 | - /** |
|
11 | - * {@inheritdoc} |
|
12 | - */ |
|
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'i' ), $value ); |
|
15 | - } |
|
10 | + /** |
|
11 | + * {@inheritdoc} |
|
12 | + */ |
|
13 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | + return $this->isSatisfied( $date->format( 'i' ), $value ); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public function increment( DateTime $date, $invert = false ) { |
|
21 | - if ( $invert ) { |
|
22 | - $date->modify( '-1 minute' ); |
|
23 | - } else { |
|
24 | - $date->modify( '+1 minute' ); |
|
25 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public function increment( DateTime $date, $invert = false ) { |
|
21 | + if ( $invert ) { |
|
22 | + $date->modify( '-1 minute' ); |
|
23 | + } else { |
|
24 | + $date->modify( '+1 minute' ); |
|
25 | + } |
|
26 | 26 | |
27 | - return $this; |
|
28 | - } |
|
27 | + return $this; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function validate( $value ) { |
|
34 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
35 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function validate( $value ) { |
|
34 | + return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
35 | + } |
|
36 | 36 | } |
@@ -10,18 +10,18 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * {@inheritdoc} |
12 | 12 | */ |
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - return $this->isSatisfied( $date->format( 'i' ), $value ); |
|
13 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
14 | + return $this->isSatisfied($date->format('i'), $value); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |
19 | 19 | */ |
20 | - public function increment( DateTime $date, $invert = false ) { |
|
21 | - if ( $invert ) { |
|
22 | - $date->modify( '-1 minute' ); |
|
20 | + public function increment(DateTime $date, $invert = false) { |
|
21 | + if ($invert) { |
|
22 | + $date->modify('-1 minute'); |
|
23 | 23 | } else { |
24 | - $date->modify( '+1 minute' ); |
|
24 | + $date->modify('+1 minute'); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | return $this; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function validate( $value ) { |
|
34 | - return (bool) preg_match( '/[\*,\/\-0-9]+/', $value ); |
|
33 | + public function validate($value) { |
|
34 | + return (bool) preg_match('/[\*,\/\-0-9]+/', $value); |
|
35 | 35 | } |
36 | 36 | } |