batch_limit}"; $wpdb->query( $wpdb->prepare( $sql, array( $this->session[ $item ] ) ) ); return true; } /** * Count items left to process for the current blog. * * @return int */ protected function count_items_to_process() { global $wpdb; // Store the highest known meta_id at the time we begin processing. if ( empty( $this->session[ $this->blog_prefix ] ) ) { $sql = "SELECT meta_id FROM {$this->blog_prefix}postmeta WHERE meta_key = 'amazonS3_cache' ORDER BY meta_id DESC LIMIT 0, 1;"; $last = $wpdb->get_var( $sql ); $this->session[ $this->blog_prefix ] = $last; } return count( $this->get_items_to_process( $this->blog_prefix, 0 ) ); } /** * Get array of items that each represent one chunk to be cleared. * * @param string $prefix Table prefix for blog. * @param int $limit * @param bool|mixed $offset * * @return array */ protected function get_items_to_process( $prefix, $limit, $offset = false ) { $count = $this->get_real_count( $prefix ); if ( 0 === $count ) { return array(); } $chunks = ceil( $count / $this->batch_limit ); return array_fill( 0, $chunks, $prefix ); } /** * Return the real number of remaining amazonS3_cache items to clear out. * * @param string $prefix * * @return int */ private function get_real_count( $prefix ) { global $wpdb; $sql = "SELECT count(meta_id) FROM {$prefix}postmeta WHERE meta_key = 'amazonS3_cache' AND meta_id <= %d"; $count = $wpdb->get_var( $wpdb->prepare( $sql, $this->session[ $prefix ] ) ); return (int) $count; } }