Commit 74582a3c authored by Erick Hitter's avatar Erick Hitter
Browse files

Review feedback: begin splitting `get_job()` into discrete functions

The `WP_Query` approach is excessive
parent 3ea320e7
......@@ -348,6 +348,32 @@ class Events_Store extends Singleton {
return $job;
}
/**
* Retrieve a single event by its ID
*
* @param int $jid Job ID
* @return object|false
*/
public function get_job_by_id( $jid ) {
global $wpdb;
// Validate ID
$jid = absint( $jid );
if ( ! $jid ) {
return false;
}
$job = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->get_table_name()} WHERE ID = %d AND status = %s LIMIT 1", $jid, self::STATUS_PENDING ) );
if ( is_object( $job ) && ! is_wp_error( $job ) ) {
$job = $this->format_job( $job );
} else {
$job = false;
}
return $job;
}
/**
* Get ID for given event details
*
......
......@@ -108,6 +108,16 @@ function get_event_by_attributes( $attributes ) {
return Events_Store::instance()->get_job( $attributes );
}
/**
* Retrieve a single event by its ID
*
* @param int $jid Job ID
* @return object|false
*/
function get_event_by_id( $jid ) {
return Events_Store::instance()->get_job_by_id( $jid );
}
/**
* Count events with a given status
*
......
......@@ -111,7 +111,7 @@ class Events extends \WP_CLI_Command {
}
// Retrieve information needed to execute event
$event = \Automattic\WP\Cron_Control\get_event_by_attributes( array( 'ID' => $args[0], ) );
$event = \Automattic\WP\Cron_Control\get_event_by_id( $args[0] );
if ( ! is_object( $event ) ) {
\WP_CLI::error( sprintf( __( 'Failed to locate event %d. Please confirm that the entry exists and that the ID is that of an event.', 'automattic-cron-control' ), $args[0] ) );
......@@ -363,7 +363,7 @@ class Events extends \WP_CLI_Command {
\WP_CLI::line( __( 'Locating event...', 'automattic-cron-control' ) . "\n" );
// Look up full event object
$event = \Automattic\WP\Cron_Control\get_event_by_attributes( array( 'ID' => $jid, ) );
$event = \Automattic\WP\Cron_Control\get_event_by_id( $jid );
if ( is_object( $event ) ) {
// Warning about Internal Events
......
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