Add column alias support in BatchRowIterator
authorStephane Bisson <sbisson@wikimedia.org>
Fri, 3 Jun 2016 13:05:10 +0000 (09:05 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Fri, 3 Jun 2016 13:05:10 +0000 (09:05 -0400)
Used by Echo/maintenance/backfillReadBundles

Bug: T136368
Change-Id: Ia8f8aa718713798a81392b5e9751c5c18ab81720

includes/utils/BatchRowIterator.php

index 3bd3a4c..419ee47 100644 (file)
@@ -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;
        }
@@ -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 = [];