PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / trunk
Image Optimizer – Compress Images and Convert to WebP or AVIF vtrunk
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_Store.php +108 -52 1.0.2 → trunk View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 /**
4 4 * Class ActionScheduler_Store
5 + *
5 6 * @codeCoverageIgnore
6 7 */
7 8 abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
8 9 const STATUS_COMPLETE = 'complete';
@@ -11,27 +12,39 @@
11 12 const STATUS_FAILED = 'failed';
12 13 const STATUS_CANCELED = 'canceled';
13 14 const DEFAULT_CLASS = 'ActionScheduler_wpPostStore';
14 15
15 - /** @var ActionScheduler_Store */
16 - private static $store = NULL;
16 + /**
17 + * ActionScheduler_Store instance.
18 + *
19 + * @var ActionScheduler_Store
20 + */
21 + private static $store = null;
17 22
18 - /** @var int */
23 + /**
24 + * Maximum length of args.
25 + *
26 + * @var int
27 + */
19 28 protected static $max_args_length = 191;
20 29
21 30 /**
22 - * @param ActionScheduler_Action $action
23 - * @param DateTime $scheduled_date Optional Date of the first instance
24 - * to store. Otherwise uses the first date of the action's
25 - * schedule.
31 + * Save action.
26 32 *
33 + * @param ActionScheduler_Action $action Action to save.
34 + * @param null|DateTime $scheduled_date Optional Date of the first instance
35 + * to store. Otherwise uses the first date of the action's
36 + * schedule.
37 + *
27 38 * @return int The action ID
28 39 */
29 - abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
40 + abstract public function save_action( ActionScheduler_Action $action, ?DateTime $scheduled_date = null );
30 41
31 42 /**
32 - * @param string $action_id
43 + * Get action.
33 44 *
45 + * @param string $action_id Action ID.
46 + *
34 47 * @return ActionScheduler_Action
35 48 */
36 49 abstract public function fetch_action( $action_id );
37 50
@@ -140,12 +153,15 @@
140 153 */
141 154 public function extra_action_counts() {
142 155 $extra_actions = array();
143 156
144 - $pastdue_action_counts = ( int ) $this->query_actions( array(
145 - 'status' => self::STATUS_PENDING,
146 - 'date' => as_get_datetime_object(),
147 - ), 'count' );
157 + $pastdue_action_counts = (int) $this->query_actions(
158 + array(
159 + 'status' => self::STATUS_PENDING,
160 + 'date' => as_get_datetime_object(),
161 + ),
162 + 'count'
163 + );
148 164
149 165 if ( $pastdue_action_counts ) {
150 166 $extra_actions['past-due'] = $pastdue_action_counts;
151 167 }
@@ -159,20 +175,26 @@
159 175 return apply_filters( 'action_scheduler_extra_action_counts', $extra_actions );
160 176 }
161 177
162 178 /**
163 - * @param string $action_id
179 + * Cancel action.
180 + *
181 + * @param string $action_id Action ID.
164 182 */
165 183 abstract public function cancel_action( $action_id );
166 184
167 185 /**
168 - * @param string $action_id
186 + * Delete action.
187 + *
188 + * @param string $action_id Action ID.
169 189 */
170 190 abstract public function delete_action( $action_id );
171 191
172 192 /**
173 - * @param string $action_id
193 + * Get action's schedule or run timestamp.
174 194 *
195 + * @param string $action_id Action ID.
196 + *
175 197 * @return DateTime The date the action is schedule to run, or the date that it ran.
176 198 */
177 199 abstract public function get_date( $action_id );
178 200
@@ -177,89 +199,113 @@
177 199 abstract public function get_date( $action_id );
178 200
179 201
180 202 /**
181 - * @param int $max_actions
182 - * @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now.
183 - * @param array $hooks Claim only actions with a hook or hooks.
184 - * @param string $group Claim only actions in the given group.
203 + * Make a claim.
185 204 *
205 + * @param int $max_actions Maximum number of actions to claim.
206 + * @param DateTime|null $before_date Claim only actions schedule before the given date. Defaults to now.
207 + * @param array $hooks Claim only actions with a hook or hooks.
208 + * @param string $group Claim only actions in the given group.
209 + *
186 210 * @return ActionScheduler_ActionClaim
187 211 */
188 - abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
212 + abstract public function stake_claim( $max_actions = 10, ?DateTime $before_date = null, $hooks = array(), $group = '' );
189 213
190 214 /**
215 + * Get claim count.
216 + *
191 217 * @return int
192 218 */
193 219 abstract public function get_claim_count();
194 220
195 221 /**
196 - * @param ActionScheduler_ActionClaim $claim
222 + * Release the claim.
223 + *
224 + * @param ActionScheduler_ActionClaim $claim Claim object.
197 225 */
198 226 abstract public function release_claim( ActionScheduler_ActionClaim $claim );
199 227
200 228 /**
201 - * @param string $action_id
229 + * Un-claim the action.
230 + *
231 + * @param string $action_id Action ID.
202 232 */
203 233 abstract public function unclaim_action( $action_id );
204 234
205 235 /**
206 - * @param string $action_id
236 + * Mark action as failed.
237 + *
238 + * @param string $action_id Action ID.
207 239 */
208 240 abstract public function mark_failure( $action_id );
209 241
210 242 /**
211 - * @param string $action_id
243 + * Log action's execution.
244 + *
245 + * @param string $action_id Actoin ID.
212 246 */
213 247 abstract public function log_execution( $action_id );
214 248
215 249 /**
216 - * @param string $action_id
250 + * Mark action as complete.
251 + *
252 + * @param string $action_id Action ID.
217 253 */
218 254 abstract public function mark_complete( $action_id );
219 255
220 256 /**
221 - * @param string $action_id
257 + * Get action's status.
222 258 *
259 + * @param string $action_id Action ID.
223 260 * @return string
224 261 */
225 262 abstract public function get_status( $action_id );
226 263
227 264 /**
228 - * @param string $action_id
265 + * Get action's claim ID.
266 + *
267 + * @param string $action_id Action ID.
229 268 * @return mixed
230 269 */
231 270 abstract public function get_claim_id( $action_id );
232 271
233 272 /**
234 - * @param string $claim_id
273 + * Find actions by claim ID.
274 + *
275 + * @param string $claim_id Claim ID.
235 276 * @return array
236 277 */
237 278 abstract public function find_actions_by_claim_id( $claim_id );
238 279
239 280 /**
240 - * @param string $comparison_operator
281 + * Validate SQL operator.
282 + *
283 + * @param string $comparison_operator Operator.
241 284 * @return string
242 285 */
243 286 protected function validate_sql_comparator( $comparison_operator ) {
244 - if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) {
287 + if ( in_array( $comparison_operator, array( '!=', '>', '>=', '<', '<=', '=' ), true ) ) {
245 288 return $comparison_operator;
246 289 }
290 +
247 291 return '=';
248 292 }
249 293
250 294 /**
251 - * Get the time MySQL formated date/time string for an action's (next) scheduled date.
295 + * Get the time MySQL formatted date/time string for an action's (next) scheduled date.
252 296 *
253 - * @param ActionScheduler_Action $action
254 - * @param DateTime $scheduled_date (optional)
297 + * @param ActionScheduler_Action $action Action.
298 + * @param null|DateTime $scheduled_date Action's schedule date (optional).
255 299 * @return string
256 300 */
257 - protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
258 - $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
301 + protected function get_scheduled_date_string( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
302 + $next = is_null( $scheduled_date ) ? $action->get_schedule()->get_date() : $scheduled_date;
303 +
259 304 if ( ! $next ) {
260 305 $next = date_create();
261 306 }
307 +
262 308 $next->setTimezone( new DateTimeZone( 'UTC' ) );
263 309
264 310 return $next->format( 'Y-m-d H:i:s' );
265 311 }
@@ -264,16 +310,17 @@
264 310 return $next->format( 'Y-m-d H:i:s' );
265 311 }
266 312
267 313 /**
268 - * Get the time MySQL formated date/time string for an action's (next) scheduled date.
314 + * Get the time MySQL formatted date/time string for an action's (next) scheduled date.
269 315 *
270 - * @param ActionScheduler_Action $action
271 - * @param DateTime $scheduled_date (optional)
316 + * @param ActionScheduler_Action|null $action Action.
317 + * @param null|DateTime $scheduled_date Action's scheduled date (optional).
272 318 * @return string
273 319 */
274 - protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
275 - $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
320 + protected function get_scheduled_date_string_local( ActionScheduler_Action $action, ?DateTime $scheduled_date = null ) {
321 + $next = is_null( $scheduled_date ) ? $action->get_schedule()->get_date() : $scheduled_date;
322 +
276 323 if ( ! $next ) {
277 324 $next = date_create();
278 325 }
279 326
@@ -324,9 +371,10 @@
324 371 * @param ActionScheduler_Action $action Action to be validated.
325 372 * @throws InvalidArgumentException When json encoded args is too long.
326 373 */
327 374 protected function validate_action( ActionScheduler_Action $action ) {
328 - if ( strlen( json_encode( $action->get_args() ) ) > static::$max_args_length ) {
375 + if ( strlen( wp_json_encode( $action->get_args() ) ) > static::$max_args_length ) {
376 + // translators: %d is a number (maximum length of action arguments).
329 377 throw new InvalidArgumentException( sprintf( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than %d characters when encoded as JSON.', 'action-scheduler' ), static::$max_args_length ) );
330 378 }
331 379 }
332 380
@@ -384,9 +432,9 @@
384 432 * Cancel a set of action IDs.
385 433 *
386 434 * @since 3.0.0
387 435 *
388 - * @param array $action_ids List of action IDs.
436 + * @param int[] $action_ids List of action IDs.
389 437 *
390 438 * @return void
391 439 */
392 440 private function bulk_cancel_actions( $action_ids ) {
@@ -397,9 +445,11 @@
397 445 do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
398 446 }
399 447
400 448 /**
401 - * @return array
449 + * Get status labels.
450 + *
451 + * @return array<string, string>
402 452 */
403 453 public function get_status_labels() {
404 454 return array(
405 455 self::STATUS_COMPLETE => __( 'Complete', 'action-scheduler' ),
@@ -412,18 +462,20 @@
412 462
413 463 /**
414 464 * Check if there are any pending scheduled actions due to run.
415 465 *
416 - * @param ActionScheduler_Action $action
417 - * @param DateTime $scheduled_date (optional)
418 466 * @return string
419 467 */
420 468 public function has_pending_actions_due() {
421 - $pending_actions = $this->query_actions( array(
422 - 'date' => as_get_datetime_object(),
423 - 'status' => ActionScheduler_Store::STATUS_PENDING,
424 - 'orderby' => 'none',
425 - ) );
469 + $pending_actions = $this->query_actions(
470 + array(
471 + 'per_page' => 1,
472 + 'date' => as_get_datetime_object(),
473 + 'status' => self::STATUS_PENDING,
474 + 'orderby' => 'none',
475 + ),
476 + 'count'
477 + );
426 478
427 479 return ! empty( $pending_actions );
428 480 }
429 481
@@ -433,17 +485,21 @@
433 485 public function init() {}
434 486
435 487 /**
436 488 * Callable function to mark an action as migrated optionally overridden in derived classes.
489 + *
490 + * @param int $action_id Action ID.
437 491 */
438 492 public function mark_migrated( $action_id ) {}
439 493
440 494 /**
495 + * Get instance.
496 + *
441 497 * @return ActionScheduler_Store
442 498 */
443 499 public static function instance() {
444 500 if ( empty( self::$store ) ) {
445 - $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
501 + $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
446 502 self::$store = new $class();
447 503 }
448 504 return self::$store;
449 505 }