@@ -5,25 +5,25 @@ |
||
5 | 5 | */ |
6 | 6 | abstract class ActionScheduler_Schedule_Deprecated implements ActionScheduler_Schedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Get the date & time this schedule was created to run, or calculate when it should be run |
|
10 | - * after a given date & time. |
|
11 | - * |
|
12 | - * @param DateTime $after DateTime to calculate against. |
|
13 | - * |
|
14 | - * @return DateTime|null |
|
15 | - */ |
|
16 | - public function next( DateTime $after = null ) { |
|
17 | - if ( empty( $after ) ) { |
|
18 | - $return_value = $this->get_date(); |
|
19 | - $replacement_method = 'get_date()'; |
|
20 | - } else { |
|
21 | - $return_value = $this->get_next( $after ); |
|
22 | - $replacement_method = 'get_next( $after )'; |
|
23 | - } |
|
8 | + /** |
|
9 | + * Get the date & time this schedule was created to run, or calculate when it should be run |
|
10 | + * after a given date & time. |
|
11 | + * |
|
12 | + * @param DateTime $after DateTime to calculate against. |
|
13 | + * |
|
14 | + * @return DateTime|null |
|
15 | + */ |
|
16 | + public function next( DateTime $after = null ) { |
|
17 | + if ( empty( $after ) ) { |
|
18 | + $return_value = $this->get_date(); |
|
19 | + $replacement_method = 'get_date()'; |
|
20 | + } else { |
|
21 | + $return_value = $this->get_next( $after ); |
|
22 | + $replacement_method = 'get_next( $after )'; |
|
23 | + } |
|
24 | 24 | |
25 | - _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
25 | + _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
26 | 26 | |
27 | - return $return_value; |
|
28 | - } |
|
27 | + return $return_value; |
|
28 | + } |
|
29 | 29 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | * |
14 | 14 | * @return DateTime|null |
15 | 15 | */ |
16 | - public function next( DateTime $after = null ) { |
|
17 | - if ( empty( $after ) ) { |
|
16 | + public function next(DateTime $after = null) { |
|
17 | + if (empty($after)) { |
|
18 | 18 | $return_value = $this->get_date(); |
19 | 19 | $replacement_method = 'get_date()'; |
20 | 20 | } else { |
21 | - $return_value = $this->get_next( $after ); |
|
21 | + $return_value = $this->get_next($after); |
|
22 | 22 | $replacement_method = 'get_next( $after )'; |
23 | 23 | } |
24 | 24 | |
25 | - _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
25 | + _deprecated_function(__METHOD__, '3.0.0', __CLASS__.'::'.$replacement_method); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
26 | 26 | |
27 | 27 | return $return_value; |
28 | 28 | } |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | * @return int The action ID. |
17 | 17 | */ |
18 | 18 | function as_enqueue_async_action( $hook, $args = array(), $group = '', $unique = false ) { |
19 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
20 | - return 0; |
|
21 | - } |
|
22 | - return ActionScheduler::factory()->async_unique( $hook, $args, $group, $unique ); |
|
19 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
20 | + return 0; |
|
21 | + } |
|
22 | + return ActionScheduler::factory()->async_unique( $hook, $args, $group, $unique ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | * @return int The action ID. |
35 | 35 | */ |
36 | 36 | function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false ) { |
37 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
38 | - return 0; |
|
39 | - } |
|
40 | - return ActionScheduler::factory()->single_unique( $hook, $args, $timestamp, $group, $unique ); |
|
37 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
38 | + return 0; |
|
39 | + } |
|
40 | + return ActionScheduler::factory()->single_unique( $hook, $args, $timestamp, $group, $unique ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @return int The action ID. |
54 | 54 | */ |
55 | 55 | function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false ) { |
56 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
57 | - return 0; |
|
58 | - } |
|
59 | - return ActionScheduler::factory()->recurring_unique( $hook, $args, $timestamp, $interval_in_seconds, $group, $unique ); |
|
56 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
57 | + return 0; |
|
58 | + } |
|
59 | + return ActionScheduler::factory()->recurring_unique( $hook, $args, $timestamp, $interval_in_seconds, $group, $unique ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | * @return int The action ID. |
85 | 85 | */ |
86 | 86 | function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false ) { |
87 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
88 | - return 0; |
|
89 | - } |
|
90 | - return ActionScheduler::factory()->cron_unique( $hook, $args, $timestamp, $schedule, $group, $unique ); |
|
87 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
88 | + return 0; |
|
89 | + } |
|
90 | + return ActionScheduler::factory()->cron_unique( $hook, $args, $timestamp, $schedule, $group, $unique ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -107,40 +107,40 @@ discard block |
||
107 | 107 | * @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found. |
108 | 108 | */ |
109 | 109 | function as_unschedule_action( $hook, $args = array(), $group = '' ) { |
110 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
111 | - return 0; |
|
112 | - } |
|
113 | - $params = array( |
|
114 | - 'hook' => $hook, |
|
115 | - 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
116 | - 'orderby' => 'date', |
|
117 | - 'order' => 'ASC', |
|
118 | - 'group' => $group, |
|
119 | - ); |
|
120 | - if ( is_array( $args ) ) { |
|
121 | - $params['args'] = $args; |
|
122 | - } |
|
110 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
111 | + return 0; |
|
112 | + } |
|
113 | + $params = array( |
|
114 | + 'hook' => $hook, |
|
115 | + 'status' => ActionScheduler_Store::STATUS_PENDING, |
|
116 | + 'orderby' => 'date', |
|
117 | + 'order' => 'ASC', |
|
118 | + 'group' => $group, |
|
119 | + ); |
|
120 | + if ( is_array( $args ) ) { |
|
121 | + $params['args'] = $args; |
|
122 | + } |
|
123 | 123 | |
124 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
124 | + $action_id = ActionScheduler::store()->query_action( $params ); |
|
125 | 125 | |
126 | - if ( $action_id ) { |
|
127 | - try { |
|
128 | - ActionScheduler::store()->cancel_action( $action_id ); |
|
129 | - } catch ( Exception $exception ) { |
|
130 | - ActionScheduler::logger()->log( |
|
131 | - $action_id, |
|
132 | - sprintf( |
|
133 | - /* translators: %s is the name of the hook to be cancelled. */ |
|
134 | - __( 'Caught exception while cancelling action: %s', 'action-scheduler' ), |
|
135 | - esc_attr( $hook ) |
|
136 | - ) |
|
137 | - ); |
|
126 | + if ( $action_id ) { |
|
127 | + try { |
|
128 | + ActionScheduler::store()->cancel_action( $action_id ); |
|
129 | + } catch ( Exception $exception ) { |
|
130 | + ActionScheduler::logger()->log( |
|
131 | + $action_id, |
|
132 | + sprintf( |
|
133 | + /* translators: %s is the name of the hook to be cancelled. */ |
|
134 | + __( 'Caught exception while cancelling action: %s', 'action-scheduler' ), |
|
135 | + esc_attr( $hook ) |
|
136 | + ) |
|
137 | + ); |
|
138 | 138 | |
139 | - $action_id = null; |
|
140 | - } |
|
141 | - } |
|
139 | + $action_id = null; |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | - return $action_id; |
|
143 | + return $action_id; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -151,22 +151,22 @@ discard block |
||
151 | 151 | * @param string $group The group the job is assigned to. |
152 | 152 | */ |
153 | 153 | function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) { |
154 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
155 | - return; |
|
156 | - } |
|
157 | - if ( empty( $args ) ) { |
|
158 | - if ( ! empty( $hook ) && empty( $group ) ) { |
|
159 | - ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook ); |
|
160 | - return; |
|
161 | - } |
|
162 | - if ( ! empty( $group ) && empty( $hook ) ) { |
|
163 | - ActionScheduler_Store::instance()->cancel_actions_by_group( $group ); |
|
164 | - return; |
|
165 | - } |
|
166 | - } |
|
167 | - do { |
|
168 | - $unscheduled_action = as_unschedule_action( $hook, $args, $group ); |
|
169 | - } while ( ! empty( $unscheduled_action ) ); |
|
154 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
155 | + return; |
|
156 | + } |
|
157 | + if ( empty( $args ) ) { |
|
158 | + if ( ! empty( $hook ) && empty( $group ) ) { |
|
159 | + ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook ); |
|
160 | + return; |
|
161 | + } |
|
162 | + if ( ! empty( $group ) && empty( $hook ) ) { |
|
163 | + ActionScheduler_Store::instance()->cancel_actions_by_group( $group ); |
|
164 | + return; |
|
165 | + } |
|
166 | + } |
|
167 | + do { |
|
168 | + $unscheduled_action = as_unschedule_action( $hook, $args, $group ); |
|
169 | + } while ( ! empty( $unscheduled_action ) ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -185,42 +185,42 @@ discard block |
||
185 | 185 | * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action. |
186 | 186 | */ |
187 | 187 | function as_next_scheduled_action( $hook, $args = null, $group = '' ) { |
188 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
189 | - return false; |
|
190 | - } |
|
188 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
189 | + return false; |
|
190 | + } |
|
191 | 191 | |
192 | - $params = array( |
|
193 | - 'hook' => $hook, |
|
194 | - 'orderby' => 'date', |
|
195 | - 'order' => 'ASC', |
|
196 | - 'group' => $group, |
|
197 | - ); |
|
192 | + $params = array( |
|
193 | + 'hook' => $hook, |
|
194 | + 'orderby' => 'date', |
|
195 | + 'order' => 'ASC', |
|
196 | + 'group' => $group, |
|
197 | + ); |
|
198 | 198 | |
199 | - if ( is_array( $args ) ) { |
|
200 | - $params['args'] = $args; |
|
201 | - } |
|
199 | + if ( is_array( $args ) ) { |
|
200 | + $params['args'] = $args; |
|
201 | + } |
|
202 | 202 | |
203 | - $params['status'] = ActionScheduler_Store::STATUS_RUNNING; |
|
204 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
205 | - if ( $action_id ) { |
|
206 | - return true; |
|
207 | - } |
|
203 | + $params['status'] = ActionScheduler_Store::STATUS_RUNNING; |
|
204 | + $action_id = ActionScheduler::store()->query_action( $params ); |
|
205 | + if ( $action_id ) { |
|
206 | + return true; |
|
207 | + } |
|
208 | 208 | |
209 | - $params['status'] = ActionScheduler_Store::STATUS_PENDING; |
|
210 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
211 | - if ( null === $action_id ) { |
|
212 | - return false; |
|
213 | - } |
|
209 | + $params['status'] = ActionScheduler_Store::STATUS_PENDING; |
|
210 | + $action_id = ActionScheduler::store()->query_action( $params ); |
|
211 | + if ( null === $action_id ) { |
|
212 | + return false; |
|
213 | + } |
|
214 | 214 | |
215 | - $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
216 | - $scheduled_date = $action->get_schedule()->get_date(); |
|
217 | - if ( $scheduled_date ) { |
|
218 | - return (int) $scheduled_date->format( 'U' ); |
|
219 | - } elseif ( null === $scheduled_date ) { // pending async action with NullSchedule. |
|
220 | - return true; |
|
221 | - } |
|
215 | + $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
216 | + $scheduled_date = $action->get_schedule()->get_date(); |
|
217 | + if ( $scheduled_date ) { |
|
218 | + return (int) $scheduled_date->format( 'U' ); |
|
219 | + } elseif ( null === $scheduled_date ) { // pending async action with NullSchedule. |
|
220 | + return true; |
|
221 | + } |
|
222 | 222 | |
223 | - return false; |
|
223 | + return false; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -238,24 +238,24 @@ discard block |
||
238 | 238 | * @return bool True if a matching action is pending or in-progress, false otherwise. |
239 | 239 | */ |
240 | 240 | function as_has_scheduled_action( $hook, $args = null, $group = '' ) { |
241 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
242 | - return false; |
|
243 | - } |
|
241 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
242 | + return false; |
|
243 | + } |
|
244 | 244 | |
245 | - $query_args = array( |
|
246 | - 'hook' => $hook, |
|
247 | - 'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ), |
|
248 | - 'group' => $group, |
|
249 | - 'orderby' => 'none', |
|
250 | - ); |
|
245 | + $query_args = array( |
|
246 | + 'hook' => $hook, |
|
247 | + 'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ), |
|
248 | + 'group' => $group, |
|
249 | + 'orderby' => 'none', |
|
250 | + ); |
|
251 | 251 | |
252 | - if ( null !== $args ) { |
|
253 | - $query_args['args'] = $args; |
|
254 | - } |
|
252 | + if ( null !== $args ) { |
|
253 | + $query_args['args'] = $args; |
|
254 | + } |
|
255 | 255 | |
256 | - $action_id = ActionScheduler::store()->query_action( $query_args ); |
|
256 | + $action_id = ActionScheduler::store()->query_action( $query_args ); |
|
257 | 257 | |
258 | - return null !== $action_id; |
|
258 | + return null !== $action_id; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -281,33 +281,33 @@ discard block |
||
281 | 281 | * @return array |
282 | 282 | */ |
283 | 283 | function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
284 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
285 | - return array(); |
|
286 | - } |
|
287 | - $store = ActionScheduler::store(); |
|
288 | - foreach ( array( 'date', 'modified' ) as $key ) { |
|
289 | - if ( isset( $args[ $key ] ) ) { |
|
290 | - $args[ $key ] = as_get_datetime_object( $args[ $key ] ); |
|
291 | - } |
|
292 | - } |
|
293 | - $ids = $store->query_actions( $args ); |
|
284 | + if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
285 | + return array(); |
|
286 | + } |
|
287 | + $store = ActionScheduler::store(); |
|
288 | + foreach ( array( 'date', 'modified' ) as $key ) { |
|
289 | + if ( isset( $args[ $key ] ) ) { |
|
290 | + $args[ $key ] = as_get_datetime_object( $args[ $key ] ); |
|
291 | + } |
|
292 | + } |
|
293 | + $ids = $store->query_actions( $args ); |
|
294 | 294 | |
295 | - if ( 'ids' === $return_format || 'int' === $return_format ) { |
|
296 | - return $ids; |
|
297 | - } |
|
295 | + if ( 'ids' === $return_format || 'int' === $return_format ) { |
|
296 | + return $ids; |
|
297 | + } |
|
298 | 298 | |
299 | - $actions = array(); |
|
300 | - foreach ( $ids as $action_id ) { |
|
301 | - $actions[ $action_id ] = $store->fetch_action( $action_id ); |
|
302 | - } |
|
299 | + $actions = array(); |
|
300 | + foreach ( $ids as $action_id ) { |
|
301 | + $actions[ $action_id ] = $store->fetch_action( $action_id ); |
|
302 | + } |
|
303 | 303 | |
304 | - if ( ARRAY_A == $return_format ) { |
|
305 | - foreach ( $actions as $action_id => $action_object ) { |
|
306 | - $actions[ $action_id ] = get_object_vars( $action_object ); |
|
307 | - } |
|
308 | - } |
|
304 | + if ( ARRAY_A == $return_format ) { |
|
305 | + foreach ( $actions as $action_id => $action_object ) { |
|
306 | + $actions[ $action_id ] = get_object_vars( $action_object ); |
|
307 | + } |
|
308 | + } |
|
309 | 309 | |
310 | - return $actions; |
|
310 | + return $actions; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | * @return ActionScheduler_DateTime |
329 | 329 | */ |
330 | 330 | function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) { |
331 | - if ( is_object( $date_string ) && $date_string instanceof DateTime ) { |
|
332 | - $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); |
|
333 | - } elseif ( is_numeric( $date_string ) ) { |
|
334 | - $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); |
|
335 | - } else { |
|
336 | - $date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) ); |
|
337 | - } |
|
338 | - return $date; |
|
331 | + if ( is_object( $date_string ) && $date_string instanceof DateTime ) { |
|
332 | + $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); |
|
333 | + } elseif ( is_numeric( $date_string ) ) { |
|
334 | + $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); |
|
335 | + } else { |
|
336 | + $date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) ); |
|
337 | + } |
|
338 | + return $date; |
|
339 | 339 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return int The action ID. |
17 | 17 | */ |
18 | -function as_enqueue_async_action( $hook, $args = array(), $group = '', $unique = false ) { |
|
19 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
18 | +function as_enqueue_async_action($hook, $args = array(), $group = '', $unique = false) { |
|
19 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
20 | 20 | return 0; |
21 | 21 | } |
22 | - return ActionScheduler::factory()->async_unique( $hook, $args, $group, $unique ); |
|
22 | + return ActionScheduler::factory()->async_unique($hook, $args, $group, $unique); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return int The action ID. |
35 | 35 | */ |
36 | -function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false ) { |
|
37 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
36 | +function as_schedule_single_action($timestamp, $hook, $args = array(), $group = '', $unique = false) { |
|
37 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
38 | 38 | return 0; |
39 | 39 | } |
40 | - return ActionScheduler::factory()->single_unique( $hook, $args, $timestamp, $group, $unique ); |
|
40 | + return ActionScheduler::factory()->single_unique($hook, $args, $timestamp, $group, $unique); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return int The action ID. |
54 | 54 | */ |
55 | -function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false ) { |
|
56 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
55 | +function as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '', $unique = false) { |
|
56 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
57 | 57 | return 0; |
58 | 58 | } |
59 | - return ActionScheduler::factory()->recurring_unique( $hook, $args, $timestamp, $interval_in_seconds, $group, $unique ); |
|
59 | + return ActionScheduler::factory()->recurring_unique($hook, $args, $timestamp, $interval_in_seconds, $group, $unique); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return int The action ID. |
85 | 85 | */ |
86 | -function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false ) { |
|
87 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
86 | +function as_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '', $unique = false) { |
|
87 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
88 | 88 | return 0; |
89 | 89 | } |
90 | - return ActionScheduler::factory()->cron_unique( $hook, $args, $timestamp, $schedule, $group, $unique ); |
|
90 | + return ActionScheduler::factory()->cron_unique($hook, $args, $timestamp, $schedule, $group, $unique); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return int|null The scheduled action ID if a scheduled action was found, or null if no matching action found. |
108 | 108 | */ |
109 | -function as_unschedule_action( $hook, $args = array(), $group = '' ) { |
|
110 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
109 | +function as_unschedule_action($hook, $args = array(), $group = '') { |
|
110 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
111 | 111 | return 0; |
112 | 112 | } |
113 | 113 | $params = array( |
@@ -117,22 +117,22 @@ discard block |
||
117 | 117 | 'order' => 'ASC', |
118 | 118 | 'group' => $group, |
119 | 119 | ); |
120 | - if ( is_array( $args ) ) { |
|
120 | + if (is_array($args)) { |
|
121 | 121 | $params['args'] = $args; |
122 | 122 | } |
123 | 123 | |
124 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
124 | + $action_id = ActionScheduler::store()->query_action($params); |
|
125 | 125 | |
126 | - if ( $action_id ) { |
|
126 | + if ($action_id) { |
|
127 | 127 | try { |
128 | - ActionScheduler::store()->cancel_action( $action_id ); |
|
129 | - } catch ( Exception $exception ) { |
|
128 | + ActionScheduler::store()->cancel_action($action_id); |
|
129 | + } catch (Exception $exception) { |
|
130 | 130 | ActionScheduler::logger()->log( |
131 | 131 | $action_id, |
132 | 132 | sprintf( |
133 | 133 | /* translators: %s is the name of the hook to be cancelled. */ |
134 | - __( 'Caught exception while cancelling action: %s', 'action-scheduler' ), |
|
135 | - esc_attr( $hook ) |
|
134 | + __('Caught exception while cancelling action: %s', 'action-scheduler'), |
|
135 | + esc_attr($hook) |
|
136 | 136 | ) |
137 | 137 | ); |
138 | 138 | |
@@ -150,23 +150,23 @@ discard block |
||
150 | 150 | * @param array $args Args that would have been passed to the job. |
151 | 151 | * @param string $group The group the job is assigned to. |
152 | 152 | */ |
153 | -function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) { |
|
154 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
153 | +function as_unschedule_all_actions($hook, $args = array(), $group = '') { |
|
154 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | - if ( empty( $args ) ) { |
|
158 | - if ( ! empty( $hook ) && empty( $group ) ) { |
|
159 | - ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook ); |
|
157 | + if (empty($args)) { |
|
158 | + if ( ! empty($hook) && empty($group)) { |
|
159 | + ActionScheduler_Store::instance()->cancel_actions_by_hook($hook); |
|
160 | 160 | return; |
161 | 161 | } |
162 | - if ( ! empty( $group ) && empty( $hook ) ) { |
|
163 | - ActionScheduler_Store::instance()->cancel_actions_by_group( $group ); |
|
162 | + if ( ! empty($group) && empty($hook)) { |
|
163 | + ActionScheduler_Store::instance()->cancel_actions_by_group($group); |
|
164 | 164 | return; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | do { |
168 | - $unscheduled_action = as_unschedule_action( $hook, $args, $group ); |
|
169 | - } while ( ! empty( $unscheduled_action ) ); |
|
168 | + $unscheduled_action = as_unschedule_action($hook, $args, $group); |
|
169 | + } while ( ! empty($unscheduled_action)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action. |
186 | 186 | */ |
187 | -function as_next_scheduled_action( $hook, $args = null, $group = '' ) { |
|
188 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
187 | +function as_next_scheduled_action($hook, $args = null, $group = '') { |
|
188 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
@@ -196,27 +196,27 @@ discard block |
||
196 | 196 | 'group' => $group, |
197 | 197 | ); |
198 | 198 | |
199 | - if ( is_array( $args ) ) { |
|
199 | + if (is_array($args)) { |
|
200 | 200 | $params['args'] = $args; |
201 | 201 | } |
202 | 202 | |
203 | 203 | $params['status'] = ActionScheduler_Store::STATUS_RUNNING; |
204 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
205 | - if ( $action_id ) { |
|
204 | + $action_id = ActionScheduler::store()->query_action($params); |
|
205 | + if ($action_id) { |
|
206 | 206 | return true; |
207 | 207 | } |
208 | 208 | |
209 | 209 | $params['status'] = ActionScheduler_Store::STATUS_PENDING; |
210 | - $action_id = ActionScheduler::store()->query_action( $params ); |
|
211 | - if ( null === $action_id ) { |
|
210 | + $action_id = ActionScheduler::store()->query_action($params); |
|
211 | + if (null === $action_id) { |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | |
215 | - $action = ActionScheduler::store()->fetch_action( $action_id ); |
|
215 | + $action = ActionScheduler::store()->fetch_action($action_id); |
|
216 | 216 | $scheduled_date = $action->get_schedule()->get_date(); |
217 | - if ( $scheduled_date ) { |
|
218 | - return (int) $scheduled_date->format( 'U' ); |
|
219 | - } elseif ( null === $scheduled_date ) { // pending async action with NullSchedule. |
|
217 | + if ($scheduled_date) { |
|
218 | + return (int) $scheduled_date->format('U'); |
|
219 | + } elseif (null === $scheduled_date) { // pending async action with NullSchedule. |
|
220 | 220 | return true; |
221 | 221 | } |
222 | 222 | |
@@ -237,23 +237,23 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return bool True if a matching action is pending or in-progress, false otherwise. |
239 | 239 | */ |
240 | -function as_has_scheduled_action( $hook, $args = null, $group = '' ) { |
|
241 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
240 | +function as_has_scheduled_action($hook, $args = null, $group = '') { |
|
241 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
242 | 242 | return false; |
243 | 243 | } |
244 | 244 | |
245 | 245 | $query_args = array( |
246 | 246 | 'hook' => $hook, |
247 | - 'status' => array( ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING ), |
|
247 | + 'status' => array(ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_PENDING), |
|
248 | 248 | 'group' => $group, |
249 | 249 | 'orderby' => 'none', |
250 | 250 | ); |
251 | 251 | |
252 | - if ( null !== $args ) { |
|
252 | + if (null !== $args) { |
|
253 | 253 | $query_args['args'] = $args; |
254 | 254 | } |
255 | 255 | |
256 | - $action_id = ActionScheduler::store()->query_action( $query_args ); |
|
256 | + $action_id = ActionScheduler::store()->query_action($query_args); |
|
257 | 257 | |
258 | 258 | return null !== $action_id; |
259 | 259 | } |
@@ -280,30 +280,30 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return array |
282 | 282 | */ |
283 | -function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
|
284 | - if ( ! ActionScheduler::is_initialized( __FUNCTION__ ) ) { |
|
283 | +function as_get_scheduled_actions($args = array(), $return_format = OBJECT) { |
|
284 | + if ( ! ActionScheduler::is_initialized(__FUNCTION__)) { |
|
285 | 285 | return array(); |
286 | 286 | } |
287 | 287 | $store = ActionScheduler::store(); |
288 | - foreach ( array( 'date', 'modified' ) as $key ) { |
|
289 | - if ( isset( $args[ $key ] ) ) { |
|
290 | - $args[ $key ] = as_get_datetime_object( $args[ $key ] ); |
|
288 | + foreach (array('date', 'modified') as $key) { |
|
289 | + if (isset($args[$key])) { |
|
290 | + $args[$key] = as_get_datetime_object($args[$key]); |
|
291 | 291 | } |
292 | 292 | } |
293 | - $ids = $store->query_actions( $args ); |
|
293 | + $ids = $store->query_actions($args); |
|
294 | 294 | |
295 | - if ( 'ids' === $return_format || 'int' === $return_format ) { |
|
295 | + if ('ids' === $return_format || 'int' === $return_format) { |
|
296 | 296 | return $ids; |
297 | 297 | } |
298 | 298 | |
299 | 299 | $actions = array(); |
300 | - foreach ( $ids as $action_id ) { |
|
301 | - $actions[ $action_id ] = $store->fetch_action( $action_id ); |
|
300 | + foreach ($ids as $action_id) { |
|
301 | + $actions[$action_id] = $store->fetch_action($action_id); |
|
302 | 302 | } |
303 | 303 | |
304 | - if ( ARRAY_A == $return_format ) { |
|
305 | - foreach ( $actions as $action_id => $action_object ) { |
|
306 | - $actions[ $action_id ] = get_object_vars( $action_object ); |
|
304 | + if (ARRAY_A == $return_format) { |
|
305 | + foreach ($actions as $action_id => $action_object) { |
|
306 | + $actions[$action_id] = get_object_vars($action_object); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return ActionScheduler_DateTime |
329 | 329 | */ |
330 | -function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) { |
|
331 | - if ( is_object( $date_string ) && $date_string instanceof DateTime ) { |
|
332 | - $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); |
|
333 | - } elseif ( is_numeric( $date_string ) ) { |
|
334 | - $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); |
|
330 | +function as_get_datetime_object($date_string = null, $timezone = 'UTC') { |
|
331 | + if (is_object($date_string) && $date_string instanceof DateTime) { |
|
332 | + $date = new ActionScheduler_DateTime($date_string->format('Y-m-d H:i:s'), new DateTimeZone($timezone)); |
|
333 | + } elseif (is_numeric($date_string)) { |
|
334 | + $date = new ActionScheduler_DateTime('@'.$date_string, new DateTimeZone($timezone)); |
|
335 | 335 | } else { |
336 | - $date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) ); |
|
336 | + $date = new ActionScheduler_DateTime(null === $date_string ? 'now' : $date_string, new DateTimeZone($timezone)); |
|
337 | 337 | } |
338 | 338 | return $date; |
339 | 339 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | * Class ActionScheduler_NullLogEntry |
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry { |
7 | - public function __construct( $action_id = '', $message = '' ) { |
|
7 | + public function __construct($action_id = '', $message = '') { |
|
8 | 8 | // nothing to see here |
9 | 9 | } |
10 | 10 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | * Class ActionScheduler_NullLogEntry |
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry { |
7 | - public function __construct( $action_id = '', $message = '' ) { |
|
8 | - // nothing to see here |
|
9 | - } |
|
7 | + public function __construct( $action_id = '', $message = '' ) { |
|
8 | + // nothing to see here |
|
9 | + } |
|
10 | 10 | } |
11 | 11 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * @param null $date The date & time to run the action. |
12 | 12 | */ |
13 | - public function __construct( DateTime $date = null ) { |
|
13 | + public function __construct(DateTime $date = null) { |
|
14 | 14 | $this->scheduled_date = null; |
15 | 15 | } |
16 | 16 |
@@ -5,25 +5,25 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullSchedule extends ActionScheduler_SimpleSchedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Make the $date param optional and default to null. |
|
10 | - * |
|
11 | - * @param null $date The date & time to run the action. |
|
12 | - */ |
|
13 | - public function __construct( DateTime $date = null ) { |
|
14 | - $this->scheduled_date = null; |
|
15 | - } |
|
8 | + /** |
|
9 | + * Make the $date param optional and default to null. |
|
10 | + * |
|
11 | + * @param null $date The date & time to run the action. |
|
12 | + */ |
|
13 | + public function __construct( DateTime $date = null ) { |
|
14 | + $this->scheduled_date = null; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | - * |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function __sleep() { |
|
23 | - return array(); |
|
24 | - } |
|
17 | + /** |
|
18 | + * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | + * |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function __sleep() { |
|
23 | + return array(); |
|
24 | + } |
|
25 | 25 | |
26 | - public function __wakeup() { |
|
27 | - $this->scheduled_date = null; |
|
28 | - } |
|
26 | + public function __wakeup() { |
|
27 | + $this->scheduled_date = null; |
|
28 | + } |
|
29 | 29 | } |
@@ -9,39 +9,39 @@ |
||
9 | 9 | */ |
10 | 10 | class ActionScheduler_InvalidActionException extends \InvalidArgumentException implements ActionScheduler_Exception { |
11 | 11 | |
12 | - /** |
|
13 | - * Create a new exception when the action's schedule cannot be fetched. |
|
14 | - * |
|
15 | - * @param string $action_id The action ID with bad args. |
|
16 | - * @return static |
|
17 | - */ |
|
18 | - public static function from_schedule( $action_id, $schedule ) { |
|
19 | - $message = sprintf( |
|
20 | - /* translators: 1: action ID 2: schedule */ |
|
21 | - __( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ), |
|
22 | - $action_id, |
|
23 | - var_export( $schedule, true ) |
|
24 | - ); |
|
12 | + /** |
|
13 | + * Create a new exception when the action's schedule cannot be fetched. |
|
14 | + * |
|
15 | + * @param string $action_id The action ID with bad args. |
|
16 | + * @return static |
|
17 | + */ |
|
18 | + public static function from_schedule( $action_id, $schedule ) { |
|
19 | + $message = sprintf( |
|
20 | + /* translators: 1: action ID 2: schedule */ |
|
21 | + __( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ), |
|
22 | + $action_id, |
|
23 | + var_export( $schedule, true ) |
|
24 | + ); |
|
25 | 25 | |
26 | - return new static( $message ); |
|
27 | - } |
|
26 | + return new static( $message ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Create a new exception when the action's args cannot be decoded to an array. |
|
31 | - * |
|
32 | - * @author Jeremy Pry |
|
33 | - * |
|
34 | - * @param string $action_id The action ID with bad args. |
|
35 | - * @return static |
|
36 | - */ |
|
37 | - public static function from_decoding_args( $action_id, $args = array() ) { |
|
38 | - $message = sprintf( |
|
39 | - /* translators: 1: action ID 2: arguments */ |
|
40 | - __( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ), |
|
41 | - $action_id, |
|
42 | - var_export( $args, true ) |
|
43 | - ); |
|
29 | + /** |
|
30 | + * Create a new exception when the action's args cannot be decoded to an array. |
|
31 | + * |
|
32 | + * @author Jeremy Pry |
|
33 | + * |
|
34 | + * @param string $action_id The action ID with bad args. |
|
35 | + * @return static |
|
36 | + */ |
|
37 | + public static function from_decoding_args( $action_id, $args = array() ) { |
|
38 | + $message = sprintf( |
|
39 | + /* translators: 1: action ID 2: arguments */ |
|
40 | + __( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ), |
|
41 | + $action_id, |
|
42 | + var_export( $args, true ) |
|
43 | + ); |
|
44 | 44 | |
45 | - return new static( $message ); |
|
46 | - } |
|
45 | + return new static( $message ); |
|
46 | + } |
|
47 | 47 | } |
@@ -15,15 +15,15 @@ discard block |
||
15 | 15 | * @param string $action_id The action ID with bad args. |
16 | 16 | * @return static |
17 | 17 | */ |
18 | - public static function from_schedule( $action_id, $schedule ) { |
|
18 | + public static function from_schedule($action_id, $schedule) { |
|
19 | 19 | $message = sprintf( |
20 | 20 | /* translators: 1: action ID 2: schedule */ |
21 | - __( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ), |
|
21 | + __('Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler'), |
|
22 | 22 | $action_id, |
23 | - var_export( $schedule, true ) |
|
23 | + var_export($schedule, true) |
|
24 | 24 | ); |
25 | 25 | |
26 | - return new static( $message ); |
|
26 | + return new static($message); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * @param string $action_id The action ID with bad args. |
35 | 35 | * @return static |
36 | 36 | */ |
37 | - public static function from_decoding_args( $action_id, $args = array() ) { |
|
37 | + public static function from_decoding_args($action_id, $args = array()) { |
|
38 | 38 | $message = sprintf( |
39 | 39 | /* translators: 1: action ID 2: arguments */ |
40 | - __( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ), |
|
40 | + __('Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler'), |
|
41 | 41 | $action_id, |
42 | - var_export( $args, true ) |
|
42 | + var_export($args, true) |
|
43 | 43 | ); |
44 | 44 | |
45 | - return new static( $message ); |
|
45 | + return new static($message); |
|
46 | 46 | } |
47 | 47 | } |
@@ -9,41 +9,41 @@ |
||
9 | 9 | */ |
10 | 10 | class ActionScheduler_OptionLock extends ActionScheduler_Lock { |
11 | 11 | |
12 | - /** |
|
13 | - * Set a lock using options for a given amount of time (60 seconds by default). |
|
14 | - * |
|
15 | - * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
16 | - * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
17 | - * |
|
18 | - * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
19 | - * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
20 | - * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
21 | - * to find the current number of claims in the database. |
|
22 | - * |
|
23 | - * @param string $lock_type A string to identify different lock types. |
|
24 | - * @bool True if lock value has changed, false if not or if set failed. |
|
25 | - */ |
|
26 | - public function set( $lock_type ) { |
|
27 | - return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
28 | - } |
|
12 | + /** |
|
13 | + * Set a lock using options for a given amount of time (60 seconds by default). |
|
14 | + * |
|
15 | + * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
16 | + * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
17 | + * |
|
18 | + * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
19 | + * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
20 | + * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
21 | + * to find the current number of claims in the database. |
|
22 | + * |
|
23 | + * @param string $lock_type A string to identify different lock types. |
|
24 | + * @bool True if lock value has changed, false if not or if set failed. |
|
25 | + */ |
|
26 | + public function set( $lock_type ) { |
|
27 | + return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * If a lock is set, return the timestamp it was set to expiry. |
|
32 | - * |
|
33 | - * @param string $lock_type A string to identify different lock types. |
|
34 | - * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
35 | - */ |
|
36 | - public function get_expiration( $lock_type ) { |
|
37 | - return get_option( $this->get_key( $lock_type ) ); |
|
38 | - } |
|
30 | + /** |
|
31 | + * If a lock is set, return the timestamp it was set to expiry. |
|
32 | + * |
|
33 | + * @param string $lock_type A string to identify different lock types. |
|
34 | + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
35 | + */ |
|
36 | + public function get_expiration( $lock_type ) { |
|
37 | + return get_option( $this->get_key( $lock_type ) ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get the key to use for storing the lock in the transient |
|
42 | - * |
|
43 | - * @param string $lock_type A string to identify different lock types. |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - protected function get_key( $lock_type ) { |
|
47 | - return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
48 | - } |
|
40 | + /** |
|
41 | + * Get the key to use for storing the lock in the transient |
|
42 | + * |
|
43 | + * @param string $lock_type A string to identify different lock types. |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + protected function get_key( $lock_type ) { |
|
47 | + return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
48 | + } |
|
49 | 49 | } |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * @param string $lock_type A string to identify different lock types. |
24 | 24 | * @bool True if lock value has changed, false if not or if set failed. |
25 | 25 | */ |
26 | - public function set( $lock_type ) { |
|
27 | - return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
26 | + public function set($lock_type) { |
|
27 | + return update_option($this->get_key($lock_type), time() + $this->get_duration($lock_type)); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @param string $lock_type A string to identify different lock types. |
34 | 34 | * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
35 | 35 | */ |
36 | - public function get_expiration( $lock_type ) { |
|
37 | - return get_option( $this->get_key( $lock_type ) ); |
|
36 | + public function get_expiration($lock_type) { |
|
37 | + return get_option($this->get_key($lock_type)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $lock_type A string to identify different lock types. |
44 | 44 | * @return string |
45 | 45 | */ |
46 | - protected function get_key( $lock_type ) { |
|
47 | - return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
46 | + protected function get_key($lock_type) { |
|
47 | + return sprintf('action_scheduler_lock_%s', $lock_type); |
|
48 | 48 | } |
49 | 49 | } |
@@ -10,88 +10,88 @@ |
||
10 | 10 | */ |
11 | 11 | class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request { |
12 | 12 | |
13 | - /** |
|
14 | - * Data store for querying actions |
|
15 | - * |
|
16 | - * @var ActionScheduler_Store |
|
17 | - * @access protected |
|
18 | - */ |
|
19 | - protected $store; |
|
20 | - |
|
21 | - /** |
|
22 | - * Prefix for ajax hooks |
|
23 | - * |
|
24 | - * @var string |
|
25 | - * @access protected |
|
26 | - */ |
|
27 | - protected $prefix = 'as'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Action for ajax hooks |
|
31 | - * |
|
32 | - * @var string |
|
33 | - * @access protected |
|
34 | - */ |
|
35 | - protected $action = 'async_request_queue_runner'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Initiate new async request |
|
39 | - */ |
|
40 | - public function __construct( ActionScheduler_Store $store ) { |
|
41 | - parent::__construct(); |
|
42 | - $this->store = $store; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Handle async requests |
|
47 | - * |
|
48 | - * Run a queue, and maybe dispatch another async request to run another queue |
|
49 | - * if there are still pending actions after completing a queue in this request. |
|
50 | - */ |
|
51 | - protected function handle() { |
|
52 | - do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
53 | - |
|
54 | - $sleep_seconds = $this->get_sleep_seconds(); |
|
55 | - |
|
56 | - if ( $sleep_seconds ) { |
|
57 | - sleep( $sleep_seconds ); |
|
58 | - } |
|
59 | - |
|
60 | - $this->maybe_dispatch(); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * If the async request runner is needed and allowed to run, dispatch a request. |
|
65 | - */ |
|
66 | - public function maybe_dispatch() { |
|
67 | - if ( ! $this->allow() ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $this->dispatch(); |
|
72 | - ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Only allow async requests when needed. |
|
77 | - * |
|
78 | - * Also allow 3rd party code to disable running actions via async requests. |
|
79 | - */ |
|
80 | - protected function allow() { |
|
81 | - |
|
82 | - if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { |
|
83 | - $allow = false; |
|
84 | - } else { |
|
85 | - $allow = true; |
|
86 | - } |
|
87 | - |
|
88 | - return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that. |
|
93 | - */ |
|
94 | - protected function get_sleep_seconds() { |
|
95 | - return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); |
|
96 | - } |
|
13 | + /** |
|
14 | + * Data store for querying actions |
|
15 | + * |
|
16 | + * @var ActionScheduler_Store |
|
17 | + * @access protected |
|
18 | + */ |
|
19 | + protected $store; |
|
20 | + |
|
21 | + /** |
|
22 | + * Prefix for ajax hooks |
|
23 | + * |
|
24 | + * @var string |
|
25 | + * @access protected |
|
26 | + */ |
|
27 | + protected $prefix = 'as'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Action for ajax hooks |
|
31 | + * |
|
32 | + * @var string |
|
33 | + * @access protected |
|
34 | + */ |
|
35 | + protected $action = 'async_request_queue_runner'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Initiate new async request |
|
39 | + */ |
|
40 | + public function __construct( ActionScheduler_Store $store ) { |
|
41 | + parent::__construct(); |
|
42 | + $this->store = $store; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Handle async requests |
|
47 | + * |
|
48 | + * Run a queue, and maybe dispatch another async request to run another queue |
|
49 | + * if there are still pending actions after completing a queue in this request. |
|
50 | + */ |
|
51 | + protected function handle() { |
|
52 | + do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
53 | + |
|
54 | + $sleep_seconds = $this->get_sleep_seconds(); |
|
55 | + |
|
56 | + if ( $sleep_seconds ) { |
|
57 | + sleep( $sleep_seconds ); |
|
58 | + } |
|
59 | + |
|
60 | + $this->maybe_dispatch(); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * If the async request runner is needed and allowed to run, dispatch a request. |
|
65 | + */ |
|
66 | + public function maybe_dispatch() { |
|
67 | + if ( ! $this->allow() ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $this->dispatch(); |
|
72 | + ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Only allow async requests when needed. |
|
77 | + * |
|
78 | + * Also allow 3rd party code to disable running actions via async requests. |
|
79 | + */ |
|
80 | + protected function allow() { |
|
81 | + |
|
82 | + if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { |
|
83 | + $allow = false; |
|
84 | + } else { |
|
85 | + $allow = true; |
|
86 | + } |
|
87 | + |
|
88 | + return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that. |
|
93 | + */ |
|
94 | + protected function get_sleep_seconds() { |
|
95 | + return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); |
|
96 | + } |
|
97 | 97 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * ActionScheduler_AsyncRequest_QueueRunner |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * ActionScheduler_AsyncRequest_QueueRunner class. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Initiate new async request |
39 | 39 | */ |
40 | - public function __construct( ActionScheduler_Store $store ) { |
|
40 | + public function __construct(ActionScheduler_Store $store) { |
|
41 | 41 | parent::__construct(); |
42 | 42 | $this->store = $store; |
43 | 43 | } |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | * if there are still pending actions after completing a queue in this request. |
50 | 50 | */ |
51 | 51 | protected function handle() { |
52 | - do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
52 | + do_action('action_scheduler_run_queue', 'Async Request'); // run a queue in the same way as WP Cron, but declare the Async Request context |
|
53 | 53 | |
54 | 54 | $sleep_seconds = $this->get_sleep_seconds(); |
55 | 55 | |
56 | - if ( $sleep_seconds ) { |
|
57 | - sleep( $sleep_seconds ); |
|
56 | + if ($sleep_seconds) { |
|
57 | + sleep($sleep_seconds); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->maybe_dispatch(); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * If the async request runner is needed and allowed to run, dispatch a request. |
65 | 65 | */ |
66 | 66 | public function maybe_dispatch() { |
67 | - if ( ! $this->allow() ) { |
|
67 | + if ( ! $this->allow()) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | */ |
80 | 80 | protected function allow() { |
81 | 81 | |
82 | - if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) { |
|
82 | + if ( ! has_action('action_scheduler_run_queue') || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due()) { |
|
83 | 83 | $allow = false; |
84 | 84 | } else { |
85 | 85 | $allow = true; |
86 | 86 | } |
87 | 87 | |
88 | - return apply_filters( 'action_scheduler_allow_async_request_runner', $allow ); |
|
88 | + return apply_filters('action_scheduler_allow_async_request_runner', $allow); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that. |
93 | 93 | */ |
94 | 94 | protected function get_sleep_seconds() { |
95 | - return apply_filters( 'action_scheduler_async_request_sleep_seconds', 5, $this ); |
|
95 | + return apply_filters('action_scheduler_async_request_sleep_seconds', 5, $this); |
|
96 | 96 | } |
97 | 97 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | */ |
8 | 8 | class ActionScheduler_DateTime extends DateTime { |
9 | 9 | |
10 | - /** |
|
11 | - * UTC offset. |
|
12 | - * |
|
13 | - * Only used when a timezone is not set. When a timezone string is |
|
14 | - * used, this will be set to 0. |
|
15 | - * |
|
16 | - * @var int |
|
17 | - */ |
|
18 | - protected $utcOffset = 0; |
|
10 | + /** |
|
11 | + * UTC offset. |
|
12 | + * |
|
13 | + * Only used when a timezone is not set. When a timezone string is |
|
14 | + * used, this will be set to 0. |
|
15 | + * |
|
16 | + * @var int |
|
17 | + */ |
|
18 | + protected $utcOffset = 0; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Get the unix timestamp of the current object. |
|
22 | - * |
|
23 | - * Missing in PHP 5.2 so just here so it can be supported consistently. |
|
24 | - * |
|
25 | - * @return int |
|
26 | - */ |
|
27 | - #[\ReturnTypeWillChange] |
|
28 | - public function getTimestamp() { |
|
29 | - return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); |
|
30 | - } |
|
20 | + /** |
|
21 | + * Get the unix timestamp of the current object. |
|
22 | + * |
|
23 | + * Missing in PHP 5.2 so just here so it can be supported consistently. |
|
24 | + * |
|
25 | + * @return int |
|
26 | + */ |
|
27 | + #[\ReturnTypeWillChange] |
|
28 | + public function getTimestamp() { |
|
29 | + return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Set the UTC offset. |
|
34 | - * |
|
35 | - * This represents a fixed offset instead of a timezone setting. |
|
36 | - * |
|
37 | - * @param $offset |
|
38 | - */ |
|
39 | - public function setUtcOffset( $offset ) { |
|
40 | - $this->utcOffset = intval( $offset ); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Set the UTC offset. |
|
34 | + * |
|
35 | + * This represents a fixed offset instead of a timezone setting. |
|
36 | + * |
|
37 | + * @param $offset |
|
38 | + */ |
|
39 | + public function setUtcOffset( $offset ) { |
|
40 | + $this->utcOffset = intval( $offset ); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns the timezone offset. |
|
45 | - * |
|
46 | - * @return int |
|
47 | - * @link http://php.net/manual/en/datetime.getoffset.php |
|
48 | - */ |
|
49 | - #[\ReturnTypeWillChange] |
|
50 | - public function getOffset() { |
|
51 | - return $this->utcOffset ? $this->utcOffset : parent::getOffset(); |
|
52 | - } |
|
43 | + /** |
|
44 | + * Returns the timezone offset. |
|
45 | + * |
|
46 | + * @return int |
|
47 | + * @link http://php.net/manual/en/datetime.getoffset.php |
|
48 | + */ |
|
49 | + #[\ReturnTypeWillChange] |
|
50 | + public function getOffset() { |
|
51 | + return $this->utcOffset ? $this->utcOffset : parent::getOffset(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Set the TimeZone associated with the DateTime |
|
56 | - * |
|
57 | - * @param DateTimeZone $timezone |
|
58 | - * |
|
59 | - * @return static |
|
60 | - * @link http://php.net/manual/en/datetime.settimezone.php |
|
61 | - */ |
|
62 | - #[\ReturnTypeWillChange] |
|
63 | - public function setTimezone( $timezone ) { |
|
64 | - $this->utcOffset = 0; |
|
65 | - parent::setTimezone( $timezone ); |
|
54 | + /** |
|
55 | + * Set the TimeZone associated with the DateTime |
|
56 | + * |
|
57 | + * @param DateTimeZone $timezone |
|
58 | + * |
|
59 | + * @return static |
|
60 | + * @link http://php.net/manual/en/datetime.settimezone.php |
|
61 | + */ |
|
62 | + #[\ReturnTypeWillChange] |
|
63 | + public function setTimezone( $timezone ) { |
|
64 | + $this->utcOffset = 0; |
|
65 | + parent::setTimezone( $timezone ); |
|
66 | 66 | |
67 | - return $this; |
|
68 | - } |
|
67 | + return $this; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get the timestamp with the WordPress timezone offset added or subtracted. |
|
72 | - * |
|
73 | - * @since 3.0.0 |
|
74 | - * @return int |
|
75 | - */ |
|
76 | - public function getOffsetTimestamp() { |
|
77 | - return $this->getTimestamp() + $this->getOffset(); |
|
78 | - } |
|
70 | + /** |
|
71 | + * Get the timestamp with the WordPress timezone offset added or subtracted. |
|
72 | + * |
|
73 | + * @since 3.0.0 |
|
74 | + * @return int |
|
75 | + */ |
|
76 | + public function getOffsetTimestamp() { |
|
77 | + return $this->getTimestamp() + $this->getOffset(); |
|
78 | + } |
|
79 | 79 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | #[\ReturnTypeWillChange] |
28 | 28 | public function getTimestamp() { |
29 | - return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' ); |
|
29 | + return method_exists('DateTime', 'getTimestamp') ? parent::getTimestamp() : $this->format('U'); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param $offset |
38 | 38 | */ |
39 | - public function setUtcOffset( $offset ) { |
|
40 | - $this->utcOffset = intval( $offset ); |
|
39 | + public function setUtcOffset($offset) { |
|
40 | + $this->utcOffset = intval($offset); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | * @link http://php.net/manual/en/datetime.settimezone.php |
61 | 61 | */ |
62 | 62 | #[\ReturnTypeWillChange] |
63 | - public function setTimezone( $timezone ) { |
|
63 | + public function setTimezone($timezone) { |
|
64 | 64 | $this->utcOffset = 0; |
65 | - parent::setTimezone( $timezone ); |
|
65 | + parent::setTimezone($timezone); |
|
66 | 66 | |
67 | 67 | return $this; |
68 | 68 | } |
@@ -5,105 +5,105 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_wcSystemStatus { |
7 | 7 | |
8 | - /** |
|
9 | - * The active data stores |
|
10 | - * |
|
11 | - * @var ActionScheduler_Store |
|
12 | - */ |
|
13 | - protected $store; |
|
14 | - |
|
15 | - /** |
|
16 | - * Constructor method for ActionScheduler_wcSystemStatus. |
|
17 | - * |
|
18 | - * @param ActionScheduler_Store $store Active store object. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - */ |
|
22 | - public function __construct( $store ) { |
|
23 | - $this->store = $store; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Display action data, including number of actions grouped by status and the oldest & newest action in each status. |
|
28 | - * |
|
29 | - * Helpful to identify issues, like a clogged queue. |
|
30 | - */ |
|
31 | - public function render() { |
|
32 | - $action_counts = $this->store->action_counts(); |
|
33 | - $status_labels = $this->store->get_status_labels(); |
|
34 | - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
35 | - |
|
36 | - $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Get oldest and newest scheduled dates for a given set of statuses. |
|
41 | - * |
|
42 | - * @param array $status_keys Set of statuses to find oldest & newest action for. |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - protected function get_oldest_and_newest( $status_keys ) { |
|
46 | - |
|
47 | - $oldest_and_newest = array(); |
|
48 | - |
|
49 | - foreach ( $status_keys as $status ) { |
|
50 | - $oldest_and_newest[ $status ] = array( |
|
51 | - 'oldest' => '–', |
|
52 | - 'newest' => '–', |
|
53 | - ); |
|
54 | - |
|
55 | - if ( 'in-progress' === $status ) { |
|
56 | - continue; |
|
57 | - } |
|
58 | - |
|
59 | - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
60 | - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
61 | - } |
|
62 | - |
|
63 | - return $oldest_and_newest; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Get oldest or newest scheduled date for a given status. |
|
68 | - * |
|
69 | - * @param string $status Action status label/name string. |
|
70 | - * @param string $date_type Oldest or Newest. |
|
71 | - * @return DateTime |
|
72 | - */ |
|
73 | - protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
74 | - |
|
75 | - $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
|
76 | - |
|
77 | - $action = $this->store->query_actions( |
|
78 | - array( |
|
79 | - 'claimed' => false, |
|
80 | - 'status' => $status, |
|
81 | - 'per_page' => 1, |
|
82 | - 'order' => $order, |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - if ( ! empty( $action ) ) { |
|
87 | - $date_object = $this->store->get_date( $action[0] ); |
|
88 | - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
89 | - } else { |
|
90 | - $action_date = '–'; |
|
91 | - } |
|
92 | - |
|
93 | - return $action_date; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get oldest or newest scheduled date for a given status. |
|
98 | - * |
|
99 | - * @param array $status_labels Set of statuses to find oldest & newest action for. |
|
100 | - * @param array $action_counts Number of actions grouped by status. |
|
101 | - * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
|
102 | - */ |
|
103 | - protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
104 | - $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
105 | - $as_datastore = get_class( ActionScheduler_Store::instance() ); |
|
106 | - ?> |
|
8 | + /** |
|
9 | + * The active data stores |
|
10 | + * |
|
11 | + * @var ActionScheduler_Store |
|
12 | + */ |
|
13 | + protected $store; |
|
14 | + |
|
15 | + /** |
|
16 | + * Constructor method for ActionScheduler_wcSystemStatus. |
|
17 | + * |
|
18 | + * @param ActionScheduler_Store $store Active store object. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + */ |
|
22 | + public function __construct( $store ) { |
|
23 | + $this->store = $store; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Display action data, including number of actions grouped by status and the oldest & newest action in each status. |
|
28 | + * |
|
29 | + * Helpful to identify issues, like a clogged queue. |
|
30 | + */ |
|
31 | + public function render() { |
|
32 | + $action_counts = $this->store->action_counts(); |
|
33 | + $status_labels = $this->store->get_status_labels(); |
|
34 | + $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
35 | + |
|
36 | + $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Get oldest and newest scheduled dates for a given set of statuses. |
|
41 | + * |
|
42 | + * @param array $status_keys Set of statuses to find oldest & newest action for. |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + protected function get_oldest_and_newest( $status_keys ) { |
|
46 | + |
|
47 | + $oldest_and_newest = array(); |
|
48 | + |
|
49 | + foreach ( $status_keys as $status ) { |
|
50 | + $oldest_and_newest[ $status ] = array( |
|
51 | + 'oldest' => '–', |
|
52 | + 'newest' => '–', |
|
53 | + ); |
|
54 | + |
|
55 | + if ( 'in-progress' === $status ) { |
|
56 | + continue; |
|
57 | + } |
|
58 | + |
|
59 | + $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
60 | + $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
61 | + } |
|
62 | + |
|
63 | + return $oldest_and_newest; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Get oldest or newest scheduled date for a given status. |
|
68 | + * |
|
69 | + * @param string $status Action status label/name string. |
|
70 | + * @param string $date_type Oldest or Newest. |
|
71 | + * @return DateTime |
|
72 | + */ |
|
73 | + protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
74 | + |
|
75 | + $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
|
76 | + |
|
77 | + $action = $this->store->query_actions( |
|
78 | + array( |
|
79 | + 'claimed' => false, |
|
80 | + 'status' => $status, |
|
81 | + 'per_page' => 1, |
|
82 | + 'order' => $order, |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + if ( ! empty( $action ) ) { |
|
87 | + $date_object = $this->store->get_date( $action[0] ); |
|
88 | + $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
89 | + } else { |
|
90 | + $action_date = '–'; |
|
91 | + } |
|
92 | + |
|
93 | + return $action_date; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get oldest or newest scheduled date for a given status. |
|
98 | + * |
|
99 | + * @param array $status_labels Set of statuses to find oldest & newest action for. |
|
100 | + * @param array $action_counts Number of actions grouped by status. |
|
101 | + * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
|
102 | + */ |
|
103 | + protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
104 | + $as_version = ActionScheduler_Versions::instance()->latest_version(); |
|
105 | + $as_datastore = get_class( ActionScheduler_Store::instance() ); |
|
106 | + ?> |
|
107 | 107 | |
108 | 108 | <table class="wc_status_table widefat" cellspacing="0"> |
109 | 109 | <thead> |
@@ -128,39 +128,39 @@ discard block |
||
128 | 128 | </thead> |
129 | 129 | <tbody> |
130 | 130 | <?php |
131 | - foreach ( $action_counts as $status => $count ) { |
|
132 | - // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
|
133 | - printf( |
|
134 | - '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
|
135 | - esc_html( $status_labels[ $status ] ), |
|
136 | - esc_html( number_format_i18n( $count ) ), |
|
137 | - esc_html( $oldest_and_newest[ $status ]['oldest'] ), |
|
138 | - esc_html( $oldest_and_newest[ $status ]['newest'] ) |
|
139 | - ); |
|
140 | - } |
|
141 | - ?> |
|
131 | + foreach ( $action_counts as $status => $count ) { |
|
132 | + // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
|
133 | + printf( |
|
134 | + '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
|
135 | + esc_html( $status_labels[ $status ] ), |
|
136 | + esc_html( number_format_i18n( $count ) ), |
|
137 | + esc_html( $oldest_and_newest[ $status ]['oldest'] ), |
|
138 | + esc_html( $oldest_and_newest[ $status ]['newest'] ) |
|
139 | + ); |
|
140 | + } |
|
141 | + ?> |
|
142 | 142 | </tbody> |
143 | 143 | </table> |
144 | 144 | |
145 | 145 | <?php |
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Is triggered when invoking inaccessible methods in an object context. |
|
150 | - * |
|
151 | - * @param string $name Name of method called. |
|
152 | - * @param array $arguments Parameters to invoke the method with. |
|
153 | - * |
|
154 | - * @return mixed |
|
155 | - * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
|
156 | - */ |
|
157 | - public function __call( $name, $arguments ) { |
|
158 | - switch ( $name ) { |
|
159 | - case 'print': |
|
160 | - _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
161 | - return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
162 | - } |
|
163 | - |
|
164 | - return null; |
|
165 | - } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Is triggered when invoking inaccessible methods in an object context. |
|
150 | + * |
|
151 | + * @param string $name Name of method called. |
|
152 | + * @param array $arguments Parameters to invoke the method with. |
|
153 | + * |
|
154 | + * @return mixed |
|
155 | + * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
|
156 | + */ |
|
157 | + public function __call( $name, $arguments ) { |
|
158 | + switch ( $name ) { |
|
159 | + case 'print': |
|
160 | + _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
161 | + return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
162 | + } |
|
163 | + |
|
164 | + return null; |
|
165 | + } |
|
166 | 166 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return void |
21 | 21 | */ |
22 | - public function __construct( $store ) { |
|
22 | + public function __construct($store) { |
|
23 | 23 | $this->store = $store; |
24 | 24 | } |
25 | 25 | |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | public function render() { |
32 | 32 | $action_counts = $this->store->action_counts(); |
33 | 33 | $status_labels = $this->store->get_status_labels(); |
34 | - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
34 | + $oldest_and_newest = $this->get_oldest_and_newest(array_keys($status_labels)); |
|
35 | 35 | |
36 | - $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
36 | + $this->get_template($status_labels, $action_counts, $oldest_and_newest); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,22 +42,22 @@ discard block |
||
42 | 42 | * @param array $status_keys Set of statuses to find oldest & newest action for. |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - protected function get_oldest_and_newest( $status_keys ) { |
|
45 | + protected function get_oldest_and_newest($status_keys) { |
|
46 | 46 | |
47 | 47 | $oldest_and_newest = array(); |
48 | 48 | |
49 | - foreach ( $status_keys as $status ) { |
|
50 | - $oldest_and_newest[ $status ] = array( |
|
49 | + foreach ($status_keys as $status) { |
|
50 | + $oldest_and_newest[$status] = array( |
|
51 | 51 | 'oldest' => '–', |
52 | 52 | 'newest' => '–', |
53 | 53 | ); |
54 | 54 | |
55 | - if ( 'in-progress' === $status ) { |
|
55 | + if ('in-progress' === $status) { |
|
56 | 56 | continue; |
57 | 57 | } |
58 | 58 | |
59 | - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
60 | - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
59 | + $oldest_and_newest[$status]['oldest'] = $this->get_action_status_date($status, 'oldest'); |
|
60 | + $oldest_and_newest[$status]['newest'] = $this->get_action_status_date($status, 'newest'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | return $oldest_and_newest; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param string $date_type Oldest or Newest. |
71 | 71 | * @return DateTime |
72 | 72 | */ |
73 | - protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
73 | + protected function get_action_status_date($status, $date_type = 'oldest') { |
|
74 | 74 | |
75 | 75 | $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
76 | 76 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | ) |
84 | 84 | ); |
85 | 85 | |
86 | - if ( ! empty( $action ) ) { |
|
87 | - $date_object = $this->store->get_date( $action[0] ); |
|
88 | - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
86 | + if ( ! empty($action)) { |
|
87 | + $date_object = $this->store->get_date($action[0]); |
|
88 | + $action_date = $date_object->format('Y-m-d H:i:s O'); |
|
89 | 89 | } else { |
90 | 90 | $action_date = '–'; |
91 | 91 | } |
@@ -100,42 +100,42 @@ discard block |
||
100 | 100 | * @param array $action_counts Number of actions grouped by status. |
101 | 101 | * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
102 | 102 | */ |
103 | - protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
103 | + protected function get_template($status_labels, $action_counts, $oldest_and_newest) { |
|
104 | 104 | $as_version = ActionScheduler_Versions::instance()->latest_version(); |
105 | - $as_datastore = get_class( ActionScheduler_Store::instance() ); |
|
105 | + $as_datastore = get_class(ActionScheduler_Store::instance()); |
|
106 | 106 | ?> |
107 | 107 | |
108 | 108 | <table class="wc_status_table widefat" cellspacing="0"> |
109 | 109 | <thead> |
110 | 110 | <tr> |
111 | - <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows details of Action Scheduler.', 'action-scheduler' ) ); ?></h2></th> |
|
111 | + <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e('Action Scheduler', 'action-scheduler'); ?><?php echo wc_help_tip(esc_html__('This section shows details of Action Scheduler.', 'action-scheduler')); ?></h2></th> |
|
112 | 112 | </tr> |
113 | 113 | <tr> |
114 | - <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'action-scheduler' ); ?></td> |
|
115 | - <td colspan="3"><?php echo esc_html( $as_version ); ?></td> |
|
114 | + <td colspan="2" data-export-label="Version"><?php esc_html_e('Version:', 'action-scheduler'); ?></td> |
|
115 | + <td colspan="3"><?php echo esc_html($as_version); ?></td> |
|
116 | 116 | </tr> |
117 | 117 | <tr> |
118 | - <td colspan="2" data-export-label="Data store"><?php esc_html_e( 'Data store:', 'action-scheduler' ); ?></td> |
|
119 | - <td colspan="3"><?php echo esc_html( $as_datastore ); ?></td> |
|
118 | + <td colspan="2" data-export-label="Data store"><?php esc_html_e('Data store:', 'action-scheduler'); ?></td> |
|
119 | + <td colspan="3"><?php echo esc_html($as_datastore); ?></td> |
|
120 | 120 | </tr> |
121 | 121 | <tr> |
122 | - <td><strong><?php esc_html_e( 'Action Status', 'action-scheduler' ); ?></strong></td> |
|
122 | + <td><strong><?php esc_html_e('Action Status', 'action-scheduler'); ?></strong></td> |
|
123 | 123 | <td class="help"> </td> |
124 | - <td><strong><?php esc_html_e( 'Count', 'action-scheduler' ); ?></strong></td> |
|
125 | - <td><strong><?php esc_html_e( 'Oldest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
|
126 | - <td><strong><?php esc_html_e( 'Newest Scheduled Date', 'action-scheduler' ); ?></strong></td> |
|
124 | + <td><strong><?php esc_html_e('Count', 'action-scheduler'); ?></strong></td> |
|
125 | + <td><strong><?php esc_html_e('Oldest Scheduled Date', 'action-scheduler'); ?></strong></td> |
|
126 | + <td><strong><?php esc_html_e('Newest Scheduled Date', 'action-scheduler'); ?></strong></td> |
|
127 | 127 | </tr> |
128 | 128 | </thead> |
129 | 129 | <tbody> |
130 | 130 | <?php |
131 | - foreach ( $action_counts as $status => $count ) { |
|
131 | + foreach ($action_counts as $status => $count) { |
|
132 | 132 | // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
133 | 133 | printf( |
134 | 134 | '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
135 | - esc_html( $status_labels[ $status ] ), |
|
136 | - esc_html( number_format_i18n( $count ) ), |
|
137 | - esc_html( $oldest_and_newest[ $status ]['oldest'] ), |
|
138 | - esc_html( $oldest_and_newest[ $status ]['newest'] ) |
|
135 | + esc_html($status_labels[$status]), |
|
136 | + esc_html(number_format_i18n($count)), |
|
137 | + esc_html($oldest_and_newest[$status]['oldest']), |
|
138 | + esc_html($oldest_and_newest[$status]['newest']) |
|
139 | 139 | ); |
140 | 140 | } |
141 | 141 | ?> |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @return mixed |
155 | 155 | * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
156 | 156 | */ |
157 | - public function __call( $name, $arguments ) { |
|
158 | - switch ( $name ) { |
|
157 | + public function __call($name, $arguments) { |
|
158 | + switch ($name) { |
|
159 | 159 | case 'print': |
160 | - _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
161 | - return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
160 | + _deprecated_function(__CLASS__.'::print()', '2.2.4', __CLASS__.'::render()'); |
|
161 | + return call_user_func_array(array($this, 'render'), $arguments); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return null; |