Normalize the code style of some ResultWrapper iteration loops
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 10 Jul 2019 22:06:05 +0000 (15:06 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 10 Jul 2019 22:20:17 +0000 (22:20 +0000)
Change-Id: Iced52ae65d31d1ca0cd2c64ebc9ab56b2aef9617

includes/CategoryFinder.php
maintenance/rebuildrecentchanges.php
maintenance/storage/orphanStats.php

index 7446b59..720abc3 100644 (file)
@@ -213,14 +213,14 @@ class CategoryFinder {
                        /* WHERE  */ [ 'cl_from' => $this->next ],
                        __METHOD__ . '-1'
                );
-               foreach ( $res as $o ) {
-                       $k = $o->cl_to;
+               foreach ( $res as $row ) {
+                       $k = $row->cl_to;
 
                        # Update parent tree
-                       if ( !isset( $this->parents[$o->cl_from] ) ) {
-                               $this->parents[$o->cl_from] = [];
+                       if ( !isset( $this->parents[$row->cl_from] ) ) {
+                               $this->parents[$row->cl_from] = [];
                        }
-                       $this->parents[$o->cl_from][$k] = $o;
+                       $this->parents[$row->cl_from][$k] = $row;
 
                        # Ignore those we already have
                        if ( in_array( $k, $this->deadend ) ) {
@@ -245,9 +245,9 @@ class CategoryFinder {
                                /* WHERE  */ [ 'page_namespace' => NS_CATEGORY, 'page_title' => $layer ],
                                __METHOD__ . '-2'
                        );
-                       foreach ( $res as $o ) {
-                               $id = $o->page_id;
-                               $name = $o->page_title;
+                       foreach ( $res as $row ) {
+                               $id = $row->page_id;
+                               $name = $row->page_title;
                                $this->name2id[$name] = $id;
                                $this->next[] = $id;
                                unset( $layer[$name] );
index 4e92653..35af15c 100644 (file)
@@ -80,6 +80,8 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 1: Insert `recentchanges` entries for page revisions.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass1( ILBFactory $lbFactory ) {
                $dbw = $this->getDB( DB_MASTER );
@@ -177,6 +179,8 @@ class RebuildRecentchanges extends Maintenance {
        /**
         * Rebuild pass 2: Enhance entries for page revisions with references to the previous revision
         * (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len).
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass2( ILBFactory $lbFactory ) {
                $dbw = $this->getDB( DB_MASTER );
@@ -199,25 +203,25 @@ class RebuildRecentchanges extends Maintenance {
                $lastOldId = 0;
                $lastSize = null;
                $updated = 0;
-               foreach ( $res as $obj ) {
+               foreach ( $res as $row ) {
                        $new = 0;
 
-                       if ( $obj->rc_cur_id != $lastCurId ) {
+                       if ( $row->rc_cur_id != $lastCurId ) {
                                # Switch! Look up the previous last edit, if any
-                               $lastCurId = intval( $obj->rc_cur_id );
-                               $emit = $obj->rc_timestamp;
+                               $lastCurId = intval( $row->rc_cur_id );
+                               $emit = $row->rc_timestamp;
 
-                               $row = $dbw->selectRow(
+                               $revRow = $dbw->selectRow(
                                        'revision',
                                        [ 'rev_id', 'rev_len' ],
                                        [ 'rev_page' => $lastCurId, "rev_timestamp < " . $dbw->addQuotes( $emit ) ],
                                        __METHOD__,
                                        [ 'ORDER BY' => 'rev_timestamp DESC' ]
                                );
-                               if ( $row ) {
-                                       $lastOldId = intval( $row->rev_id );
+                               if ( $revRow ) {
+                                       $lastOldId = intval( $revRow->rev_id );
                                        # Grab the last text size if available
-                                       $lastSize = !is_null( $row->rev_len ) ? intval( $row->rev_len ) : null;
+                                       $lastSize = !is_null( $revRow->rev_len ) ? intval( $revRow->rev_len ) : null;
                                } else {
                                        # No previous edit
                                        $lastOldId = 0;
@@ -233,7 +237,7 @@ class RebuildRecentchanges extends Maintenance {
                                $size = (int)$dbw->selectField(
                                        'revision',
                                        'rev_len',
-                                       [ 'rev_id' => $obj->rc_this_oldid ],
+                                       [ 'rev_id' => $row->rc_this_oldid ],
                                        __METHOD__
                                );
 
@@ -249,13 +253,13 @@ class RebuildRecentchanges extends Maintenance {
                                        ],
                                        [
                                                'rc_cur_id' => $lastCurId,
-                                               'rc_this_oldid' => $obj->rc_this_oldid,
-                                               'rc_timestamp' => $obj->rc_timestamp // index usage
+                                               'rc_this_oldid' => $row->rc_this_oldid,
+                                               'rc_timestamp' => $row->rc_timestamp // index usage
                                        ],
                                        __METHOD__
                                );
 
-                               $lastOldId = intval( $obj->rc_this_oldid );
+                               $lastOldId = intval( $row->rc_this_oldid );
                                $lastSize = $size;
 
                                if ( ( ++$updated % $this->getBatchSize() ) == 0 ) {
@@ -267,6 +271,8 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 3: Insert `recentchanges` entries for action logs.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass3( ILBFactory $lbFactory ) {
                global $wgLogRestrictions, $wgFilterLogTypes;
@@ -347,6 +353,8 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 4: Mark bot and autopatrolled entries.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass4( ILBFactory $lbFactory ) {
                global $wgUseRCPatrol, $wgMiserMode;
@@ -376,8 +384,8 @@ class RebuildRecentchanges extends Maintenance {
                        );
 
                        $botusers = [];
-                       foreach ( $res as $obj ) {
-                               $botusers[] = User::newFromRow( $obj );
+                       foreach ( $res as $row ) {
+                               $botusers[] = User::newFromRow( $row );
                        }
 
                        # Fill in the rc_bot field
@@ -428,8 +436,8 @@ class RebuildRecentchanges extends Maintenance {
                                [ 'user_groups' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
                        );
 
-                       foreach ( $res as $obj ) {
-                               $patrolusers[] = User::newFromRow( $obj );
+                       foreach ( $res as $row ) {
+                               $patrolusers[] = User::newFromRow( $row );
                        }
 
                        # Fill in the rc_patrolled field
@@ -453,8 +461,10 @@ class RebuildRecentchanges extends Maintenance {
        }
 
        /**
-        * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry
-        * for a single action (upload only, at the moment, but potentially also move, protect, ...).
+        * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log
+        * entry for a single action (upload only, at the moment, but potentially move, protect, ...).
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass5( ILBFactory $lbFactory ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -475,9 +485,9 @@ class RebuildRecentchanges extends Maintenance {
                );
 
                $updates = 0;
-               foreach ( $res as $obj ) {
-                       $rev_id = $obj->ls_value;
-                       $log_id = $obj->ls_log_id;
+               foreach ( $res as $row ) {
+                       $rev_id = $row->ls_value;
+                       $log_id = $row->ls_log_id;
 
                        // Mark the logging row as having an associated rev id
                        $dbw->update(
index 219b47c..3866be7 100644 (file)
@@ -57,12 +57,12 @@ class OrphanStats extends Maintenance {
                $hashes = [];
                $maxSize = 0;
 
-               foreach ( $res as $boRow ) {
-                       $extDB = $this->getDB( $boRow->bo_cluster );
+               foreach ( $res as $row ) {
+                       $extDB = $this->getDB( $row->bo_cluster );
                        $blobRow = $extDB->selectRow(
                                'blobs',
                                '*',
-                               [ 'blob_id' => $boRow->bo_blob_id ],
+                               [ 'blob_id' => $row->bo_blob_id ],
                                __METHOD__
                        );