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 );
}
public function execute() {
- if ( $this->getOption( 'file' ) ) {
+ if ( $this->getOption( 'file' ) || $this->hasOption( 'multiversiononly' ) ) {
$this->doDBUpdates(); // skip update log checks/saves
} else {
parent::execute();
$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' );
"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