119 $force = $this->hasOption(
'force' );
120 $brokenOnly = $this->hasOption(
'broken-only' );
121 $verbose = $this->hasOption(
'verbose' );
122 $start = $this->getOption(
'start',
false );
123 $split = $this->hasOption(
'split' );
124 $sleep = (int)$this->getOption(
'sleep', 0 );
125 $reserialize = $this->hasOption(
'convert-to-json' );
126 $oldimage = $this->hasOption(
'oldimage' );
128 $dbw = $this->getPrimaryDB();
130 $fieldPrefix =
'oi_';
131 $queryBuilderTemplate = FileSelectQueryBuilder::newForOldFile( $dbw );
133 $fieldPrefix =
'img_';
134 $queryBuilderTemplate = FileSelectQueryBuilder::newForFile( $dbw );
140 $batchSize = intval( $this->getBatchSize() );
141 if ( $batchSize <= 0 ) {
142 $this->fatalError(
"Batch size is too low...", 12 );
144 $repo = $this->newLocalRepo( $force, $brokenOnly, $reserialize, $split );
145 $this->setConditions( $dbw, $queryBuilderTemplate, $fieldPrefix );
146 $queryBuilderTemplate
147 ->orderBy( $fieldPrefix .
'name', SelectQueryBuilder::SORT_ASC )
148 ->limit( $batchSize );
150 $batchCondition = [];
152 if ( $start !==
false ) {
153 $batchCondition[] = $dbw->
expr( $fieldPrefix .
'name',
'>=', $start );
156 $queryBuilder = clone $queryBuilderTemplate;
157 $res = $queryBuilder->
andWhere( $batchCondition )
158 ->caller( __METHOD__ )->fetchResultSet();
159 $nameField = $fieldPrefix .
'name';
160 if ( $res->numRows() > 0 ) {
161 $row1 = $res->current();
162 $this->output(
"Processing next {$res->numRows()} row(s) starting with {$row1->$nameField}.\n" );
166 foreach ( $res as $row ) {
169 $file = $repo->newFileFromRow( $row );
170 $file->maybeUpgradeRow();
171 if ( $file->getUpgraded() ) {
174 $this->output(
"Refreshed File:{$row->$nameField}.\n" );
180 $this->output(
"Forcibly refreshed File:{$row->$nameField}.\n" );
184 $this->output(
"Skipping File:{$row->$nameField}.\n" );
188 }
catch ( Exception $e ) {
189 $this->output(
"{$row->$nameField} failed. {$e->getMessage()}\n" );
192 if ( $res->numRows() > 0 ) {
194 $batchCondition = [ $dbw->
expr( $fieldPrefix .
'name',
'>', $row->$nameField ) ];
196 $this->waitForReplication();
200 }
while ( $res->numRows() === $batchSize );
202 $total = $upgraded + $leftAlone;
204 $this->output(
"\nFinished refreshing file metadata for $total files. "
205 .
"$upgraded needed to be refreshed, $leftAlone did not need to "
206 .
"be but were refreshed anyways, and $error refreshes were suspicious.\n" );
208 $this->output(
"\nFinished refreshing file metadata for $total files. "
209 .
"$upgraded were refreshed, $leftAlone were already up to date, "
210 .
"and $error refreshes were suspicious.\n" );