Revert "Background processing; multisite should process current blog queue only"

This reverts commit c950dcc6e3.
This commit is contained in:
Mike Jolley 2017-12-08 16:46:25 +00:00
parent 9491db496c
commit 05eb303a6f
1 changed files with 30 additions and 23 deletions

View File

@ -184,18 +184,22 @@ abstract class WP_Background_Process extends WP_Async_Request {
protected function is_queue_empty() { protected function is_queue_empty() {
global $wpdb; global $wpdb;
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; $table = $wpdb->options;
$column = 'option_name';
if ( is_multisite() ) { if ( is_multisite() ) {
$count = $wpdb->get_var( $wpdb->prepare( " $table = $wpdb->sitemeta;
SELECT COUNT(*) FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s AND site_id = %d $column = 'meta_key';
", $key, get_current_blog_id() ) );
} else {
$count = $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE %s
", $key ) );
} }
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$count = $wpdb->get_var( $wpdb->prepare( "
SELECT COUNT(*)
FROM {$table}
WHERE {$column} LIKE %s
", $key ) );
return ( $count > 0 ) ? false : true; return ( $count > 0 ) ? false : true;
} }
@ -244,32 +248,35 @@ abstract class WP_Background_Process extends WP_Async_Request {
} }
/** /**
* Get batch. * Get batch
* *
* @return stdClass Return the first batch from the queue * @return stdClass Return the first batch from the queue
*/ */
protected function get_batch() { protected function get_batch() {
global $wpdb; global $wpdb;
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; $table = $wpdb->options;
$column = 'option_name';
$key_column = 'option_id';
$value_column = 'option_value';
if ( is_multisite() ) { if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
$key_column = 'meta_id';
$value_column = 'meta_value'; $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 ) );
} }
$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 ) );
$batch = new stdClass(); $batch = new stdClass();
$batch->key = $query->$value_column; $batch->key = $query->$value_column;
$batch->data = maybe_unserialize( $query->$value_column ); $batch->data = maybe_unserialize( $query->$value_column );