Localisation updates for core and extension messages from translatewiki.net
[lhc/web/wiklou.git] / maintenance / populateImageSha1.php
index c8c2d5f..5222c2d 100644 (file)
@@ -22,7 +22,7 @@
 
 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";
@@ -31,26 +31,46 @@ class PopulateImageSha1 extends Maintenance {
                $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true );
        }
 
+       protected function getUpdateKey() {
+               return 'populate img_sha1';
+       }
+
+       protected function updateSkippedMessage() {
+               return 'img_sha1 column of image table already populated.';
+       }
+
        public function execute() {
+               if ( $this->getOption( 'file' ) ) {
+                       $this->doDBUpdates(); // skip update log checks/saves
+               } else {
+                       parent::execute();
+               }
+       }
+
+       public function doDBUpdates() {
                $method = $this->getOption( 'method', 'normal' );
                $file = $this->getOption( 'file' );
 
                $t = -microtime( true );
                $dbw = wfGetDB( DB_MASTER );
                if ( $file ) {
-                       $res = $dbw->selectRow(
+                       $res = $dbw->select(
                                'image',
                                array( 'img_name' ),
-                               array( 'img_name' => $dbw->addQuotes( $file ) ),
+                               array( 'img_name' => $file ),
                                __METHOD__
                        );
                        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 +86,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 +112,8 @@ class PopulateImageSha1 extends Maintenance {
                }
                $t += microtime( true );
                $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $numRows, $t ) );
+
+               return !$file; // we only updated *some* files, don't log
        }
 }