r94382 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94381‎ | r94382 | r94383 >
Date:20:37, 12 August 2011
Author:aaron
Status:ok
Tags:
Comment:
Changed PopulateImageSha1 to use LoggedUpdateMaintenance and added it to $postDatabaseUpdateMaintenance
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/populateImageSha1.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -1305,7 +1305,7 @@
13061306
13071307 /**
13081308 * Do the actual work. All child classes will need to implement this.
1309 - * Return true to log the update as done or false on failure.
 1309+ * Return true to log the update as done or false (usually on failure).
13101310 * @return Bool
13111311 */
13121312 abstract protected function doDBUpdates();
Index: trunk/phase3/maintenance/populateImageSha1.php
@@ -22,16 +22,29 @@
2323
2424 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2525
26 -class PopulateImageSha1 extends Maintenance {
 26+class PopulateImageSha1 extends LoggedUpdateMaintenance {
2727 public function __construct() {
2828 parent::__construct();
2929 $this->mDescription = "Populate the img_sha1 field";
3030 $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" .
3131 "\t\tdefault uses Database class", false, true );
3232 $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true );
 33+ $this->setBatchSize( 200 );
3334 }
3435
35 - public function execute() {
 36+ protected function getUpdateKey() {
 37+ return 'populate img_sha1';
 38+ }
 39+
 40+ protected function updateSkippedMessage() {
 41+ return 'img_sha1 column of image table already populated.';
 42+ }
 43+
 44+ protected function updatelogFailedMessage() {
 45+ return 'Could not insert img_sha1 population row.';
 46+ }
 47+
 48+ public function doDBUpdates() {
3649 $method = $this->getOption( 'method', 'normal' );
3750 $file = $this->getOption( 'file' );
3851
@@ -46,11 +59,15 @@
4760 );
4861 if ( !$res ) {
4962 $this->error( "No such file: $file", true );
50 - return;
 63+ return false;
5164 }
 65+ $this->output( "Populating img_sha1 field for specified files\n" );
5266 } else {
53 - $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ );
 67+ $res = $dbw->select( 'image',
 68+ array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ );
 69+ $this->output( "Populating img_sha1 field\n" );
5470 }
 71+
5572 $imageTable = $dbw->tableName( 'image' );
5673
5774 if ( $method == 'pipe' ) {
@@ -66,7 +83,7 @@
6784 $numRows = $res->numRows();
6885 $i = 0;
6986 foreach ( $res as $row ) {
70 - if ( $i % 100 == 0 ) {
 87+ if ( $i % $this->mBatchSize == 0 ) {
7188 $this->output( sprintf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) );
7289 wfWaitForSlaves();
7390 }
@@ -92,6 +109,12 @@
93110 }
94111 $t += microtime( true );
95112 $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) );
 113+
 114+ if ( $file ) {
 115+ return false; // we only updated *some* files, don't log
 116+ } else {
 117+ return true;
 118+ }
96119 }
97120 }
98121
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -42,7 +42,8 @@
4343 protected $postDatabaseUpdateMaintenance = array(
4444 'DeleteDefaultMessages',
4545 'PopulateRevisionLength',
46 - 'PopulateRevisionSha1'
 46+ 'PopulateRevisionSha1',
 47+ 'PopulateImageSha1'
4748 );
4849
4950 /**
Index: trunk/phase3/includes/AutoLoader.php
@@ -835,6 +835,7 @@
836836 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php',
837837 'Maintenance' => 'maintenance/Maintenance.php',
838838 'PopulateCategory' => 'maintenance/populateCategory.php',
 839+ 'PopulateImageSha1' => 'maintenance/populateImageSha1.php',
839840 'PopulateLogSearch' => 'maintenance/populateLogSearch.php',
840841 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php',
841842 'PopulateParentId' => 'maintenance/populateParentId.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r103033REL1_18 Partial manual merge of r94370, r94382, r96578, r101019 to bring Logg...reedy21:20, 14 November 2011

Status & tagging log