X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=blobdiff_plain;f=includes%2Futils%2FBatchRowIterator.php;h=9fc243120a644a42b05f5c422166caa5ae29f660;hb=2e7f4e48735b0e916336d9166cb1ab1756e0fa9f;hp=3bd3a4c3ec2e4c3efcdd37152495d88a852f83fd;hpb=75185ec3da61b5efbb9291c22238c731e1ea0942;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/utils/BatchRowIterator.php b/includes/utils/BatchRowIterator.php index 3bd3a4c3ec..9fc243120a 100644 --- a/includes/utils/BatchRowIterator.php +++ b/includes/utils/BatchRowIterator.php @@ -31,7 +31,7 @@ class BatchRowIterator implements RecursiveIterator { protected $db; /** - * @var string $table The name of the table to read from + * @var string|array $table The name or names of the table to read from */ protected $table; @@ -79,7 +79,7 @@ class BatchRowIterator implements RecursiveIterator { /** * @param IDatabase $db The database to read from - * @param string $table The name of the table to read from + * @param string|array $table The name or names of the table to read from * @param string|array $primaryKey The name or names of the primary key columns * @param integer $batchSize The number of rows to fetch per iteration * @throws MWException @@ -136,8 +136,9 @@ class BatchRowIterator implements RecursiveIterator { */ public function extractPrimaryKeys( $row ) { $pk = []; - foreach ( $this->primaryKey as $column ) { - $pk[$column] = $row->$column; + foreach ( $this->primaryKey as $alias => $column ) { + $name = is_numeric( $alias ) ? $column : $alias; + $pk[$name] = $row->{$name}; } return $pk; } @@ -216,7 +217,7 @@ class BatchRowIterator implements RecursiveIterator { * `=` conditions while the final key uses a `>` condition * * Example output: - * array( '( foo = 42 AND bar > 7 ) OR ( foo > 42 )' ) + * [ '( foo = 42 AND bar > 7 ) OR ( foo > 42 )' ] * * @return array The SQL conditions necessary to select the next set * of rows in the batched query @@ -228,8 +229,9 @@ class BatchRowIterator implements RecursiveIterator { $maxRow = end( $this->current ); $maximumValues = []; - foreach ( $this->primaryKey as $column ) { - $maximumValues[$column] = $this->db->addQuotes( $maxRow->$column ); + foreach ( $this->primaryKey as $alias => $column ) { + $name = is_numeric( $alias ) ? $column : $alias; + $maximumValues[$column] = $this->db->addQuotes( $maxRow->{$name} ); } $pkConditions = [];