Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/128964

Change subject: Added --multiversiononly option to image SHA1 population script
......................................................................

Added --multiversiononly option to image SHA1 population script

* A portion of files have bad SHA1 values due to re-upload bugs.
  This adds an option to just force updates for files with re-uploads.

Change-Id: I24bd9a8f19bafc3e794cf32c78ce7f720f302627
---
M maintenance/populateImageSha1.php
1 file changed, 10 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/64/128964/1

diff --git a/maintenance/populateImageSha1.php 
b/maintenance/populateImageSha1.php
index 126d22d..4964bf1 100644
--- a/maintenance/populateImageSha1.php
+++ b/maintenance/populateImageSha1.php
@@ -33,6 +33,7 @@
                parent::__construct();
                $this->mDescription = "Populate the img_sha1 field";
                $this->addOption( 'force', "Recalculate sha1 for rows that 
already have a value" );
+               $this->addOption( 'multiversiononly', "Calculate only for files 
with several versions" );
                $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 );
@@ -47,7 +48,7 @@
        }
 
        public function execute() {
-               if ( $this->getOption( 'file' ) ) {
+               if ( $this->getOption( 'file' ) || $this->hasOption( 
'multiversiononly' ) ) {
                        $this->doDBUpdates(); // skip update log checks/saves
                } else {
                        parent::execute();
@@ -82,7 +83,12 @@
                                $conds = array( 'img_sha1' => '' );
                                $this->output( "Populating img_sha1 field\n" );
                        }
-                       $res = $dbw->select( 'image', array( 'img_name' ), 
$conds, __METHOD__ );
+                       if ( $this->hasOption( 'multiversiononly' ) ) {
+                               $res = $dbw->select( 'oldimage',
+                                       array( 'img_name' => 
'DISTINCT(oi_name)' ), $conds, __METHOD__ );
+                       } else {
+                               $res = $dbw->select( 'image', array( 'img_name' 
), $conds, __METHOD__ );
+                       }
                }
 
                $imageTable = $dbw->tableName( 'image' );
@@ -109,10 +115,12 @@
                                        "Done %d of %d, %5.3f%%  \r", $i, 
$numRows, $i / $numRows * 100 ) );
                                wfWaitForSlaves();
                        }
+
                        $file = wfLocalFile( $row->img_name );
                        if ( !$file ) {
                                continue;
                        }
+
                        // Upgrade the current file version...
                        $sha1 = $file->getRepo()->getFileSha1( $file->getPath() 
);
                        if ( strval( $sha1 ) !== '' ) { // file on disk and 
hashed properly

-- 
To view, visit https://gerrit.wikimedia.org/r/128964
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24bd9a8f19bafc3e794cf32c78ce7f720f302627
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to