From f018c8135071c3f8bd9cf891acc0588222191372 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Wed, 13 Oct 2010 22:34:25 +0000 Subject: [PATCH] Assignment in loop conditions suck while ( $row = $dbw->fetchObject( $res ) ) { to foreach ( $res as $row ) in maintenance stuffs (more to come) --- maintenance/convertLinks.php | 4 ++-- maintenance/purgeOldText.inc | 6 +++--- maintenance/rollbackEdits.php | 2 +- maintenance/storage/checkStorage.php | 14 +++++++------- maintenance/storage/compressOld.inc | 4 ++-- maintenance/storage/moveToExternal.php | 2 +- maintenance/storage/resolveStubs.php | 2 +- maintenance/upgrade1_5.php | 16 ++++++++-------- maintenance/userDupes.inc | 4 ++-- maintenance/userOptions.inc | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php index a128bca025..f13681bf48 100644 --- a/maintenance/convertLinks.php +++ b/maintenance/convertLinks.php @@ -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]; diff --git a/maintenance/purgeOldText.inc b/maintenance/purgeOldText.inc index b88ad7231a..58b3fa12e8 100644 --- a/maintenance/purgeOldText.inc +++ b/maintenance/purgeOldText.inc @@ -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" ); diff --git a/maintenance/rollbackEdits.php b/maintenance/rollbackEdits.php index c7f6aa7db5..2be0566a2b 100644 --- a/maintenance/rollbackEdits.php +++ b/maintenance/rollbackEdits.php @@ -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; diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 15fb68f0df..d991551d10 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -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] ); diff --git a/maintenance/storage/compressOld.inc b/maintenance/storage/compressOld.inc index e5d5fe9c7e..4a97505a6c 100644 --- a/maintenance/storage/compressOld.inc +++ b/maintenance/storage/compressOld.inc @@ -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; } diff --git a/maintenance/storage/moveToExternal.php b/maintenance/storage/moveToExternal.php index 907254b369..80d8646b35 100644 --- a/maintenance/storage/moveToExternal.php +++ b/maintenance/storage/moveToExternal.php @@ -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; diff --git a/maintenance/storage/resolveStubs.php b/maintenance/storage/resolveStubs.php index ff1b010427..cd8ef34550 100644 --- a/maintenance/storage/resolveStubs.php +++ b/maintenance/storage/resolveStubs.php @@ -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 ); } } diff --git a/maintenance/upgrade1_5.php b/maintenance/upgrade1_5.php index e0e021424d..880391037f 100644 --- a/maintenance/upgrade1_5.php +++ b/maintenance/upgrade1_5.php @@ -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 ); diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index 668d0bc98c..9dcd1814a1 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -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 ); diff --git a/maintenance/userOptions.inc b/maintenance/userOptions.inc index bfc8e8e67e..88dfc3d869 100644 --- a/maintenance/userOptions.inc +++ b/maintenance/userOptions.inc @@ -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 ); -- 2.20.1