33require_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 ) {
87 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
88 ->setReason(
'Dry run mode, image upgrades are suppressed' );
102 if ( $this->repo ===
null ) {
103 $this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
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' ];
175 $this->
buildTable(
'image',
'img_name', LocalFile::getQueryInfo(), $callback );
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 ],
222 $timestamp = $this->dbw->timestamp( $this->
getRepo()->getFileTimestamp( $fullpath ) );
223 $services = MediaWikiServices::getInstance();
225 $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
226 if ( $altname != $filename ) {
227 if ( $this->dryrun ) {
228 $filename = $altname;
229 $this->
output(
"Estimating transcoding... $altname\n" );
233 $filename = $this->renameFile( $filename );
237 if ( $filename ==
'' ) {
238 $this->
output(
"Empty filename for $fullpath\n" );
242 if ( !$this->dryrun ) {
243 $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
244 $pageText = SpecialUpload::getInitialPageText(
245 '(recovered file, missing upload log entry)'
247 $user = User::newSystemUser(
'Maintenance script', [
'steal' =>
true ] );
248 $status =
$file->recordUpload2(
250 '(recovered file, missing upload log entry)',
256 if ( !$status->isOK() ) {
257 $this->
output(
"Error uploading file $fullpath\n" );
262 $this->
output( $fullpath .
"\n" );
$wgUpdateCompatibleMetadata
If to automatically update the img_metadata field if the metadata field is outdated but compatible wi...
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const RUN_MAINTENANCE_IF_MAIN
Maintenance script to update image metadata records.
__construct()
Default constructor.
buildTable( $table, $key, $queryInfo, $callback)
oldimageCallback( $row, $copy)
checkMissingImage( $fullpath)
IMaintainableDatabase $dbw
imageCallback( $row, $copy)
execute()
Do the actual work.
addMissingImage( $filename, $fullpath)
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
Advanced database interface for IDatabase handles that include maintenance methods.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.