← All changes
|
vendor/woocommerce/action-scheduler/classes/ActionScheduler_ListTable.php
+32
-28
1.5.4
→
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 | */ |
| @@ -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,9 +223,9 @@ | ||
| 223 | 223 | if ( $interval <= 0 ) { |
| 224 | 224 | return __( 'Now!', 'action-scheduler' ); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $output = ''; | |
| 227 | + $output = ''; | |
| 228 | 228 | $num_time_periods = count( self::$time_periods ); |
| 229 | 229 | |
| 230 | 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++ ) { |
| 231 | 231 | |
| @@ -234,9 +234,9 @@ | ||
| 234 | 234 | if ( $periods_in_interval > 0 ) { |
| 235 | 235 | if ( ! empty( $output ) ) { |
| 236 | 236 | $output .= ' '; |
| 237 | 237 | } |
| 238 | - $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 ); | |
| 239 | 239 | $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; |
| 240 | 240 | $periods_included++; |
| 241 | 241 | } |
| 242 | 242 | } |
| @@ -280,9 +280,9 @@ | ||
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $row_html = '<ul>'; |
| 283 | 283 | foreach ( $row['args'] as $key => $value ) { |
| 284 | - $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 | |
| 285 | 285 | } |
| 286 | 286 | $row_html .= '</ul>'; |
| 287 | 287 | |
| 288 | 288 | return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); |
| @@ -330,9 +330,9 @@ | ||
| 330 | 330 | * |
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | 333 | protected function maybe_render_actions( $row, $column_name ) { |
| 334 | - if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) { | |
| 334 | + if ( 'pending' === strtolower( $row['status_name'] ) ) { | |
| 335 | 335 | return parent::maybe_render_actions( $row, $column_name ); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | return ''; |
| @@ -358,12 +358,12 @@ | ||
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 361 | 361 | foreach ( $table_list as $table_name ) { |
| 362 | - if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) { | |
| 362 | + if ( ! in_array( $wpdb->prefix . $table_name, $found_tables, true ) ) { | |
| 363 | 363 | $this->admin_notices[] = array( |
| 364 | 364 | 'class' => 'error', |
| 365 | - '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' ), | |
| 366 | 366 | ); |
| 367 | 367 | $this->recreate_tables(); |
| 368 | 368 | parent::display_admin_notices(); |
| 369 | 369 | |
| @@ -392,9 +392,9 @@ | ||
| 392 | 392 | $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' ); |
| 393 | 393 | |
| 394 | 394 | // No lock set or lock expired. |
| 395 | 395 | if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) { |
| 396 | - $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' ) ); | |
| 397 | 397 | /* translators: %s: process URL */ |
| 398 | 398 | $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress »</a>', 'action-scheduler' ), esc_url( $in_progress_url ) ); |
| 399 | 399 | } else { |
| 400 | 400 | /* translators: %d: seconds */ |
| @@ -411,22 +411,23 @@ | ||
| 411 | 411 | |
| 412 | 412 | if ( is_array( $notification ) ) { |
| 413 | 413 | delete_transient( 'action_scheduler_admin_notice' ); |
| 414 | 414 | |
| 415 | - $action = $this->store->fetch_action( $notification['action_id'] ); | |
| 415 | + $action = $this->store->fetch_action( $notification['action_id'] ); | |
| 416 | 416 | $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>'; |
| 417 | - if ( 1 == $notification['success'] ) { | |
| 417 | + | |
| 418 | + if ( 1 === absint( $notification['success'] ) ) { | |
| 418 | 419 | $class = 'updated'; |
| 419 | 420 | switch ( $notification['row_action_type'] ) { |
| 420 | - case 'run' : | |
| 421 | + case 'run': | |
| 421 | 422 | /* translators: %s: action HTML */ |
| 422 | 423 | $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html ); |
| 423 | 424 | break; |
| 424 | - case 'cancel' : | |
| 425 | + case 'cancel': | |
| 425 | 426 | /* translators: %s: action HTML */ |
| 426 | 427 | $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html ); |
| 427 | 428 | break; |
| 428 | - default : | |
| 429 | + default: | |
| 429 | 430 | /* translators: %s: action HTML */ |
| 430 | 431 | $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html ); |
| 431 | 432 | break; |
| 432 | 433 | } |
| @@ -507,8 +508,9 @@ | ||
| 507 | 508 | $this->store->delete_action( $id ); |
| 508 | 509 | } catch ( Exception $e ) { |
| 509 | 510 | // A possible reason for an exception would include a scenario where the same action is deleted by a |
| 510 | 511 | // concurrent request. |
| 512 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 511 | 513 | error_log( |
| 512 | 514 | sprintf( |
| 513 | 515 | /* translators: 1: action ID 2: exception message. */ |
| 514 | 516 | __( 'Action Scheduler was unable to delete action %1$d. Reason: %2$s', 'action-scheduler' ), |
| @@ -566,19 +568,19 @@ | ||
| 566 | 568 | */ |
| 567 | 569 | protected function process_row_action( $action_id, $row_action_type ) { |
| 568 | 570 | try { |
| 569 | 571 | switch ( $row_action_type ) { |
| 570 | - case 'run' : | |
| 572 | + case 'run': | |
| 571 | 573 | $this->runner->process_action( $action_id, 'Admin List Table' ); |
| 572 | 574 | break; |
| 573 | - case 'cancel' : | |
| 575 | + case 'cancel': | |
| 574 | 576 | $this->store->cancel_action( $action_id ); |
| 575 | 577 | break; |
| 576 | 578 | } |
| 577 | - $success = 1; | |
| 579 | + $success = 1; | |
| 578 | 580 | $error_message = ''; |
| 579 | 581 | } catch ( Exception $e ) { |
| 580 | - $success = 0; | |
| 582 | + $success = 0; | |
| 581 | 583 | $error_message = $e->getMessage(); |
| 582 | 584 | } |
| 583 | 585 | |
| 584 | 586 | set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); |
| @@ -639,13 +641,15 @@ | ||
| 639 | 641 | 'schedule' => $action->get_schedule(), |
| 640 | 642 | ); |
| 641 | 643 | } |
| 642 | 644 | |
| 643 | - $this->set_pagination_args( array( | |
| 644 | - 'total_items' => $total_items, | |
| 645 | - 'per_page' => $per_page, | |
| 646 | - 'total_pages' => ceil( $total_items / $per_page ), | |
| 647 | - ) ); | |
| 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 | + ); | |
| 648 | 652 | } |
| 649 | 653 | |
| 650 | 654 | /** |
| 651 | 655 | * Prints the available statuses so the user can click to filter. |