OSDN Git Service

TableIterator: rename 'limit' parameter to 'chunk_size', so that it's not confused...
authorscribu <mail@scribu.net>
Mon, 27 May 2013 20:37:22 +0000 (23:37 +0300)
committerscribu <mail@scribu.net>
Mon, 27 May 2013 20:37:23 +0000 (23:37 +0300)
see https://github.com/wp-cli/wp-cli/commit/b1bd56dd5e2bdc106603c1034affc6a953b5e6b1#commitcomment-3296894

php/WP_CLI/Iterators/Query.php
php/WP_CLI/Iterators/Table.php
php/commands/search-replace.php

index 1577e99..016961a 100644 (file)
@@ -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 {
         * </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 ) {
@@ -51,7 +51,7 @@ class Query implements \Iterator {
                        }
                }
 
-               $this->offset += $this->limit;
+               $this->offset += $this->chunk_size;
                return true;
        }
 
index 450301a..6e05cf9 100644 (file)
@@ -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 ) {
index a08af87..e6bcd5f 100644 (file)
@@ -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 );