Background processing; multisite should process current blog queue only

#17915
This commit is contained in:
Mike Jolley 2017-12-07 13:01:05 +00:00
parent 0ca68ff51e
commit c950dcc6e3
1 changed files with 26 additions and 33 deletions

View File

@ -184,21 +184,17 @@ abstract class WP_Background_Process extends WP_Async_Request {
protected function is_queue_empty() {
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$count = $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(*)
FROM {$table}
WHERE {$column} LIKE %s
", $key ) );
if ( is_multisite() ) {
$count = $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(*) FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s AND site_id = %d
", $key, get_current_blog_id() ) );
} else {
$count = $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE %s
", $key ) );
}
return ( $count > 0 ) ? false : true;
}
@ -248,34 +244,31 @@ abstract class WP_Background_Process extends WP_Async_Request {
}
/**
* Get batch
* Get batch.
*
* @return stdClass Return the first batch from the queue
*/
protected function get_batch() {
global $wpdb;
$table = $wpdb->options;
$column = 'option_name';
$key_column = 'option_id';
$value_column = 'option_value';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
$key_column = 'meta_id';
$value_column = 'meta_value';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$query = $wpdb->get_row( $wpdb->prepare( "
SELECT *
FROM {$table}
WHERE {$column} LIKE %s
ORDER BY {$key_column} ASC
LIMIT 1
", $key ) );
if ( is_multisite() ) {
$value_column = 'meta_value';
$query = $wpdb->get_row( $wpdb->prepare( "
SELECT * FROM {$wpdb->sitemeta}
WHERE meta_key LIKE %s
AND site_id = %d
ORDER BY meta_id ASC LIMIT 1
", $key, get_current_blog_id() ) );
} else {
$value_column = 'option_value';
$query = $wpdb->get_row( $wpdb->prepare( "
SELECT * FROM {$wpdb->options}
WHERE option_name LIKE %s
ORDER BY option_id ASC LIMIT 1
", $key ) );
}
$batch = new stdClass();
$batch->key = $query->$column;