33require_once __DIR__ .
'/Maintenance.php';
51 parent::__construct();
57 $this->
addDescription(
'Script to update image metadata records' );
59 $this->
addOption(
'missing',
'Check for files without associated database record' );
60 $this->
addOption(
'dry-run',
'Only report, don\'t update the database' );
65 $this->dryrun = $this->
hasOption(
'dry-run' );
66 if ( $this->dryrun ) {
67 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
68 ->setReason(
'Dry run mode, image upgrades are suppressed' );
82 if ( !
isset( $this->repo ) ) {
94 function init( $count, $table ) {
97 $this->count = $count;
99 $this->
table = $table;
103 $this->updated += $updated;
105 if ( $this->processed % 100 != 0 ) {
108 $portion = $this->processed / $this->count;
109 $updateRate = $this->updated / $this->processed;
112 $delta = $now - $this->startTime;
113 $estimatedTotalTime = $delta /
$portion;
115 $rate = $this->processed /
$delta;
117 $this->
output(
sprintf(
"%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
125 $updateRate * 100.0 ) );
130 $count = $this->dbw->selectField( $table,
'count(*)',
'', __METHOD__ );
131 $this->
init( $count, $table );
132 $this->
output(
"Processing $table...\n" );
135 $queryInfo[
'tables'], $queryInfo[
'fields'], [], __METHOD__, [], $queryInfo[
'joins']
138 foreach ( $result as $row ) {
146 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
150 $callback = [
$this,
'imageCallback' ];
157 $file = $this->
getRepo()->newFileFromRow( $row );
159 return $file->getUpgraded();
164 [ $this,
'oldimageCallback' ] );
170 if ( $row->oi_archive_name ==
'' ) {
171 $this->
output(
"Empty oi_archive_name for oi_name={$row->oi_name}\n" );
175 $file = $this->
getRepo()->newFileFromRow( $row );
177 return $file->getUpgraded();
181 $this->
getRepo()->enumFiles( [ $this,
'checkMissingImage' ] );
186 $row = $this->dbw->selectRow(
'image',
188 [
'img_name' => $filename ],
197 $timestamp = $this->dbw->timestamp( $this->
getRepo()->getFileTimestamp( $fullpath ) );
199 $altname = MediaWikiServices::getInstance()->getContentLanguage()->
200 checkTitleEncoding( $filename );
201 if ( $altname != $filename ) {
202 if ( $this->dryrun ) {
204 $this->
output(
"Estimating transcoding... $altname\n" );
206 # @todo FIXME: create renameFile()
211 if ( $filename ==
'' ) {
212 $this->
output(
"Empty filename for $fullpath\n" );
216 if ( !$this->dryrun ) {
218 if ( !$file->recordUpload(
220 '(recovered file, missing upload log entry)',
227 $this->
output(
"Error uploading file $fullpath\n" );
232 $this->
output( $fullpath .
"\n" );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$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.
wfLocalFile( $title)
Get an object referring to a locally registered file.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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)
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
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.
static singleton()
Get a RepoGroup instance.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
Advanced database interface for IDatabase handles that include maintenance methods.
require_once RUN_MAINTENANCE_IF_MAIN