Plugin Updates

This commit is contained in:
Tony Volpe
2024-03-19 15:33:31 +00:00
parent ff5b56dc44
commit 3a70a6e4bf
317 changed files with 8178 additions and 2933 deletions

View File

@@ -153,11 +153,41 @@ abstract class ActionScheduler {
add_action( 'init', array( $store, 'init' ), 1, 0 );
add_action( 'init', array( $logger, 'init' ), 1, 0 );
add_action( 'init', array( $runner, 'init' ), 1, 0 );
add_action(
'init',
/**
* Runs after the active store's init() method has been called.
*
* It would probably be preferable to have $store->init() (or it's parent method) set this itself,
* once it has initialized, however that would cause problems in cases where a custom data store is in
* use and it has not yet been updated to follow that same logic.
*/
function () {
self::$data_store_initialized = true;
/**
* Fires when Action Scheduler is ready: it is safe to use the procedural API after this point.
*
* @since 3.5.5
*/
do_action( 'action_scheduler_init' );
},
1
);
} else {
$admin_view->init();
$store->init();
$logger->init();
$runner->init();
self::$data_store_initialized = true;
/**
* Fires when Action Scheduler is ready: it is safe to use the procedural API after this point.
*
* @since 3.5.5
*/
do_action( 'action_scheduler_init' );
}
if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) {
@@ -166,14 +196,13 @@ abstract class ActionScheduler {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' );
WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Clean_Command' );
if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) {
$command = new Migration_Command();
$command->register();
}
}
self::$data_store_initialized = true;
/**
* Handle WP comment cleanup after migration.
*/
@@ -192,8 +221,12 @@ abstract class ActionScheduler {
*/
public static function is_initialized( $function_name = null ) {
if ( ! self::$data_store_initialized && ! empty( $function_name ) ) {
$message = sprintf( __( '%s() was called before the Action Scheduler data store was initialized', 'action-scheduler' ), esc_attr( $function_name ) );
error_log( $message, E_WARNING );
$message = sprintf(
/* translators: %s function name. */
__( '%s() was called before the Action Scheduler data store was initialized', 'action-scheduler' ),
esc_attr( $function_name )
);
_doing_it_wrong( $function_name, $message, '3.1.6' );
}
return self::$data_store_initialized;

View File

@@ -673,24 +673,34 @@ abstract class ActionScheduler_Abstract_ListTable extends WP_List_Table {
// Helper to set 'all' filter when not set on status counts passed in.
if ( ! isset( $this->status_counts['all'] ) ) {
$this->status_counts = array( 'all' => array_sum( $this->status_counts ) ) + $this->status_counts;
$all_count = array_sum( $this->status_counts );
if ( isset( $this->status_counts['past-due'] ) ) {
$all_count -= $this->status_counts['past-due'];
}
$this->status_counts = array( 'all' => $all_count ) + $this->status_counts;
}
foreach ( $this->status_counts as $status_name => $count ) {
// Translated status labels.
$status_labels = ActionScheduler_Store::instance()->get_status_labels();
$status_labels['all'] = _x( 'All', 'status labels', 'action-scheduler' );
$status_labels['past-due'] = _x( 'Past-due', 'status labels', 'action-scheduler' );
foreach ( $this->status_counts as $status_slug => $count ) {
if ( 0 === $count ) {
continue;
}
if ( $status_name === $request_status || ( empty( $request_status ) && 'all' === $status_name ) ) {
if ( $status_slug === $request_status || ( empty( $request_status ) && 'all' === $status_slug ) ) {
$status_list_item = '<li class="%1$s"><a href="%2$s" class="current">%3$s</a> (%4$d)</li>';
} else {
$status_list_item = '<li class="%1$s"><a href="%2$s">%3$s</a> (%4$d)</li>';
}
$status_filter_url = ( 'all' === $status_name ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_name );
$status_name = isset( $status_labels[ $status_slug ] ) ? $status_labels[ $status_slug ] : ucfirst( $status_slug );
$status_filter_url = ( 'all' === $status_slug ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_slug );
$status_filter_url = remove_query_arg( array( 'paged', 's' ), $status_filter_url );
$status_list_items[] = sprintf( $status_list_item, esc_attr( $status_name ), esc_url( $status_filter_url ), esc_html( ucfirst( $status_name ) ), absint( $count ) );
$status_list_items[] = sprintf( $status_list_item, esc_attr( $status_slug ), esc_url( $status_filter_url ), esc_html( $status_name ), absint( $count ) );
}
if ( $status_list_items ) {

View File

@@ -48,30 +48,56 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
* Generally, this should be capitalised and not localised as it's a proper noun.
*/
public function process_action( $action_id, $context = '' ) {
// Temporarily override the error handler while we process the current action.
set_error_handler(
/**
* Temporary error handler which can catch errors and convert them into exceptions. This faciliates more
* robust error handling across all supported PHP versions.
*
* @throws Exception
*
* @param int $type Error level expressed as an integer.
* @param string $message Error message.
*/
function ( $type, $message ) {
throw new Exception( $message );
},
E_USER_ERROR | E_RECOVERABLE_ERROR
);
/*
* The nested try/catch structure is required because we potentially need to convert thrown errors into
* exceptions (and an exception thrown from a catch block cannot be caught by a later catch block in the *same*
* structure).
*/
try {
$valid_action = false;
do_action( 'action_scheduler_before_execute', $action_id, $context );
try {
$valid_action = false;
do_action( 'action_scheduler_before_execute', $action_id, $context );
if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) {
do_action( 'action_scheduler_execution_ignored', $action_id, $context );
return;
if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) {
do_action( 'action_scheduler_execution_ignored', $action_id, $context );
return;
}
$valid_action = true;
do_action( 'action_scheduler_begin_execute', $action_id, $context );
$action = $this->store->fetch_action( $action_id );
$this->store->log_execution( $action_id );
$action->execute();
do_action( 'action_scheduler_after_execute', $action_id, $action, $context );
$this->store->mark_complete( $action_id );
} catch ( Throwable $e ) {
// Throwable is defined when executing under PHP 7.0 and up. We convert it to an exception, for
// compatibility with ActionScheduler_Logger.
throw new Exception( $e->getMessage(), $e->getCode(), $e );
}
$valid_action = true;
do_action( 'action_scheduler_begin_execute', $action_id, $context );
$action = $this->store->fetch_action( $action_id );
$this->store->log_execution( $action_id );
$action->execute();
do_action( 'action_scheduler_after_execute', $action_id, $action, $context );
$this->store->mark_complete( $action_id );
} catch ( Exception $e ) {
if ( $valid_action ) {
$this->store->mark_failure( $action_id );
do_action( 'action_scheduler_failed_execution', $action_id, $e, $context );
} else {
do_action( 'action_scheduler_failed_validation', $action_id, $e, $context );
}
// This catch block exists for compatibility with PHP 5.6.
$this->handle_action_error( $action_id, $e, $context, $valid_action );
} finally {
restore_error_handler();
}
if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) {
@@ -79,6 +105,39 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
}
}
/**
* Marks actions as either having failed execution or failed validation, as appropriate.
*
* @param int $action_id Action ID.
* @param Exception $e Exception instance.
* @param string $context Execution context.
* @param bool $valid_action If the action is valid.
*
* @return void
*/
private function handle_action_error( $action_id, $e, $context, $valid_action ) {
if ( $valid_action ) {
$this->store->mark_failure( $action_id );
/**
* Runs when action execution fails.
*
* @param int $action_id Action ID.
* @param Exception $e Exception instance.
* @param string $context Execution context.
*/
do_action( 'action_scheduler_failed_execution', $action_id, $e, $context );
} else {
/**
* Runs when action validation fails.
*
* @param int $action_id Action ID.
* @param Exception $e Exception instance.
* @param string $context Execution context.
*/
do_action( 'action_scheduler_failed_validation', $action_id, $e, $context );
}
}
/**
* Schedule the next instance of the action if necessary.
*
@@ -143,12 +202,22 @@ abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abst
return false;
}
// Now let's fetch the first action (having the same hook) of *any status*ithin the same window.
// Now let's fetch the first action (having the same hook) of *any status* within the same window.
unset( $query_args['status'] );
$first_action_id_with_the_same_hook = $this->store->query_actions( $query_args );
// If the IDs match, then actions for this hook must be consistently failing.
return $first_action_id_with_the_same_hook === $first_failing_action_id;
/**
* If a recurring action is assessed as consistently failing, it will not be rescheduled. This hook provides a
* way to observe and optionally override that assessment.
*
* @param bool $is_consistently_failing If the action is considered to be consistently failing.
* @param ActionScheduler_Action $action The action being assessed.
*/
return (bool) apply_filters(
'action_scheduler_recurring_action_is_consistently_failing',
$first_action_id_with_the_same_hook === $first_failing_action_id,
$action
);
}
/**

View File

@@ -25,7 +25,7 @@ abstract class ActionScheduler_Abstract_Schema {
/**
* @var array Names of tables that will be registered by this class.
*/
protected $tables = [];
protected $tables = array();
/**
* Can optionally be used by concrete classes to carry out additional initialization work
@@ -90,10 +90,10 @@ abstract class ActionScheduler_Abstract_Schema {
$plugin_option_name = 'schema-';
switch ( static::class ) {
case 'ActionScheduler_StoreSchema' :
case 'ActionScheduler_StoreSchema':
$plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker';
break;
case 'ActionScheduler_LoggerSchema' :
case 'ActionScheduler_LoggerSchema':
$plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker';
break;
}
@@ -129,7 +129,7 @@ abstract class ActionScheduler_Abstract_Schema {
* @return void
*/
private function update_table( $table ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$definition = $this->get_table_definition( $table );
if ( $definition ) {
$updated = dbDelta( $definition );
@@ -148,7 +148,7 @@ abstract class ActionScheduler_Abstract_Schema {
* table prefix for the current blog
*/
protected function get_full_table_name( $table ) {
return $GLOBALS[ 'wpdb' ]->prefix . $table;
return $GLOBALS['wpdb']->prefix . $table;
}
/**
@@ -159,14 +159,19 @@ abstract class ActionScheduler_Abstract_Schema {
public function tables_exist() {
global $wpdb;
$existing_tables = $wpdb->get_col( 'SHOW TABLES' );
$expected_tables = array_map(
function ( $table_name ) use ( $wpdb ) {
return $wpdb->prefix . $table_name;
},
$this->tables
);
$tables_exist = true;
return count( array_intersect( $existing_tables, $expected_tables ) ) === count( $expected_tables );
foreach ( $this->tables as $table_name ) {
$table_name = $wpdb->prefix . $table_name;
$pattern = str_replace( '_', '\\_', $table_name );
$existing_table = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $pattern ) );
if ( $existing_table !== $table_name ) {
$tables_exist = false;
break;
}
}
return $tables_exist;
}
}

View File

@@ -26,6 +26,8 @@ abstract class ActionScheduler_Lock {
/**
* Set a lock.
*
* To prevent race conditions, implementations should avoid setting the lock if the lock is already held.
*
* @param string $lock_type A string to identify different lock types.
* @return bool
*/

View File

@@ -347,7 +347,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
'hook' => $hook,
'status' => self::STATUS_PENDING,
'per_page' => 1000,
'orderby' => 'action_id',
'orderby' => 'none',
)
);
@@ -372,7 +372,7 @@ abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
'group' => $group,
'status' => self::STATUS_PENDING,
'per_page' => 1000,
'orderby' => 'action_id',
'orderby' => 'none',
)
);