X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpopulateRevisionLength.php;h=a9457c2a1cd13f65b078bc4b734b4174f526fba2;hb=6a077079d66ac41e9c8d499d4c3e8da1b24313db;hp=a9fb394ad10945994f18ab296989fb50ef9f0ee8;hpb=174f34a86de3162bc673fd3bc6bed815cccf0edc;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/populateRevisionLength.php b/maintenance/populateRevisionLength.php index a9fb394ad1..a9457c2a1c 100644 --- a/maintenance/populateRevisionLength.php +++ b/maintenance/populateRevisionLength.php @@ -1,7 +1,6 @@ mDescription = "Populates the rev_len and ar_len fields"; + $this->addDescription( 'Populates the rev_len and ar_len fields' ); $this->setBatchSize( 200 ); } @@ -42,12 +42,12 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { } public function doDBUpdates() { - $db = $this->getDB( DB_MASTER ); - if ( !$db->tableExists( 'revision' ) ) { + $dbw = $this->getDB( DB_MASTER ); + if ( !$dbw->tableExists( 'revision' ) ) { $this->error( "revision table does not exist", true ); - } elseif ( !$db->tableExists( 'archive' ) ) { + } elseif ( !$dbw->tableExists( 'archive' ) ) { $this->error( "archive table does not exist", true ); - } elseif ( !$db->fieldExists( 'revision', 'rev_len', __METHOD__ ) ) { + } elseif ( !$dbw->fieldExists( 'revision', 'rev_len', __METHOD__ ) ) { $this->output( "rev_len column does not exist\n\n", true ); return false; @@ -73,9 +73,10 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { * @return int */ protected function doLenUpdates( $table, $idCol, $prefix, $fields ) { - $db = $this->getDB( DB_MASTER ); - $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ ); - $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ ); + $dbr = $this->getDB( DB_REPLICA ); + $dbw = $this->getDB( DB_MASTER ); + $start = $dbw->selectField( $table, "MIN($idCol)", false, __METHOD__ ); + $end = $dbw->selectField( $table, "MAX($idCol)", false, __METHOD__ ); if ( !$start || !$end ) { $this->output( "...$table table seems to be empty.\n" ); @@ -89,25 +90,27 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { while ( $blockStart <= $end ) { $this->output( "...doing $idCol from $blockStart to $blockEnd\n" ); - $res = $db->select( + $res = $dbr->select( $table, $fields, - array( + [ "$idCol >= $blockStart", "$idCol <= $blockEnd", "{$prefix}_len IS NULL" - ), + ], __METHOD__ ); - $this->beginTransaction( $db, __METHOD__ ); - # Go through and update rev_len from these rows. - foreach ( $res as $row ) { - if ( $this->upgradeRow( $row, $table, $idCol, $prefix ) ) { - $count++; + if ( $res->numRows() > 0 ) { + $this->beginTransaction( $dbw, __METHOD__ ); + # Go through and update rev_len from these rows. + foreach ( $res as $row ) { + if ( $this->upgradeRow( $row, $table, $idCol, $prefix ) ) { + $count++; + } } + $this->commitTransaction( $dbw, __METHOD__ ); } - $this->commitTransaction( $db, __METHOD__ ); $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; @@ -125,7 +128,7 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { * @return bool */ protected function upgradeRow( $row, $table, $idCol, $prefix ) { - $db = $this->getDB( DB_MASTER ); + $dbw = $this->getDB( DB_MASTER ); $rev = ( $table === 'archive' ) ? Revision::newFromArchiveRow( $row ) @@ -133,7 +136,7 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { $content = $rev->getContent(); if ( !$content ) { - # This should not happen, but sometimes does (bug 20757) + # This should not happen, but sometimes does (T22757) $id = $row->$idCol; $this->output( "Content of $table $id unavailable!\n" ); @@ -141,9 +144,9 @@ class PopulateRevisionLength extends LoggedUpdateMaintenance { } # Update the row... - $db->update( $table, - array( "{$prefix}_len" => $content->getSize() ), - array( $idCol => $row->$idCol ), + $dbw->update( $table, + [ "{$prefix}_len" => $content->getSize() ], + [ $idCol => $row->$idCol ], __METHOD__ );