From: scribu Date: Sun, 14 Apr 2013 23:37:32 +0000 (+0300) Subject: make query string mandatory first parameter in Iterators\Query constructor X-Git-Tag: v0.10.0~114 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3ab5140e621dba66defc878a9cbdc1f92cfd57d9;p=wvm%2Fwvm.git make query string mandatory first parameter in Iterators\Query constructor see #390 --- diff --git a/php/WP_CLI/Iterators/Query.php b/php/WP_CLI/Iterators/Query.php index 19545862..523e300d 100644 --- a/php/WP_CLI/Iterators/Query.php +++ b/php/WP_CLI/Iterators/Query.php @@ -24,24 +24,19 @@ class Query implements \Iterator { * * This will loop over all users, but will retrieve them 100 by 100: * - * foreach( new Iterators\Query( array( 'query' => 'SELECT * FROM users', 'limit' => 100 ) ) as $user ) { + * foreach( new Iterators\Query( 'SELECT * FROM users', 100 ) as $user ) { * tickle( $user ); * } * * - * - * @param array $args Supported arguments: - * query – the query as a string. It shouldn't include any LIMIT clauses - * limit – (optional) how many rows to retrieve at once, default value is 500 + * @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) */ - function __construct( $args = array() ) { + public function __construct( $query, $limit = 500 ) { + $this->query = $query; + $this->limit = $limit; + $this->db = $GLOBALS['wpdb']; - foreach( $args as $key => $value ) { - $this->$key = $value; - } - if ( !$this->query ) { - throw new InvalidArgumentException( 'Missing query argument.' ); - } } function load_items_from_db() { diff --git a/php/WP_CLI/Iterators/Table.php b/php/WP_CLI/Iterators/Table.php index eade2ca1..825bf265 100644 --- a/php/WP_CLI/Iterators/Table.php +++ b/php/WP_CLI/Iterators/Table.php @@ -52,11 +52,10 @@ class Table extends Query { $conditions = self::build_where_conditions( $args['where'] ); $where_sql = $conditions? " WHERE $conditions" : ''; $query = "SELECT $fields FROM $table $where_sql"; - $parent_args = compact( 'query' ); - if ( isset( $args['limit'] ) ) { - $parent_args['limit'] = $args['limit']; - } - parent::__construct( $parent_args ); + + $limit = isset( $args['limit'] ) ? $args['limit'] : 500; + + parent::__construct( $query, $limit ); } static function build_fields( $fields ) {