r74742 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74741‎ | r74742 | r74743 >
Date:22:34, 13 October 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Assignment in loop conditions suck

while ( $row = $dbw->fetchObject( $res ) ) { to foreach ( $res as $row ) in maintenance stuffs (more to come)
Modified paths:
  • /trunk/phase3/maintenance/convertLinks.php (modified) (history)
  • /trunk/phase3/maintenance/purgeOldText.inc (modified) (history)
  • /trunk/phase3/maintenance/rollbackEdits.php (modified) (history)
  • /trunk/phase3/maintenance/storage/checkStorage.php (modified) (history)
  • /trunk/phase3/maintenance/storage/compressOld.inc (modified) (history)
  • /trunk/phase3/maintenance/storage/moveToExternal.php (modified) (history)
  • /trunk/phase3/maintenance/storage/resolveStubs.php (modified) (history)
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)
  • /trunk/phase3/maintenance/userDupes.inc (modified) (history)
  • /trunk/phase3/maintenance/userOptions.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/storage/compressOld.inc
@@ -18,7 +18,7 @@
1919 break;
2020 }
2121 $last = $start;
22 - while( $row = $dbw->fetchObject( $res ) ) {
 22+ foreach ( $res as $row ) {
2323 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
2424 compressPage( $row, $extdb );
2525 $last = $row->old_id;
@@ -169,7 +169,7 @@
170170 $revLoadOptions
171171 );
172172 $revs = array();
173 - while ( $revRow = $dbw->fetchObject( $revRes ) ) {
 173+ foreach ( $res as $row ) {
174174 $revs[] = $revRow;
175175 }
176176
Index: trunk/phase3/maintenance/storage/moveToExternal.php
@@ -59,7 +59,7 @@
6060 "old_id BETWEEN $blockStart AND $blockEnd",
6161 'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
6262 ), $fname );
63 - while ( $row = $dbr->fetchObject( $res ) ) {
 63+ foreach ( $res as $row ) {
6464 # Resolve stubs
6565 $text = $row->old_text;
6666 $id = $row->old_id;
Index: trunk/phase3/maintenance/storage/resolveStubs.php
@@ -38,7 +38,7 @@
3939 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
4040 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
4141 $fname );
42 - while ( $row = $dbr->fetchObject( $res ) ) {
 42+ foreach ( $res as $row ) {
4343 resolveStub( $row->old_id, $row->old_text, $row->old_flags );
4444 }
4545 }
Index: trunk/phase3/maintenance/storage/checkStorage.php
@@ -70,7 +70,7 @@
7171 $dbr->ping();
7272 $res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ),
7373 array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), $fname );
74 - while ( $row = $dbr->fetchObject( $res ) ) {
 74+ foreach ( $res as $row ) {
7575 $this->oldIdMap[$row->rev_id] = $row->rev_text_id;
7676 }
7777 $dbr->freeResult( $res );
@@ -85,7 +85,7 @@
8686 $objectRevs = array();
8787 $res = $dbr->select( 'text', array( 'old_id', 'old_flags' ),
8888 'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', $fname );
89 - while ( $row = $dbr->fetchObject( $res ) ) {
 89+ foreach ( $res as $row ) {
9090 $flags = $row->old_flags;
9191 $id = $row->old_id;
9292
@@ -139,7 +139,7 @@
140140 if ( count( $externalRevs ) ) {
141141 $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
142142 array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), $fname );
143 - while ( $row = $dbr->fetchObject( $res ) ) {
 143+ foreach ( $res as $row ) {
144144 $urlParts = explode( '://', $row->old_text, 2 );
145145 if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
146146 $this->error( 'restore text', "Error: invalid URL \"{$row->old_text}\"", $row->old_id );
@@ -177,7 +177,7 @@
178178 $res = $extDb->select( $blobsTable,
179179 array( 'blob_id' ),
180180 array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
181 - while ( $row = $extDb->fetchObject( $res ) ) {
 181+ foreach ( $res as $row ) {
182182 unset( $xBlobIds[$row->blob_id] );
183183 }
184184 $extDb->freeResult( $res );
@@ -196,7 +196,7 @@
197197 $headerLength = 300;
198198 $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
199199 array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), $fname );
200 - while ( $row = $dbr->fetchObject( $res ) ) {
 200+ foreach ( $res as $row ) {
201201 $oldId = $row->old_id;
202202 $matches = array();
203203 if ( !preg_match( '/^O:(\d+):"(\w+)"/', $row->header, $matches ) ) {
@@ -247,7 +247,7 @@
248248 $headerLength = 300;
249249 $res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
250250 array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), $fname );
251 - while ( $row = $dbr->fetchObject( $res ) ) {
 251+ foreach ( $res as $row ) {
252252 $flags = explode( ',', $row->old_flags );
253253 if ( in_array( 'external', $flags ) ) {
254254 // Concat blob is in external storage?
@@ -355,7 +355,7 @@
356356 $res = $extDb->select( $blobsTable,
357357 array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
358358 array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
359 - while ( $row = $extDb->fetchObject( $res ) ) {
 359+ foreach ( $res as $row ) {
360360 if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
361361 $this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
362362 $oldIds[$row->blob_id] );
Index: trunk/phase3/maintenance/userOptions.inc
@@ -111,7 +111,7 @@
112112 __METHOD__
113113 );
114114
115 - while ( $id = $dbr->fetchObject( $result ) ) {
 115+ foreach ( $result as $id ) {
116116
117117 $user = User::newFromId( $id->user_id );
118118
@@ -161,7 +161,7 @@
162162 __METHOD__
163163 );
164164
165 - while ( $id = $dbr->fetchObject( $result ) ) {
 165+ foreach ( $result as $id ) {
166166
167167 $user = User::newFromId( $id->user_id );
168168
Index: trunk/phase3/maintenance/rollbackEdits.php
@@ -86,7 +86,7 @@
8787 array( 'page_latest = rev_id', 'rev_user_text' => $user ),
8888 __METHOD__
8989 );
90 - while ( $row = $dbr->fetchObject( $results ) ) {
 90+ foreach ( $results as $row ) {
9191 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
9292 }
9393 return $titles;
Index: trunk/phase3/maintenance/purgeOldText.inc
@@ -21,7 +21,7 @@
2222 # Get "active" text records from the revisions table
2323 echo( "Searching for active text records in revisions table..." );
2424 $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
25 - while ( $row = $dbw->fetchObject( $res ) ) {
 25+ foreach ( $res as $row ) {
2626 $cur[] = $row->rev_text_id;
2727 }
2828 echo( "done.\n" );
@@ -29,7 +29,7 @@
3030 # Get "active" text records from the archive table
3131 echo( "Searching for active text records in archive table..." );
3232 $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
33 - while ( $row = $dbw->fetchObject( $res ) ) {
 33+ foreach ( $res as $row ) { {
3434 $cur[] = $row->ar_text_id;
3535 }
3636 echo( "done.\n" );
@@ -39,7 +39,7 @@
4040 $set = implode( ', ', $cur );
4141 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
4242 $old = array();
43 - while ( $row = $dbw->fetchObject( $res ) ) {
 43+ foreach ( $res as $row ) { {
4444 $old[] = $row->old_id;
4545 }
4646 echo( "done.\n" );
Index: trunk/phase3/maintenance/userDupes.inc
@@ -190,7 +190,7 @@
191191 HAVING n > 1", $fname );
192192
193193 $list = array();
194 - while ( $row = $this->db->fetchObject( $result ) ) {
 194+ foreach ( $res as $row ) {
195195 $list[] = $row->user_name;
196196 }
197197 return $list;
@@ -215,7 +215,7 @@
216216 $firstId = $firstRow->user_id;
217217 wfOut( "Record that will be used for '$name' is user_id=$firstId\n" );
218218
219 - while ( $row = $this->db->fetchObject( $result ) ) {
 219+ foreach ( $result as $row ) {
220220 $dupeId = $row->user_id;
221221 wfOut( "... dupe id $dupeId: " );
222222 $edits = $this->editCount( $dupeId );
Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -344,7 +344,7 @@
345345 __METHOD__ );
346346
347347 $add = array();
348 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 348+ foreach ( $result as $row ) {
349349 $copy = array();
350350 foreach ( $fields as $field => $source ) {
351351 if ( $source === MW_UPGRADE_COPY ) {
@@ -455,7 +455,7 @@
456456 FROM $cur
457457 ORDER BY cur_id", __METHOD__ );
458458 $add = array();
459 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 459+ foreach ( $result as $row ) {
460460 $add[] = array(
461461 'old_namespace' => $row->cur_namespace,
462462 'old_title' => $row->cur_title,
@@ -488,7 +488,7 @@
489489 __METHOD__ );
490490
491491 $add = array();
492 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 492+ foreach ( $result as $row ) {
493493 $add[] = array(
494494 'rev_id' => $row->old_id,
495495 'rev_page' => $row->cur_id,
@@ -516,7 +516,7 @@
517517 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}
518518 ORDER BY cur_id", __METHOD__ );
519519 $add = array();
520 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 520+ foreach ( $result as $row ) {
521521 $add[] = array(
522522 'page_id' => $row->cur_id,
523523 'page_namespace' => $row->cur_namespace,
@@ -578,7 +578,7 @@
579579 FROM $links, $cur
580580 WHERE l_to=cur_id", __METHOD__ );
581581 $add = array();
582 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 582+ foreach ( $result as $row ) {
583583 $add[] = array(
584584 'pl_from' => $row->l_from,
585585 'pl_namespace' => $row->cur_namespace,
@@ -598,7 +598,7 @@
599599 "SELECT bl_from, bl_to FROM $brokenlinks",
600600 __METHOD__ );
601601 $add = array();
602 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 602+ foreach ( $result as $row ) {
603603 $pagename = $this->conv( $row->bl_to );
604604 $title = Title::newFromText( $pagename );
605605 if ( is_null( $title ) ) {
@@ -905,7 +905,7 @@
906906 __METHOD__ );
907907
908908 $add = array();
909 - while ( $row = $this->dbr->fetchObject( $result ) ) {
 909+ foreach ( $result as $row ) {
910910 $add[] = array(
911911 'wl_user' => $row->wl_user,
912912 'wl_namespace' => MWNamespace::getSubject( $row->wl_namespace ),
@@ -1214,7 +1214,7 @@
12151215 echo "Found $n titles with duplicate entries.\n";
12161216 if ( $n > 0 ) {
12171217 echo "Correcting...\n";
1218 - while ( $row = $dbw->fetchObject( $res ) ) {
 1218+ foreach ( $res as $row ) {
12191219 $ns = intval( $row->cur_namespace );
12201220 $title = $dbw->addQuotes( $row->cur_title );
12211221
Index: trunk/phase3/maintenance/convertLinks.php
@@ -113,7 +113,7 @@
114114 $res = $dbw->query( "SELECT cur_namespace,cur_title,cur_id FROM $cur" );
115115 $ids = array();
116116
117 - while ( $row = $dbw->fetchObject( $res ) ) {
 117+ foreach ( $res as $row ) {
118118 $title = $row->cur_title;
119119 if ( $row->cur_namespace ) {
120120 $title = $wgContLang->getNsText( $row->cur_namespace ) . ":$title";
@@ -154,7 +154,7 @@
155155 }
156156
157157 $tuplesAdded = 0; # no tuples added to INSERT yet
158 - while ( $row = $dbw->fetchObject( $res ) ) {
 158+ foreach ( $res as $row ) {
159159 $fromTitle = $row->l_from;
160160 if ( array_key_exists( $fromTitle, $ids ) ) { # valid title
161161 $from = $ids[$fromTitle];

Follow-up revisions

RevisionCommit summaryAuthorDate
r74744follow-up to r74742: fix typosashley22:43, 13 October 2010
r74953Double braces introduced in r74742 giving a fatal:...platonides17:42, 18 October 2010

Comments

#Comment by Platonides (talk | contribs)   17:42, 18 October 2010

Not as much as parser errors. Fixed in r74953.

#Comment by Aaron Schulz (talk | contribs)   19:43, 18 October 2010

Zingers in CR? hehe...

Status & tagging log