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/ActionScheduler_ListTable.php +52 -47 1.5.1 → trunk View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 /**
4 4 * Implements the admin view of the actions.
5 + *
5 6 * @codeCoverageIgnore
6 7 */
7 8 class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
8 9
@@ -48,12 +49,11 @@
48 49 */
49 50 protected $runner;
50 51
51 52 /**
52 - * Bulk actions. The key of the array is the method name of the implementation:
53 + * Bulk actions. The key of the array is the method name of the implementation.
54 + * Example: bulk_<key>(array $ids, string $sql_in).
53 55 *
54 - * bulk_<key>(array $ids, string $sql_in).
55 - *
56 56 * See the comments in the parent class for further details
57 57 *
58 58 * @var array
59 59 */
@@ -75,11 +75,11 @@
75 75
76 76 /**
77 77 * Sets the current data store object into `store->action` and initialises the object.
78 78 *
79 - * @param ActionScheduler_Store $store
80 - * @param ActionScheduler_Logger $logger
81 - * @param ActionScheduler_QueueRunner $runner
79 + * @param ActionScheduler_Store $store Store object.
80 + * @param ActionScheduler_Logger $logger Logger object.
81 + * @param ActionScheduler_QueueRunner $runner Runner object.
82 82 */
83 83 public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) {
84 84
85 85 $this->store = $store;
@@ -117,9 +117,9 @@
117 117 $request_status = $this->get_request_status();
118 118
119 119 if ( empty( $request_status ) ) {
120 120 $this->sort_by[] = 'status';
121 - } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) {
121 + } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ), true ) ) {
122 122 $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) );
123 123 $this->sort_by[] = 'claim_id';
124 124 }
125 125
@@ -124,11 +124,11 @@
124 124 }
125 125
126 126 $this->row_actions = array(
127 127 'hook' => array(
128 - 'run' => array(
129 - 'name' => __( 'Run', 'action-scheduler' ),
130 - 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
128 + 'run' => array(
129 + 'name' => __( 'Run', 'action-scheduler' ),
130 + 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
131 131 ),
132 132 'cancel' => array(
133 133 'name' => __( 'Cancel', 'action-scheduler' ),
134 134 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ),
@@ -223,11 +223,12 @@
223 223 if ( $interval <= 0 ) {
224 224 return __( 'Now!', 'action-scheduler' );
225 225 }
226 226
227 - $output = '';
227 + $output = '';
228 + $num_time_periods = count( self::$time_periods );
228 229
229 - for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) {
230 + for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < $num_time_periods && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) {
230 231
231 232 $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] );
232 233
233 234 if ( $periods_in_interval > 0 ) {
@@ -233,9 +234,9 @@
233 234 if ( $periods_in_interval > 0 ) {
234 235 if ( ! empty( $output ) ) {
235 236 $output .= ' ';
236 237 }
237 - $output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
238 + $output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
238 239 $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds'];
239 240 $periods_included++;
240 241 }
241 242 }
@@ -245,9 +246,9 @@
245 246
246 247 /**
247 248 * Returns the recurrence of an action or 'Non-repeating'. The output is human readable.
248 249 *
249 - * @param ActionScheduler_Action $action
250 + * @param ActionScheduler_Action $action Action object.
250 251 *
251 252 * @return string
252 253 */
253 254 protected function get_recurrence( $action ) {
@@ -268,9 +269,9 @@
268 269
269 270 /**
270 271 * Serializes the argument of an action to render it in a human friendly format.
271 272 *
272 - * @param array $row The array representation of the current row of the table
273 + * @param array $row The array representation of the current row of the table.
273 274 *
274 275 * @return string
275 276 */
276 277 public function column_args( array $row ) {
@@ -279,9 +280,9 @@
279 280 }
280 281
281 282 $row_html = '<ul>';
282 283 foreach ( $row['args'] as $key => $value ) {
283 - $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) );
284 + $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
284 285 }
285 286 $row_html .= '</ul>';
286 287
287 288 return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row );
@@ -310,10 +311,10 @@
310 311
311 312 /**
312 313 * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal.
313 314 *
314 - * @param ActionScheduler_LogEntry $log_entry
315 - * @param DateTimezone $timezone
315 + * @param ActionScheduler_LogEntry $log_entry Log entry object.
316 + * @param DateTimezone $timezone Timestamp.
316 317 * @return string
317 318 */
318 319 protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) {
319 320 $date = $log_entry->get_date();
@@ -323,15 +324,15 @@
323 324
324 325 /**
325 326 * Only display row actions for pending actions.
326 327 *
327 - * @param array $row Row to render
328 - * @param string $column_name Current row
328 + * @param array $row Row to render.
329 + * @param string $column_name Current row.
329 330 *
330 331 * @return string
331 332 */
332 333 protected function maybe_render_actions( $row, $column_name ) {
333 - if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) {
334 + if ( 'pending' === strtolower( $row['status_name'] ) ) {
334 335 return parent::maybe_render_actions( $row, $column_name );
335 336 }
336 337
337 338 return '';
@@ -357,12 +358,12 @@
357 358 );
358 359
359 360 $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
360 361 foreach ( $table_list as $table_name ) {
361 - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
362 + if ( ! in_array( $wpdb->prefix . $table_name, $found_tables, true ) ) {
362 363 $this->admin_notices[] = array(
363 364 'class' => 'error',
364 - 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ),
365 + 'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).', 'action-scheduler' ),
365 366 );
366 367 $this->recreate_tables();
367 368 parent::display_admin_notices();
368 369
@@ -389,11 +390,11 @@
389 390 } elseif ( $this->store->has_pending_actions_due() ) {
390 391
391 392 $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' );
392 393
393 - // No lock set or lock expired
394 + // No lock set or lock expired.
394 395 if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) {
395 - $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
396 + $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
396 397 /* translators: %s: process URL */
397 398 $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress &raquo;</a>', 'action-scheduler' ), esc_url( $in_progress_url ) );
398 399 } else {
399 400 /* translators: %d: seconds */
@@ -410,22 +411,23 @@
410 411
411 412 if ( is_array( $notification ) ) {
412 413 delete_transient( 'action_scheduler_admin_notice' );
413 414
414 - $action = $this->store->fetch_action( $notification['action_id'] );
415 + $action = $this->store->fetch_action( $notification['action_id'] );
415 416 $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>';
416 - if ( 1 == $notification['success'] ) {
417 +
418 + if ( 1 === absint( $notification['success'] ) ) {
417 419 $class = 'updated';
418 420 switch ( $notification['row_action_type'] ) {
419 - case 'run' :
421 + case 'run':
420 422 /* translators: %s: action HTML */
421 423 $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html );
422 424 break;
423 - case 'cancel' :
425 + case 'cancel':
424 426 /* translators: %s: action HTML */
425 427 $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html );
426 428 break;
427 - default :
429 + default:
428 430 /* translators: %s: action HTML */
429 431 $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html );
430 432 break;
431 433 }
@@ -448,9 +450,9 @@
448 450
449 451 /**
450 452 * Prints the scheduled date in a human friendly format.
451 453 *
452 - * @param array $row The array representation of the current row of the table
454 + * @param array $row The array representation of the current row of the table.
453 455 *
454 456 * @return string
455 457 */
456 458 public function column_schedule( $row ) {
@@ -459,9 +461,9 @@
459 461
460 462 /**
461 463 * Get the scheduled date in a human friendly format.
462 464 *
463 - * @param ActionScheduler_Schedule $schedule
465 + * @param ActionScheduler_Schedule $schedule Action's schedule.
464 466 * @return string
465 467 */
466 468 protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) {
467 469
@@ -491,15 +493,15 @@
491 493 return $schedule_display_string;
492 494 }
493 495
494 496 /**
495 - * Bulk delete
497 + * Bulk delete.
496 498 *
497 499 * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data
498 500 * properly validated by the callee and it will delete the actions without any extra validation.
499 501 *
500 - * @param array $ids
501 - * @param string $ids_sql Inherited and unused
502 + * @param int[] $ids Action IDs.
503 + * @param string $ids_sql Inherited and unused.
502 504 */
503 505 protected function bulk_delete( array $ids, $ids_sql ) {
504 506 foreach ( $ids as $id ) {
505 507 try {
@@ -506,8 +508,9 @@
506 508 $this->store->delete_action( $id );
507 509 } catch ( Exception $e ) {
508 510 // A possible reason for an exception would include a scenario where the same action is deleted by a
509 511 // concurrent request.
512 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
510 513 error_log(
511 514 sprintf(
512 515 /* translators: 1: action ID 2: exception message. */
513 516 __( 'Action Scheduler was unable to delete action %1$d. Reason: %2$s', 'action-scheduler' ),
@@ -522,9 +525,9 @@
522 525 /**
523 526 * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their
524 527 * parameters are valid.
525 528 *
526 - * @param int $action_id
529 + * @param int $action_id Action ID.
527 530 */
528 531 protected function row_action_cancel( $action_id ) {
529 532 $this->process_row_action( $action_id, 'cancel' );
530 533 }
@@ -532,9 +535,9 @@
532 535 /**
533 536 * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their
534 537 * parameters are valid.
535 538 *
536 - * @param int $action_id
539 + * @param int $action_id Action ID.
537 540 */
538 541 protected function row_action_run( $action_id ) {
539 542 $this->process_row_action( $action_id, 'run' );
540 543 }
@@ -559,25 +562,25 @@
559 562 }
560 563 /**
561 564 * Implements the logic behind processing an action once an action link is clicked on the list table.
562 565 *
563 - * @param int $action_id
566 + * @param int $action_id Action ID.
564 567 * @param string $row_action_type The type of action to perform on the action.
565 568 */
566 569 protected function process_row_action( $action_id, $row_action_type ) {
567 570 try {
568 571 switch ( $row_action_type ) {
569 - case 'run' :
572 + case 'run':
570 573 $this->runner->process_action( $action_id, 'Admin List Table' );
571 574 break;
572 - case 'cancel' :
575 + case 'cancel':
573 576 $this->store->cancel_action( $action_id );
574 577 break;
575 578 }
576 - $success = 1;
579 + $success = 1;
577 580 $error_message = '';
578 581 } catch ( Exception $e ) {
579 - $success = 0;
582 + $success = 0;
580 583 $error_message = $e->getMessage();
581 584 }
582 585
583 586 set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 );
@@ -638,13 +641,15 @@
638 641 'schedule' => $action->get_schedule(),
639 642 );
640 643 }
641 644
642 - $this->set_pagination_args( array(
643 - 'total_items' => $total_items,
644 - 'per_page' => $per_page,
645 - 'total_pages' => ceil( $total_items / $per_page ),
646 - ) );
645 + $this->set_pagination_args(
646 + array(
647 + 'total_items' => $total_items,
648 + 'per_page' => $per_page,
649 + 'total_pages' => ceil( $total_items / $per_page ),
650 + )
651 + );
647 652 }
648 653
649 654 /**
650 655 * Prints the available statuses so the user can click to filter.