Commit 61dc3f45 authored by Erick Hitter's avatar Erick Hitter

PHPCS fixes

parent 064e7379
......@@ -579,7 +579,9 @@ class Events_Store extends Singleton {
// Create the post, or update an existing entry to run again in the future.
if ( is_int( $update_id ) && $update_id > 0 ) {
$wpdb->update( $this->get_table_name(), $job_post, array( 'ID' => $update_id ) );
$wpdb->update( $this->get_table_name(), $job_post, array(
'ID' => $update_id,
) );
} else {
$job_post['created'] = current_time( 'mysql', true );
......@@ -637,7 +639,9 @@ class Events_Store extends Singleton {
'instance' => mt_rand( 1000000, 999999999 ), // Breaks unique constraint, and can be recreated from entry's remaining data.
);
$success = $wpdb->update( $this->get_table_name(), $updates, array( 'ID' => $job_id ) );
$success = $wpdb->update( $this->get_table_name(), $updates, array(
'ID' => $job_id,
) );
// Delete internal cache.
// Should only be skipped during bulk operations.
......@@ -724,7 +728,9 @@ class Events_Store extends Singleton {
}
if ( $count > 0 ) {
$wpdb->delete( $this->get_table_name(), array( 'status' => self::STATUS_COMPLETED ) );
$wpdb->delete( $this->get_table_name(), array(
'status' => self::STATUS_COMPLETED,
) );
}
}
......
......@@ -96,7 +96,9 @@ class Events extends Singleton {
// That was easy.
if ( ! is_array( $events ) || empty( $events ) ) {
return array( 'events' => null );
return array(
'events' => null,
);
}
// Simplify array format for further processing.
......@@ -104,8 +106,9 @@ class Events extends Singleton {
// Select only those events to run in the next sixty seconds.
// Will include missed events as well.
$current_events = $internal_events = array();
$current_window = strtotime( sprintf( '+%d seconds', JOB_QUEUE_WINDOW_IN_SECONDS ) );
$current_events = array();
$internal_events = array();
$current_window = strtotime( sprintf( '+%d seconds', JOB_QUEUE_WINDOW_IN_SECONDS ) );
foreach ( $events as $event ) {
// Skip events whose time hasn't come.
......@@ -250,12 +253,17 @@ class Events extends Singleton {
public function run_event( $timestamp, $action, $instance, $force = false ) {
// Validate input data.
if ( empty( $timestamp ) || empty( $action ) || empty( $instance ) ) {
return new \WP_Error( 'missing-data', __( 'Invalid or incomplete request data.', 'automattic-cron-control' ), array( 'status' => 400 ) );
return new \WP_Error( 'missing-data', __( 'Invalid or incomplete request data.', 'automattic-cron-control' ), array(
'status' => 400,
) );
}
// Ensure we don't run jobs ahead of time.
if ( ! $force && $timestamp > time() ) {
return new \WP_Error( 'premature', sprintf( __( 'Job with identifier `%1$s` is not scheduled to run yet.', 'automattic-cron-control' ), "$timestamp-$action-$instance" ), array( 'status' => 403 ) );
/* translators: 1: Job identifier */
return new \WP_Error( 'premature', sprintf( __( 'Job with identifier `%1$s` is not scheduled to run yet.', 'automattic-cron-control' ), "$timestamp-$action-$instance" ), array(
'status' => 403,
) );
}
// Find the event to retrieve the full arguments.
......@@ -268,7 +276,10 @@ class Events extends Singleton {
// Nothing to do...
if ( ! is_object( $event ) ) {
return new \WP_Error( 'no-event', sprintf( __( 'Job with identifier `%1$s` could not be found.', 'automattic-cron-control' ), "$timestamp-$action-$instance" ), array( 'status' => 404 ) );
/* translators: 1: Job identifier */
return new \WP_Error( 'no-event', sprintf( __( 'Job with identifier `%1$s` could not be found.', 'automattic-cron-control' ), "$timestamp-$action-$instance" ), array(
'status' => 404,
) );
}
unset( $timestamp, $action, $instance );
......@@ -279,7 +290,10 @@ class Events extends Singleton {
$this->prime_event_action_lock( $event );
if ( ! $this->can_run_event( $event ) ) {
return new \WP_Error( 'no-free-threads', sprintf( __( 'No resources available to run the job with action action `%1$s` and arguments `%2$s`.', 'automattic-cron-control' ), $event->action, maybe_serialize( $event->args ) ), array( 'status' => 429 ) );
/* translators: 1: Event action, 2: Event arguments */
return new \WP_Error( 'no-free-threads', sprintf( __( 'No resources available to run the job with action `%1$s` and arguments `%2$s`.', 'automattic-cron-control' ), $event->action, maybe_serialize( $event->args ) ), array(
'status' => 429,
) );
}
// Free locks should event throw uncatchable error.
......@@ -304,6 +318,7 @@ class Events extends Singleton {
$return = array(
'success' => false,
/* translators: 1: Event action, 2: Event arguments, 3: Throwable error, 4: Line number that raised Throwable error */
'message' => sprintf( __( 'Callback for job with action `%1$s` and arguments `%2$s` raised a Throwable - %3$s in %4$s on line %5$d.', 'automattic-cron-control' ), $event->action, maybe_serialize( $event->args ), $t->getMessage(), $t->getFile(), $t->getLine() ),
);
}
......@@ -321,6 +336,7 @@ class Events extends Singleton {
if ( ! isset( $return ) ) {
$return = array(
'success' => true,
/* translators: 1: Event action, 2: Event arguments */
'message' => sprintf( __( 'Job with action `%1$s` and arguments `%2$s` executed.', 'automattic-cron-control' ), $event->action, maybe_serialize( $event->args ) ),
);
}
......
......@@ -73,11 +73,11 @@ class Lock {
*/
private static function get_key( $lock, $type = 'lock' ) {
switch ( $type ) {
case 'lock' :
case 'lock':
return "a8ccc_lock_{$lock}";
break;
case 'timestamp' :
case 'timestamp':
return "a8ccc_lock_ts_{$lock}";
break;
}
......
......@@ -75,6 +75,7 @@ class Main extends Singleton {
foreach ( $constants as $constant => $expected_value ) {
if ( defined( $constant ) ) {
if ( constant( $constant ) !== $expected_value ) {
/* translators: 1: Plugin name, 2: Constant name */
error_log( sprintf( __( '%1$s: %2$s set to unexpected value; must be corrected for proper behaviour.', 'automattic-cron-control' ), 'Cron Control', $constant ) );
}
} else {
......@@ -89,6 +90,7 @@ class Main extends Singleton {
public function block_direct_cron() {
if ( false !== stripos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) || false !== stripos( $_SERVER['SCRIPT_NAME'], '/wp-cron.php' ) ) {
status_header( 403 );
/* translators: 1: Plugin name */
wp_send_json_error( new \WP_Error( 'forbidden', sprintf( __( 'Normal cron execution is blocked when the %s plugin is active.', 'automattic-cron-control' ), 'Cron Control' ) ), array( 'status' => 400 ) );
}
}
......@@ -115,7 +117,10 @@ class Main extends Singleton {
public function admin_notice() {
?>
<div class="notice notice-error">
<p><?php printf( __( '<strong>%1$s</strong>: To use this plugin, define the constant %2$s.', 'automattic-cron-control' ), 'Cron Control', '<code>WP_CRON_CONTROL_SECRET</code>' ); ?></p>
<p><?php
/* translators: 1: Plugin name, 2: Constant name */
printf( __( '<strong>%1$s</strong>: To use this plugin, define the constant %2$s.', 'automattic-cron-control' ), 'Cron Control', '<code>WP_CRON_CONTROL_SECRET</code>' );
?></p>
</div>
<?php
}
......
......@@ -89,10 +89,13 @@ class REST_API extends Singleton {
if ( 1 === $run_disabled ) {
$message = __( 'Automatic event execution is disabled indefinitely.', 'automattic-cron-control' );
} else {
/* translators: 1: Time automatic execution is disabled until, 2: Unix timestamp */
$message = sprintf( __( 'Automatic event execution is disabled until %1$s UTC (%2$d).', 'automattic-cron-control' ), date_i18n( TIME_FORMAT, $run_disabled ), $run_disabled );
}
return rest_ensure_response( new \WP_Error( 'automatic-execution-disabled', $message, array( 'status' => 403 ) ) );
return rest_ensure_response( new \WP_Error( 'automatic-execution-disabled', $message, array(
'status' => 403,
) ) );
}
// Parse request for details needed to identify the event to execute.
......@@ -118,7 +121,9 @@ class REST_API extends Singleton {
// For now, mimic original plugin's "authentication" method. This needs to be better.
if ( ! isset( $body['secret'] ) || ! hash_equals( \WP_CRON_CONTROL_SECRET, $body['secret'] ) ) {
return new \WP_Error( 'no-secret', __( 'Secret must be specified with all requests', 'automattic-cron-control' ), array( 'status' => 400 ) );
return new \WP_Error( 'no-secret', __( 'Secret must be specified with all requests', 'automattic-cron-control' ), array(
'status' => 400,
) );
}
return true;
......
......@@ -28,7 +28,9 @@ function collapse_events_array( $events, $timestamp = null ) {
if ( is_numeric( $timestamp ) ) {
if ( isset( $events[ $timestamp ] ) ) {
$_events = $events[ $timestamp ];
$events = array( $timestamp => $_events );
$events = array(
$timestamp => $_events,
);
unset( $_events );
} else {
return $collapsed_events;
......
......@@ -53,7 +53,7 @@ const TIME_FORMAT = \Automattic\WP\Cron_Control\TIME_FORMAT;
function stop_the_insanity() {
global $wpdb, $wp_object_cache;
$wpdb->queries = array(); // or define( 'WP_IMPORTING', true );.
$wpdb->queries = array(); // or define WP_IMPORTING
if ( ! is_object( $wp_object_cache ) ) {
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment