r111795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111794‎ | r111795 | r111796 >
Date:21:48, 17 February 2012
Author:aaron
Status:ok
Tags:
Comment:
(bug 34373) - 'populateRevisionSha1.php misses archive rows, whose text is stored directly in the archive table (not text table)'
Modified paths:
  • /trunk/phase3/maintenance/populateRevisionSha1.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateRevisionSha1.php
@@ -36,31 +36,33 @@
3737
3838 protected function doDBUpdates() {
3939 $db = $this->getDB( DB_MASTER );
 40+
4041 if ( !$db->tableExists( 'revision' ) ) {
4142 $this->error( "revision table does not exist", true );
42 - }
43 - if ( !$db->tableExists( 'archive' ) ) {
 43+ } elseif ( !$db->tableExists( 'archive' ) ) {
4444 $this->error( "archive table does not exist", true );
4545 }
4646
4747 $this->output( "Populating rev_sha1 column\n" );
48 - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
 48+ $rc = $this->doSha1Updates( 'revision', 'rev_id', 'rev' );
4949
5050 $this->output( "Populating ar_sha1 column\n" );
51 - $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
 51+ $ac = $this->doSha1Updates( 'archive', 'ar_rev_id', 'ar' );
 52+ $this->output( "Populating ar_sha1 column legacy rows\n" );
 53+ $ac += $this->doSha1LegacyUpdates();
5254
5355 $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" );
5456 return true;
5557 }
5658
5759 /**
58 - * @param $db DatabaseBase
5960 * @param $table string
6061 * @param $idCol
6162 * @param $prefix string
6263 * @return Integer Rows changed
6364 */
64 - protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
 65+ protected function doSha1Updates( $table, $idCol, $prefix ) {
 66+ $db = $this->getDB( DB_MASTER );
6567 $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
6668 $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
6769 if ( !$start || !$end ) {
@@ -81,20 +83,7 @@
8284
8385 $db->begin();
8486 foreach ( $res as $row ) {
85 - if ( $table === 'archive' ) {
86 - $rev = Revision::newFromArchiveRow( $row );
87 - } else {
88 - $rev = new Revision( $row );
89 - }
90 - $text = $rev->getRawText();
91 - if ( !is_string( $text ) ) {
92 - # This should not happen, but sometimes does (bug 20757)
93 - $this->output( "Text of revision {$row->$idCol} unavailable!\n" );
94 - } else {
95 - $db->update( $table,
96 - array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
97 - array( $idCol => $row->$idCol ),
98 - __METHOD__ );
 87+ if ( $this->upgradeRow( $row, $db, $table, $idCol, $prefix ) ) {
9988 $count++;
10089 }
10190 }
@@ -106,6 +95,50 @@
10796 }
10897 return $count;
10998 }
 99+
 100+ protected function doSha1LegacyUpdates() {
 101+ $count = 0;
 102+ $db = $this->getDB( DB_MASTER );
 103+ $res = $db->select( 'archive', '*', array( 'ar_rev_id IS NULL' ), __METHOD__ );
 104+
 105+ $updateSize = 0;
 106+ $db->begin();
 107+ foreach ( $res as $row ) {
 108+ if ( $this->upgradeRow( $row, 'archive', 'ar_timestamp', 'ar' ) ) {
 109+ ++$count;
 110+ }
 111+ if ( ++$updateSize >= 100 ) {
 112+ $updateSize = 0;
 113+ $db->commit();
 114+ $this->output( "Commited row with ar_timestamp={$row->ar_timestamp}\n" );
 115+ wfWaitForSlaves();
 116+ $db->begin();
 117+ }
 118+ }
 119+ $db->commit();
 120+ }
 121+
 122+ protected function upgradeRow( $row, $table, $idCol, $prefix ) {
 123+ $db = $this->getDB( DB_MASTER );
 124+ if ( $table === 'archive' ) {
 125+ $rev = Revision::newFromArchiveRow( $row );
 126+ } else {
 127+ $rev = new Revision( $row );
 128+ }
 129+ $text = $rev->getRawText();
 130+ if ( !is_string( $text ) ) {
 131+ # This should not happen, but sometimes does (bug 20757)
 132+ $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" );
 133+ return false;
 134+ } else {
 135+ $db->update( $table,
 136+ array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
 137+ array( $idCol => $row->$idCol ),
 138+ __METHOD__
 139+ );
 140+ return true;
 141+ }
 142+ }
110143 }
111144
112145 $maintClass = "PopulateRevisionSha1";

Sign-offs

UserFlagDate
Reedyinspected20:07, 6 March 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111881r111795: update line to remove bogus $db argumentaaron19:47, 19 February 2012
r111920r111795: Split out upgradeLegacyArchiveRow() function and added NS/title to c...aaron11:00, 20 February 2012
r113169Minor followup to r111795, make doSha1LegacyUpdates return it's count value s...reedy19:21, 6 March 2012
r113174MFT r111795, r111881, r111920, r112573, r112995, r113169reedy20:12, 6 March 2012
r113175MFT r111795, r111881, r111920, r112573, r112995, r113169reedy20:13, 6 March 2012

Status & tagging log