*/
class Query implements \Iterator {
- private $limit = 500;
+ private $chunk_size;
private $query = '';
private $global_index = 0;
* </code>
*
* @param string $query The query as a string. It shouldn't include any LIMIT clauses
- * @param number $limit How many rows to retrieve at once; default value is 500 (optional)
+ * @param number $chunk_size How many rows to retrieve at once; default value is 500 (optional)
*/
- public function __construct( $query, $limit = 500 ) {
+ public function __construct( $query, $chunk_size = 500 ) {
$this->query = $query;
- $this->limit = $limit;
+ $this->chunk_size = $chunk_size;
$this->db = $GLOBALS['wpdb'];
}
private function load_items_from_db() {
- $query = $this->query . sprintf( ' LIMIT %d OFFSET %d', $this->limit, $this->offset );
+ $query = $this->query . sprintf( ' LIMIT %d OFFSET %d', $this->chunk_size, $this->offset );
$this->results = $this->db->get_results( $query );
if ( !$this->results ) {
}
}
- $this->offset += $this->limit;
+ $this->offset += $this->chunk_size;
return true;
}
'fields' => array( '*' ),
'where' => array(),
'table' => null,
+ 'chunk_size' => 500
);
$table = $args['table'];
$args = array_merge( $defaults, $args );
$where_sql = $conditions? " WHERE $conditions" : '';
$query = "SELECT $fields FROM $table $where_sql";
- $limit = isset( $args['limit'] ) ? $args['limit'] : 500;
-
- parent::__construct( $query, $limit );
+ parent::__construct( $query, $args['chunk_size'] );
}
private static function build_fields( $fields ) {
'table' => $table,
'fields' => array( $primary_key, $col ),
'where' => $col . ' LIKE "%' . like_escape( esc_sql( $old ) ) . '%"',
- 'limit' => 1000
+ 'chunk_size' => 1000
);
$it = new \WP_CLI\Iterators\Table( $args );