30require_once __DIR__ .
'/Maintenance.php';
49 parent::__construct();
51 $this->
addDescription(
'Script to update image metadata records' );
56 'Reload metadata from file even if the metadata looks ok',
63 'Only fix really broken records, leave old but still compatible records alone.'
67 'Fix records with an out of date serialization format.'
71 'Enable splitting out large metadata items to the text table. Implies --convert-to-json.'
75 'Output extra information about each upgraded/non-upgraded file.',
80 $this->
addOption(
'start',
'Name of file to start with',
false,
true );
81 $this->
addOption(
'end',
'Name of file to end with',
false,
true );
85 'Only refresh files with this media type, e.g. BITMAP, UNKNOWN etc.',
91 "Only refresh files with this MIME type. Can accept wild-card 'image/*'. "
92 .
"Potentially inefficient unless 'mediatype' is also specified",
98 '(Inefficient!) Only refresh files where the img_metadata field '
99 .
'contains this string. Can be used if its known a specific '
100 .
'property was being extracted incorrectly.',
106 'Time to sleep between each batch (in seconds). Default: 0',
114 $brokenOnly = $this->
hasOption(
'broken-only' );
115 $verbose = $this->
hasOption(
'verbose' );
116 $start = $this->
getOption(
'start',
false );
118 $sleep = (int)$this->
getOption(
'sleep', 0 );
119 $reserialize = $this->
hasOption(
'convert-to-json' );
127 if ( $batchSize <= 0 ) {
128 $this->
fatalError(
"Batch size is too low...", 12 );
131 $repo = $this->
newLocalRepo( $force, $brokenOnly, $reserialize, $split );
136 if ( $start !==
false ) {
141 'LIMIT' => $batchSize,
142 'ORDER BY' =>
'img_name ASC',
145 $fileQuery = LocalFile::getQueryInfo();
146 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
150 $fileQuery[
'tables'],
151 $fileQuery[
'fields'],
152 array_merge( $conds, $conds2 ),
158 if (
$res->numRows() > 0 ) {
159 $row1 =
$res->current();
160 $this->
output(
"Processing next {$res->numRows()} row(s) starting with {$row1->img_name}.\n" );
164 foreach (
$res as $row ) {
167 $file = $repo->newFileFromRow( $row );
168 $file->maybeUpgradeRow();
169 if (
$file->getUpgraded() ) {
172 $this->
output(
"Refreshed File:{$row->img_name}.\n" );
178 $this->
output(
"Forcibly refreshed File:{$row->img_name}.\n" );
182 $this->
output(
"Skipping File:{$row->img_name}.\n" );
186 }
catch ( Exception $e ) {
187 $this->
output(
"{$row->img_name} failed. {$e->getMessage()}\n" );
190 $conds2 = [
'img_name > ' .
$dbw->
addQuotes( $row->img_name ) ];
191 $lbFactory->waitForReplication();
195 }
while (
$res->numRows() === $batchSize );
197 $total = $upgraded + $leftAlone;
199 $this->
output(
"\nFinished refreshing file metadata for $total files. "
200 .
"$upgraded needed to be refreshed, $leftAlone did not need to "
201 .
"be but were refreshed anyways, and $error refreshes were suspicious.\n" );
203 $this->
output(
"\nFinished refreshing file metadata for $total files. "
204 .
"$upgraded were refreshed, $leftAlone were already up to date, "
205 .
"and $error refreshes were suspicious.\n" );
218 $mediatype = $this->
getOption(
'mediatype',
false );
219 $like = $this->
getOption(
'metadata-contains',
false );
221 if ( $end !==
false ) {
224 if (
$mime !==
false ) {
225 list( $major, $minor ) = File::splitMime(
$mime );
226 $conds[
'img_major_mime'] = $major;
227 if ( $minor !==
'*' ) {
228 $conds[
'img_minor_mime'] = $minor;
231 if ( $mediatype !==
false ) {
232 $conds[
'img_media_type'] = $mediatype;
250 if ( $brokenOnly && $force ) {
251 $this->
fatalError(
'Cannot use --broken-only and --force together. ', 2 );
253 $reserialize = $reserialize || $split;
254 if ( $brokenOnly && $reserialize ) {
255 $this->
fatalError(
'Cannot use --broken-only with --convert-to-json or --split. ',
260 'updateCompatibleMetadata' => !$brokenOnly,
262 if ( $reserialize ) {
263 $overrides[
'reserializeMetadata'] =
true;
264 $overrides[
'useJsonMetadata'] =
true;
267 $overrides[
'useSplitMetadata'] =
true;
270 return MediaWikiServices::getInstance()->getRepoGroup()
271 ->newCustomLocalRepo( $overrides );
276require_once RUN_MAINTENANCE_IF_MAIN;
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
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.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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.