From: scribu Date: Mon, 27 May 2013 20:37:22 +0000 (+0300) Subject: TableIterator: rename 'limit' parameter to 'chunk_size', so that it's not confused... X-Git-Tag: v0.10.0~34 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=85d4d0c8362997ebe6f552408f82f108921c91f8;p=wvm%2Fwvm.git TableIterator: rename 'limit' parameter to 'chunk_size', so that it's not confused with SQL LIMIT see https://github.com/wp-cli/wp-cli/commit/b1bd56dd5e2bdc106603c1034affc6a953b5e6b1#commitcomment-3296894 --- diff --git a/php/WP_CLI/Iterators/Query.php b/php/WP_CLI/Iterators/Query.php index 1577e99a..016961a0 100644 --- a/php/WP_CLI/Iterators/Query.php +++ b/php/WP_CLI/Iterators/Query.php @@ -9,7 +9,7 @@ namespace WP_CLI\Iterators; */ class Query implements \Iterator { - private $limit = 500; + private $chunk_size; private $query = ''; private $global_index = 0; @@ -30,17 +30,17 @@ class Query implements \Iterator { * * * @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 ) { @@ -51,7 +51,7 @@ class Query implements \Iterator { } } - $this->offset += $this->limit; + $this->offset += $this->chunk_size; return true; } diff --git a/php/WP_CLI/Iterators/Table.php b/php/WP_CLI/Iterators/Table.php index 450301ae..6e05cf9e 100644 --- a/php/WP_CLI/Iterators/Table.php +++ b/php/WP_CLI/Iterators/Table.php @@ -44,6 +44,7 @@ class Table extends Query { 'fields' => array( '*' ), 'where' => array(), 'table' => null, + 'chunk_size' => 500 ); $table = $args['table']; $args = array_merge( $defaults, $args ); @@ -53,9 +54,7 @@ class Table extends Query { $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 ) { diff --git a/php/commands/search-replace.php b/php/commands/search-replace.php index a08af875..e6bcd5f9 100644 --- a/php/commands/search-replace.php +++ b/php/commands/search-replace.php @@ -67,7 +67,7 @@ class Search_Replace_Command extends WP_CLI_Command { '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 );