Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WP Plugins
Cron-Control
Commits
74582a3c
Commit
74582a3c
authored
Mar 17, 2017
by
Erick Hitter
Browse files
Review feedback: begin splitting `get_job()` into discrete functions
The `WP_Query` approach is excessive
parent
3ea320e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
includes/class-events-store.php
View file @
74582a3c
...
...
@@ -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
*
...
...
includes/functions.php
View file @
74582a3c
...
...
@@ -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
*
...
...
includes/wp-cli/class-events.php
View file @
74582a3c
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment