From: Aaron Schulz Date: Fri, 12 Aug 2011 20:37:35 +0000 (+0000) Subject: Changed PopulateImageSha1 to use LoggedUpdateMaintenance and added it to $postDatabas... X-Git-Tag: 1.31.0-rc.0~28304 X-Git-Url: http://git.cyclocoop.org/%22%20.%20%20%20%24self2%20.%20%20%20%22&var_mode_affiche=boucle?a=commitdiff_plain;h=7cb4d69d9d2c442ad3cfe6efd5307463aef562d8;p=lhc%2Fweb%2Fwiklou.git Changed PopulateImageSha1 to use LoggedUpdateMaintenance and added it to $postDatabaseUpdateMaintenance --- diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 18a658b3a4..274b896d2a 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -835,6 +835,7 @@ $wgAutoloadLocalClasses = array( 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php', 'Maintenance' => 'maintenance/Maintenance.php', 'PopulateCategory' => 'maintenance/populateCategory.php', + 'PopulateImageSha1' => 'maintenance/populateImageSha1.php', 'PopulateLogSearch' => 'maintenance/populateLogSearch.php', 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php', 'PopulateParentId' => 'maintenance/populateParentId.php', diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index dd0e32384a..111db4e994 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -42,7 +42,8 @@ abstract class DatabaseUpdater { protected $postDatabaseUpdateMaintenance = array( 'DeleteDefaultMessages', 'PopulateRevisionLength', - 'PopulateRevisionSha1' + 'PopulateRevisionSha1', + 'PopulateImageSha1' ); /** diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 586b727ef6..2829eac0cc 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1305,7 +1305,7 @@ abstract class LoggedUpdateMaintenance extends Maintenance { /** * Do the actual work. All child classes will need to implement this. - * Return true to log the update as done or false on failure. + * Return true to log the update as done or false (usually on failure). * @return Bool */ abstract protected function doDBUpdates(); diff --git a/maintenance/populateImageSha1.php b/maintenance/populateImageSha1.php index c8c2d5f319..4fee6fee5f 100644 --- a/maintenance/populateImageSha1.php +++ b/maintenance/populateImageSha1.php @@ -22,16 +22,29 @@ require_once( dirname( __FILE__ ) . '/Maintenance.php' ); -class PopulateImageSha1 extends Maintenance { +class PopulateImageSha1 extends LoggedUpdateMaintenance { public function __construct() { parent::__construct(); $this->mDescription = "Populate the img_sha1 field"; $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" . "\t\tdefault uses Database class", false, true ); $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true ); + $this->setBatchSize( 200 ); } - public function execute() { + protected function getUpdateKey() { + return 'populate img_sha1'; + } + + protected function updateSkippedMessage() { + return 'img_sha1 column of image table already populated.'; + } + + protected function updatelogFailedMessage() { + return 'Could not insert img_sha1 population row.'; + } + + public function doDBUpdates() { $method = $this->getOption( 'method', 'normal' ); $file = $this->getOption( 'file' ); @@ -46,11 +59,15 @@ class PopulateImageSha1 extends Maintenance { ); if ( !$res ) { $this->error( "No such file: $file", true ); - return; + return false; } + $this->output( "Populating img_sha1 field for specified files\n" ); } else { - $res = $dbw->select( 'image', array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); + $res = $dbw->select( 'image', + array( 'img_name' ), array( 'img_sha1' => '' ), __METHOD__ ); + $this->output( "Populating img_sha1 field\n" ); } + $imageTable = $dbw->tableName( 'image' ); if ( $method == 'pipe' ) { @@ -66,7 +83,7 @@ class PopulateImageSha1 extends Maintenance { $numRows = $res->numRows(); $i = 0; foreach ( $res as $row ) { - if ( $i % 100 == 0 ) { + if ( $i % $this->mBatchSize == 0 ) { $this->output( sprintf( "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) ); wfWaitForSlaves(); } @@ -92,6 +109,12 @@ class PopulateImageSha1 extends Maintenance { } $t += microtime( true ); $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) ); + + if ( $file ) { + return false; // we only updated *some* files, don't log + } else { + return true; + } } }