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( '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' ) {
$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();
}
}
$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
}
}