require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Maintenance script to refresh image metadata fields.
*
class RefreshImageMetadata extends Maintenance {
/**
- * @var Database
+ * @var IMaintainableDatabase
*/
protected $dbw;
$error = 0;
$dbw = $this->getDB( DB_MASTER );
- if ( $this->mBatchSize <= 0 ) {
- $this->error( "Batch size is too low...", 12 );
+ $batchSize = $this->getBatchSize();
+ if ( $batchSize <= 0 ) {
+ $this->fatalError( "Batch size is too low...", 12 );
}
$repo = RepoGroup::singleton()->getLocalRepo();
}
$options = [
- 'LIMIT' => $this->mBatchSize,
+ 'LIMIT' => $batchSize,
'ORDER BY' => 'img_name ASC',
];
+ $fileQuery = LocalFile::getQueryInfo();
+
do {
$res = $dbw->select(
- 'image',
- '*',
+ $fileQuery['tables'],
+ $fileQuery['fields'],
array_merge( $conds, $conds2 ),
__METHOD__,
- $options
+ $options,
+ $fileQuery['joins']
);
if ( $res->numRows() > 0 ) {
$row1 = $res->current();
- $this->output( "Processing next {$this->mBatchSize} rows starting with {$row1->img_name}.\n" );
+ $this->output( "Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" );
$res->rewind();
- } else {
- $this->error( "No images to process.", 4 );
}
foreach ( $res as $row ) {
}
$conds2 = [ 'img_name > ' . $dbw->addQuotes( $row->img_name ) ];
wfWaitForSlaves();
- } while ( $res->numRows() === $this->mBatchSize );
+ } while ( $res->numRows() === $batchSize );
$total = $upgraded + $leftAlone;
if ( $force ) {
}
/**
- * @param Database $dbw
+ * @param IDatabase $dbw
* @return array
*/
function getConditions( $dbw ) {
}
if ( $brokenOnly && $force ) {
- $this->error( 'Cannot use --broken-only and --force together. ', 2 );
+ $this->fatalError( 'Cannot use --broken-only and --force together. ', 2 );
}
}
}
-$maintClass = 'RefreshImageMetadata';
+$maintClass = RefreshImageMetadata::class;
require_once RUN_MAINTENANCE_IF_MAIN;