Go to the documentation of this file.
33 require_once __DIR__ .
'/Maintenance.php';
71 parent::__construct();
77 $this->
addDescription(
'Script to update image metadata records' );
79 $this->
addOption(
'missing',
'Check for files without associated database record' );
80 $this->
addOption(
'dry-run',
'Only report, don\'t update the database' );
85 $this->dryrun = $this->
hasOption(
'dry-run' );
86 if ( $this->dryrun ) {
88 ->setReason(
'Dry run mode, image upgrades are suppressed' );
102 if ( $this->repo ===
null ) {
119 $this->processed = 0;
122 $this->startTime = microtime(
true );
129 if ( $this->processed % 100 != 0 ) {
135 $now = microtime(
true );
137 $estimatedTotalTime = $delta / $portion;
138 $eta = $this->startTime + $estimatedTotalTime;
139 $rate = $this->processed / $delta;
141 $this->
output( sprintf(
"%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
149 $updateRate * 100.0 ) );
154 $count = $this->dbw->selectField(
$table,
'count(*)',
'', __METHOD__ );
156 $this->
output(
"Processing $table...\n" );
159 $queryInfo[
'tables'], $queryInfo[
'fields'], [], __METHOD__, [], $queryInfo[
'joins']
162 foreach ( $result as $row ) {
163 $update = call_user_func( $callback, $row,
null );
170 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
174 $callback = [ $this,
'imageCallback' ];
183 return $file->getUpgraded();
188 [ $this,
'oldimageCallback' ] );
194 if ( $row->oi_archive_name ==
'' ) {
195 $this->
output(
"Empty oi_archive_name for oi_name={$row->oi_name}\n" );
201 return $file->getUpgraded();
205 $this->
getRepo()->enumFiles( [ $this,
'checkMissingImage' ] );
210 $row = $this->dbw->selectRow(
'image',
212 [
'img_name' => $filename ],
221 $timestamp = $this->dbw->timestamp( $this->
getRepo()->getFileTimestamp( $fullpath ) );
222 $services = MediaWikiServices::getInstance();
224 $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
225 if ( $altname != $filename ) {
226 if ( $this->dryrun ) {
227 $filename = $altname;
228 $this->
output(
"Estimating transcoding... $altname\n" );
232 $filename = $this->renameFile( $filename );
236 if ( $filename ==
'' ) {
237 $this->
output(
"Empty filename for $fullpath\n" );
241 if ( !$this->dryrun ) {
242 $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
243 if ( !
$file->recordUpload(
245 '(recovered file, missing upload log entry)',
252 $this->
output(
"Error uploading file $fullpath\n" );
257 $this->
output( $fullpath .
"\n" );
const RUN_MAINTENANCE_IF_MAIN
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...
execute()
Do the actual work.
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
addDescription( $text)
Set the description text.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Maintenance script to update image metadata records.
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
imageCallback( $row, $copy)
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
checkMissingImage( $fullpath)
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
__construct()
Default constructor.
oldimageCallback( $row, $copy)
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
buildTable( $table, $key, $queryInfo, $callback)
addMissingImage( $filename, $fullpath)
IMaintainableDatabase $dbw
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
Advanced database interface for IDatabase handles that include maintenance methods.
A repository that stores files in the local filesystem and registers them in the wiki's own database.