Skip to content

Commit

Permalink
Merge branch 'trunk' into phpcs/ActionScheduler_WPCLI_Scheduler_comma…
Browse files Browse the repository at this point in the history
…nd.php
  • Loading branch information
crstauf committed Oct 25, 2024
2 parents 47812c9 + 9c12a73 commit 3855fbb
Show file tree
Hide file tree
Showing 23 changed files with 454 additions and 267 deletions.
6 changes: 2 additions & 4 deletions classes/ActionScheduler_InvalidActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function from_schedule( $action_id, $schedule ) {
/* translators: 1: action ID 2: schedule */
__( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ),
$action_id,
var_export( $schedule, true )
var_export( $schedule, true ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
);

return new static( $message );
Expand All @@ -30,8 +30,6 @@ public static function from_schedule( $action_id, $schedule ) {
/**
* Create a new exception when the action's args cannot be decoded to an array.
*
* @author Jeremy Pry
*
* @param string $action_id The action ID with bad args.
* @param mixed $args Passed arguments.
* @return static
Expand All @@ -41,7 +39,7 @@ public static function from_decoding_args( $action_id, $args = array() ) {
/* translators: 1: action ID 2: arguments */
__( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ),
$action_id,
var_export( $args, true )
var_export( $args, true ) // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
);

return new static( $message );
Expand Down
60 changes: 32 additions & 28 deletions classes/ActionScheduler_ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/**
* Implements the admin view of the actions.
*
* @codeCoverageIgnore
*/
class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
Expand Down Expand Up @@ -49,9 +50,8 @@ class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
protected $runner;

/**
* Bulk actions. The key of the array is the method name of the implementation:
*
* bulk_<key>(array $ids, string $sql_in).
* Bulk actions. The key of the array is the method name of the implementation.
* Example: bulk_<key>(array $ids, string $sql_in).
*
* See the comments in the parent class for further details
*
Expand Down Expand Up @@ -118,16 +118,16 @@ public function __construct( ActionScheduler_Store $store, ActionScheduler_Logge

if ( empty( $request_status ) ) {
$this->sort_by[] = 'status';
} elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) {
} elseif ( in_array( $request_status, array( 'in-progress', 'failed' ), true ) ) {
$this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) );
$this->sort_by[] = 'claim_id';
}

$this->row_actions = array(
'hook' => array(
'run' => array(
'name' => __( 'Run', 'action-scheduler' ),
'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
'run' => array(
'name' => __( 'Run', 'action-scheduler' ),
'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
),
'cancel' => array(
'name' => __( 'Cancel', 'action-scheduler' ),
Expand Down Expand Up @@ -224,7 +224,7 @@ private static function human_interval( $interval, $periods_to_include = 2 ) {
return __( 'Now!', 'action-scheduler' );
}

$output = '';
$output = '';
$num_time_periods = count( self::$time_periods );

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++ ) {
Expand All @@ -235,7 +235,7 @@ private static function human_interval( $interval, $periods_to_include = 2 ) {
if ( ! empty( $output ) ) {
$output .= ' ';
}
$output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
$output .= sprintf( translate_nooped_plural( self::$time_periods[ $time_period_index ]['names'], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
$seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds'];
$periods_included++;
}
Expand Down Expand Up @@ -281,7 +281,7 @@ public function column_args( array $row ) {

$row_html = '<ul>';
foreach ( $row['args'] as $key => $value ) {
$row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) );
$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
}
$row_html .= '</ul>';

Expand Down Expand Up @@ -331,7 +331,7 @@ protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, Date
* @return string
*/
protected function maybe_render_actions( $row, $column_name ) {
if ( 'pending' === strtolower( $row[ 'status_name' ] ) ) {
if ( 'pending' === strtolower( $row['status_name'] ) ) {
return parent::maybe_render_actions( $row, $column_name );
}

Expand Down Expand Up @@ -359,10 +359,10 @@ public function display_admin_notices() {

$found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}actionscheduler%'" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
foreach ( $table_list as $table_name ) {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables ) ) {
if ( ! in_array( $wpdb->prefix . $table_name, $found_tables, true ) ) {
$this->admin_notices[] = array(
'class' => 'error',
'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).' , 'action-scheduler' ),
'message' => __( 'It appears one or more database tables were missing. Attempting to re-create the missing table(s).', 'action-scheduler' ),
);
$this->recreate_tables();
parent::display_admin_notices();
Expand Down Expand Up @@ -393,7 +393,7 @@ public function display_admin_notices() {

// No lock set or lock expired.
if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) {
$in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
$in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
/* translators: %s: process URL */
$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 ) );
} else {
Expand All @@ -412,20 +412,21 @@ public function display_admin_notices() {
if ( is_array( $notification ) ) {
delete_transient( 'action_scheduler_admin_notice' );

$action = $this->store->fetch_action( $notification['action_id'] );
$action = $this->store->fetch_action( $notification['action_id'] );
$action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>';
if ( 1 == $notification['success'] ) {

if ( 1 === absint( $notification['success'] ) ) {
$class = 'updated';
switch ( $notification['row_action_type'] ) {
case 'run' :
case 'run':
/* translators: %s: action HTML */
$action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html );
break;
case 'cancel' :
case 'cancel':
/* translators: %s: action HTML */
$action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html );
break;
default :
default:
/* translators: %s: action HTML */
$action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html );
break;
Expand Down Expand Up @@ -508,6 +509,7 @@ protected function bulk_delete( array $ids, $ids_sql ) {
} catch ( Exception $e ) {
// A possible reason for an exception would include a scenario where the same action is deleted by a
// concurrent request.
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log(
sprintf(
/* translators: 1: action ID 2: exception message. */
Expand Down Expand Up @@ -567,17 +569,17 @@ protected function recreate_tables() {
protected function process_row_action( $action_id, $row_action_type ) {
try {
switch ( $row_action_type ) {
case 'run' :
case 'run':
$this->runner->process_action( $action_id, 'Admin List Table' );
break;
case 'cancel' :
case 'cancel':
$this->store->cancel_action( $action_id );
break;
}
$success = 1;
$success = 1;
$error_message = '';
} catch ( Exception $e ) {
$success = 0;
$success = 0;
$error_message = $e->getMessage();
}

Expand Down Expand Up @@ -640,11 +642,13 @@ public function prepare_items() {
);
}

$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
)
);
}

/**
Expand Down
12 changes: 9 additions & 3 deletions classes/ActionScheduler_LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
class ActionScheduler_LogEntry {

/**
* Action's ID for log entry.
*
* @var int $action_id
*/
protected $action_id = '';
protected $action_id = '';

/**
* Log entry's message.
*
* @var string $message
*/
protected $message = '';
protected $message = '';

/**
* Log entry's date.
*
* @var Datetime $date
*/
protected $date;
Expand Down Expand Up @@ -43,7 +49,7 @@ public function __construct( $action_id, $message, $date = null ) {

$this->action_id = $action_id;
$this->message = $message;
$this->date = $date ? $date : new Datetime;
$this->date = $date ? $date : new Datetime();
}

/**
Expand Down
1 change: 1 addition & 0 deletions classes/ActionScheduler_OptionLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* for up-to a given duration.
*
* Class ActionScheduler_OptionLock
*
* @since 3.0.0
*/
class ActionScheduler_OptionLock extends ActionScheduler_Lock {
Expand Down
Loading

0 comments on commit 3855fbb

Please sign in to comment.