Assignment in loop conditions suck
authorSam Reed <reedy@users.mediawiki.org>
Wed, 13 Oct 2010 22:34:25 +0000 (22:34 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Wed, 13 Oct 2010 22:34:25 +0000 (22:34 +0000)
while ( $row = $dbw->fetchObject( $res ) ) { to foreach ( $res as $row ) in maintenance stuffs (more to come)

maintenance/convertLinks.php
maintenance/purgeOldText.inc
maintenance/rollbackEdits.php
maintenance/storage/checkStorage.php
maintenance/storage/compressOld.inc
maintenance/storage/moveToExternal.php
maintenance/storage/resolveStubs.php
maintenance/upgrade1_5.php
maintenance/userDupes.inc
maintenance/userOptions.inc

index a128bca..f13681b 100644 (file)
@@ -113,7 +113,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                        $res = $dbw->query( "SELECT cur_namespace,cur_title,cur_id FROM $cur" );
                        $ids = array();
 
-                       while ( $row = $dbw->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $title = $row->cur_title;
                                if ( $row->cur_namespace ) {
                                        $title = $wgContLang->getNsText( $row->cur_namespace ) . ":$title";
@@ -154,7 +154,7 @@ This gives a huge speed improvement for very large links tables which are MyISAM
                                }
        
                                $tuplesAdded = 0; # no tuples added to INSERT yet
-                               while ( $row = $dbw->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $fromTitle = $row->l_from;
                                        if ( array_key_exists( $fromTitle, $ids ) ) { # valid title
                                                $from = $ids[$fromTitle];
index b88ad72..58b3fa1 100644 (file)
@@ -21,7 +21,7 @@ function PurgeRedundantText( $delete = false ) {
        # Get "active" text records from the revisions table
        echo( "Searching for active text records in revisions table..." );
        $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
-       while ( $row = $dbw->fetchObject( $res ) ) {
+       foreach ( $res as $row ) {
                $cur[] = $row->rev_text_id;
        }
        echo( "done.\n" );
@@ -29,7 +29,7 @@ function PurgeRedundantText( $delete = false ) {
        # Get "active" text records from the archive table
        echo( "Searching for active text records in archive table..." );
        $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
-       while ( $row = $dbw->fetchObject( $res ) ) {
+       foreach ( $res as $row ) { {
                $cur[] = $row->ar_text_id;
        }
        echo( "done.\n" );
@@ -39,7 +39,7 @@ function PurgeRedundantText( $delete = false ) {
        $set = implode( ', ', $cur );
        $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
        $old = array();
-       while ( $row = $dbw->fetchObject( $res ) ) {
+       foreach ( $res as $row ) { {
                $old[] = $row->old_id;
        }
        echo( "done.\n" );
index c7f6aa7..2be0566 100644 (file)
@@ -86,7 +86,7 @@ class RollbackEdits extends Maintenance {
                        array( 'page_latest = rev_id', 'rev_user_text' => $user ),
                        __METHOD__
                );
-               while ( $row = $dbr->fetchObject( $results ) ) {
+               foreach ( $results as $row ) {
                        $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
                }
                return $titles;
index 15fb68f..d991551 100644 (file)
@@ -70,7 +70,7 @@ class CheckStorage {
                        $dbr->ping();
                        $res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ),
                                array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), $fname );
-                       while ( $row = $dbr->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $this->oldIdMap[$row->rev_id] = $row->rev_text_id;
                        }
                        $dbr->freeResult( $res );
@@ -85,7 +85,7 @@ class CheckStorage {
                        $objectRevs = array();
                        $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ),
                                'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', $fname );
-                       while ( $row = $dbr->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $flags = $row->old_flags;
                                $id = $row->old_id;
 
@@ -139,7 +139,7 @@ class CheckStorage {
                        if ( count( $externalRevs ) ) {
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
                                        array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $urlParts = explode( '://', $row->old_text, 2 );
                                        if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
                                                $this->error( 'restore text', "Error: invalid URL \"{$row->old_text}\"", $row->old_id );
@@ -177,7 +177,7 @@ class CheckStorage {
                                        $res = $extDb->select( $blobsTable,
                                                array( 'blob_id' ),
                                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
-                                       while ( $row = $extDb->fetchObject( $res ) ) {
+                                       foreach ( $res as $row ) {
                                                unset( $xBlobIds[$row->blob_id] );
                                        }
                                        $extDb->freeResult( $res );
@@ -196,7 +196,7 @@ class CheckStorage {
                                $headerLength = 300;
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
                                        array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $oldId = $row->old_id;
                                        $matches = array();
                                        if ( !preg_match( '/^O:(\d+):"(\w+)"/', $row->header, $matches ) ) {
@@ -247,7 +247,7 @@ class CheckStorage {
                                $headerLength = 300;
                                $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
                                        array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), $fname );
-                               while ( $row = $dbr->fetchObject( $res ) ) {
+                               foreach ( $res as $row ) {
                                        $flags = explode( ',', $row->old_flags );
                                        if ( in_array( 'external', $flags ) ) {
                                                // Concat blob is in external storage?
@@ -355,7 +355,7 @@ class CheckStorage {
                        $res = $extDb->select( $blobsTable,
                                array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
                                array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
-                       while ( $row = $extDb->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
                                        $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
                                                $oldIds[$row->blob_id] );
index e5d5fe9..4a97505 100644 (file)
@@ -18,7 +18,7 @@ function compressOldPages( $start = 0, $extdb = '' ) {
                        break;
                }
                $last = $start;
-               while( $row = $dbw->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        # print "  {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
                        compressPage( $row, $extdb );
                        $last = $row->old_id;
@@ -169,7 +169,7 @@ function compressWithConcat( $startId, $maxChunkSize, $beginDate,
                        $revLoadOptions
                );
                $revs = array();
-               while ( $revRow = $dbw->fetchObject( $revRes ) ) {
+               foreach ( $res as $row ) {
                        $revs[] = $revRow;
                }
 
index 907254b..80d8646 100644 (file)
@@ -59,7 +59,7 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) {
                                "old_id BETWEEN $blockStart AND $blockEnd",
                                'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
                        ), $fname );
-               while ( $row = $dbr->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        # Resolve stubs
                        $text = $row->old_text;
                        $id = $row->old_id;
index ff1b010..cd8ef34 100644 (file)
@@ -38,7 +38,7 @@ function resolveStubs() {
                        "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
                        'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
                        $fname );
-               while ( $row = $dbr->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        resolveStub( $row->old_id, $row->old_text, $row->old_flags );
                }               
        }
index e0e0214..8803910 100644 (file)
@@ -344,7 +344,7 @@ class FiveUpgrade extends Maintenance {
                        __METHOD__ );
 
                $add = array();
-               while ( $row = $this->dbr->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {
                        $copy = array();
                        foreach ( $fields as $field => $source ) {
                                if ( $source === MW_UPGRADE_COPY ) {
@@ -455,7 +455,7 @@ class FiveUpgrade extends Maintenance {
                        FROM $cur
                        ORDER BY cur_id", __METHOD__ );
                $add = array();
-               while ( $row = $this->dbr->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {
                        $add[] = array(
                                'old_namespace'  => $row->cur_namespace,
                                'old_title'      => $row->cur_title,
@@ -488,7 +488,7 @@ class FiveUpgrade extends Maintenance {
                        __METHOD__ );
 
                $add = array();
-               while ( $row = $this->dbr->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {
                        $add[] = array(
                                'rev_id'         =>              $row->old_id,
                                'rev_page'       =>              $row->cur_id,
@@ -516,7 +516,7 @@ class FiveUpgrade extends Maintenance {
                        WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}
                        ORDER BY cur_id", __METHOD__ );
                $add = array();
-               while ( $row = $this->dbr->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {
                        $add[] = array(
                                'page_id'           =>              $row->cur_id,
                                'page_namespace'    =>              $row->cur_namespace,
@@ -578,7 +578,7 @@ CREATE TABLE $pagelinks (
                                FROM $links, $cur
                                WHERE l_to=cur_id", __METHOD__ );
                        $add = array();
-                       while ( $row = $this->dbr->fetchObject( $result ) ) {
+                       foreach ( $result as $row ) {
                                $add[] = array(
                                        'pl_from'      =>              $row->l_from,
                                        'pl_namespace' =>              $row->cur_namespace,
@@ -598,7 +598,7 @@ CREATE TABLE $pagelinks (
                                "SELECT bl_from, bl_to FROM $brokenlinks",
                                __METHOD__ );
                        $add = array();
-                       while ( $row = $this->dbr->fetchObject( $result ) ) {
+                       foreach ( $result as $row ) {
                                $pagename = $this->conv( $row->bl_to );
                                $title = Title::newFromText( $pagename );
                                if ( is_null( $title ) ) {
@@ -905,7 +905,7 @@ END;
                        __METHOD__ );
 
                $add = array();
-               while ( $row = $this->dbr->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {
                        $add[] = array(
                                'wl_user'      =>                          $row->wl_user,
                                'wl_namespace' => MWNamespace::getSubject( $row->wl_namespace ),
@@ -1214,7 +1214,7 @@ END
                echo "Found $n titles with duplicate entries.\n";
                if ( $n > 0 ) {
                        echo "Correcting...\n";
-                       while ( $row = $dbw->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $ns = intval( $row->cur_namespace );
                                $title = $dbw->addQuotes( $row->cur_title );
 
index 668d0bc..9dcd181 100644 (file)
@@ -190,7 +190,7 @@ class UserDupes {
                          HAVING n > 1", $fname );
 
                $list = array();
-               while ( $row = $this->db->fetchObject( $result ) ) {
+               foreach ( $res as $row ) {
                        $list[] = $row->user_name;
                }
                return $list;
@@ -215,7 +215,7 @@ class UserDupes {
                $firstId  = $firstRow->user_id;
                wfOut( "Record that will be used for '$name' is user_id=$firstId\n" );
 
-               while ( $row = $this->db->fetchObject( $result ) ) {
+               foreach ( $result as $row ) {           
                        $dupeId = $row->user_id;
                        wfOut( "... dupe id $dupeId: " );
                        $edits = $this->editCount( $dupeId );
index bfc8e8e..88dfc3d 100644 (file)
@@ -111,7 +111,7 @@ class userOptions {
                        __METHOD__
                        );
 
-               while ( $id = $dbr->fetchObject( $result ) ) {
+               foreach ( $result as $id ) {
 
                        $user = User::newFromId( $id->user_id );
 
@@ -161,7 +161,7 @@ class userOptions {
                        __METHOD__
                        );
 
-               while ( $id = $dbr->fetchObject( $result ) ) {
+               foreach ( $result as $id ) {
 
                        $user = User::newFromId( $id->user_id );