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 +50 -26 1.5.4 → 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,15 +12,25 @@
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 /**
31 + * Save action.
32 + *
22 33 * @param ActionScheduler_Action $action Action to save.
23 34 * @param null|DateTime $scheduled_date Optional Date of the first instance
24 35 * to store. Otherwise uses the first date of the action's
25 36 * schedule.
@@ -25,9 +36,9 @@
25 36 * schedule.
26 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 43 * Get action.
33 44 *
@@ -142,12 +153,15 @@
142 153 */
143 154 public function extra_action_counts() {
144 155 $extra_actions = array();
145 156
146 - $pastdue_action_counts = (int) $this->query_actions( array(
147 - 'status' => self::STATUS_PENDING,
148 - 'date' => as_get_datetime_object(),
149 - ), '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 + );
150 164
151 165 if ( $pastdue_action_counts ) {
152 166 $extra_actions['past-due'] = $pastdue_action_counts;
153 167 }
@@ -187,16 +201,16 @@
187 201
188 202 /**
189 203 * Make a claim.
190 204 *
191 - * @param int $max_actions Maximum number of actions to claim.
192 - * @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now.
193 - * @param array $hooks Claim only actions with a hook or hooks.
194 - * @param string $group Claim only actions in the given group.
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.
195 209 *
196 210 * @return ActionScheduler_ActionClaim
197 211 */
198 - 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 = '' );
199 213
200 214 /**
201 215 * Get claim count.
202 216 *
@@ -269,11 +283,12 @@
269 283 * @param string $comparison_operator Operator.
270 284 * @return string
271 285 */
272 286 protected function validate_sql_comparator( $comparison_operator ) {
273 - if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) {
287 + if ( in_array( $comparison_operator, array( '!=', '>', '>=', '<', '<=', '=' ), true ) ) {
274 288 return $comparison_operator;
275 289 }
290 +
276 291 return '=';
277 292 }
278 293
279 294 /**
@@ -282,13 +297,15 @@
282 297 * @param ActionScheduler_Action $action Action.
283 298 * @param null|DateTime $scheduled_date Action's schedule date (optional).
284 299 * @return string
285 300 */
286 - protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
287 - $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 +
288 304 if ( ! $next ) {
289 305 $next = date_create();
290 306 }
307 +
291 308 $next->setTimezone( new DateTimeZone( 'UTC' ) );
292 309
293 310 return $next->format( 'Y-m-d H:i:s' );
294 311 }
@@ -295,14 +312,15 @@
295 312
296 313 /**
297 314 * Get the time MySQL formatted date/time string for an action's (next) scheduled date.
298 315 *
299 - * @param ActionScheduler_Action $action Action.
300 - * @param null|DateTime $scheduled_date Action's scheduled date (optional).
316 + * @param ActionScheduler_Action|null $action Action.
317 + * @param null|DateTime $scheduled_date Action's scheduled date (optional).
301 318 * @return string
302 319 */
303 - protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
304 - $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 +
305 323 if ( ! $next ) {
306 324 $next = date_create();
307 325 }
308 326
@@ -447,13 +465,17 @@
447 465 *
448 466 * @return string
449 467 */
450 468 public function has_pending_actions_due() {
451 - $pending_actions = $this->query_actions( array(
452 - 'date' => as_get_datetime_object(),
453 - 'status' => self::STATUS_PENDING,
454 - 'orderby' => 'none',
455 - ) );
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 + );
456 478
457 479 return ! empty( $pending_actions );
458 480 }
459 481
@@ -469,13 +491,15 @@
469 491 */
470 492 public function mark_migrated( $action_id ) {}
471 493
472 494 /**
495 + * Get instance.
496 + *
473 497 * @return ActionScheduler_Store
474 498 */
475 499 public static function instance() {
476 500 if ( empty( self::$store ) ) {
477 - $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
501 + $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
478 502 self::$store = new $class();
479 503 }
480 504 return self::$store;
481 505 }