74 $this->oldHash = $this->file->repo->getHashPath( $this->file->getName() );
75 $this->newHash = $this->file->repo->getHashPath( $this->target->getDBkey() );
76 $this->oldName = $this->file->getName();
77 $this->newName = $this->file->repo->getNameFromTitle( $this->target );
95 $archiveBase =
'archive';
100 $result = $this->db->select(
'oldimage',
101 [
'oi_archive_name',
'oi_deleted' ],
102 [
'oi_name' => $this->oldName ],
104 [
'LOCK IN SHARE MODE' ]
107 foreach ( $result as $row ) {
108 $archiveNames[] = $row->oi_archive_name;
110 $bits = explode(
'!',
$oldName, 2 );
112 if ( count( $bits ) != 2 ) {
113 wfDebug(
"Old file name missing !: '$oldName'" );
117 list( $timestamp, $filename ) = $bits;
119 if ( $this->oldName != $filename ) {
120 wfDebug(
"Old file name doesn't match: '$oldName'" );
127 if ( $row->oi_deleted & File::DELETED_FILE ) {
132 "{$archiveBase}/{$this->oldHash}{$oldName}",
133 "{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
137 return $archiveNames;
145 $repo = $this->file->repo;
146 $status = $repo->newGood();
147 $destFile = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
148 ->newFile( $this->target );
155 if ( !$checkStatus->isGood() ) {
157 $this->file->unlock();
158 $status->merge( $checkStatus );
161 $triplets = $checkStatus->value;
165 if ( !$statusDb->isGood() ) {
167 $this->file->unlock();
168 $statusDb->setOK(
false );
173 if ( !$repo->hasSha1Storage() ) {
178 wfDebugLog(
'imagemove',
"Moved files for {$this->file->getName()}: " .
179 "{$statusMove->successCount} successes, {$statusMove->failCount} failures" );
180 if ( !$statusMove->isGood() ) {
184 $this->file->unlock();
185 wfDebugLog(
'imagemove',
"Error in moving files: "
186 . $statusMove->getWikiText(
false,
false,
'en' ) );
187 $statusMove->setOK(
false );
191 $status->merge( $statusMove );
197 wfDebugLog(
'imagemove',
"Renamed {$this->file->getName()} in database: " .
198 "{$statusDb->successCount} successes, {$statusDb->failCount} failures" );
201 $this->file->unlock();
206 $status->merge( $statusDb );
218 $repo = $this->file->repo;
219 $status = $repo->newGood();
224 [
'img_name' => $this->oldName ],
227 $oldRowCount = $dbw->lockForUpdate(
229 [
'oi_name' => $this->oldName ],
234 $status->successCount++;
236 $status->failCount++;
238 $status->successCount += $oldRowCount;
242 $status->failCount += max( 0, $this->oldCount - $oldRowCount );
243 if ( $status->failCount ) {
244 $status->error(
'imageinvalidfilename' );
260 [
'img_name' => $this->newName ],
261 [
'img_name' => $this->oldName ],
269 'oi_name' => $this->newName,
270 'oi_archive_name = ' . $dbw->strreplace(
'oi_archive_name',
271 $dbw->addQuotes( $this->oldName ), $dbw->addQuotes( $this->newName ) ),
273 [
'oi_name' => $this->oldName ],
283 $moves = array_merge( [ $this->cur ], $this->olds );
286 foreach ( $moves as $move ) {
288 $srcUrl = $this->file->repo->getVirtualUrl() .
'/public/' . rawurlencode( $move[0] );
289 $triplets[] = [ $srcUrl,
'public', $move[1] ];
292 "Generated move triplet for {$this->file->getName()}: {$srcUrl} :: public :: {$move[1]}"
307 foreach ( $triplets as
$file ) {
311 $result = $this->file->repo->fileExistsBatch( $files );
312 if ( in_array(
null, $result,
true ) ) {
313 return Status::newFatal(
'backend-fail-internal',
314 $this->file->repo->getBackend()->getName() );
317 $filteredTriplets = [];
318 foreach ( $triplets as
$file ) {
319 if ( $result[
$file[0]] ) {
320 $filteredTriplets[] =
$file;
322 wfDebugLog(
'imagemove',
"File {$file[0]} does not exist" );
326 return Status::newGood( $filteredTriplets );
337 foreach ( $triplets as $triplet ) {
339 $pairs[] = [ $triplet[1], $triplet[2] ];
342 $this->file->repo->cleanupBatch( $pairs );
353 foreach ( $triplets as $triplet ) {
354 $files[] = $triplet[0];
357 $this->file->repo->cleanupBatch( $files );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Helper class for file movement.
cleanupTarget( $triplets)
Cleanup a partially moved array of triplets by deleting the target files.
addOlds()
Add the old versions of the image to the batch.
doDBUpdates()
Do the database updates and return a new Status indicating how many rows where updated.
getMoveTriplets()
Generate triplets for FileRepo::storeBatch().
execute()
Perform the move.
verifyDBUpdates()
Verify the database updates and return a new Status indicating how many rows would be updated.
removeNonexistentFiles( $triplets)
Removes non-existent files from move batch.
__construct(LocalFile $file, Title $target)
addCurrent()
Add the current image to the batch.
cleanupSource( $triplets)
Cleanup a fully moved array of triplets by deleting the source files.
Class to represent a local file in the wiki's own database.
Represents a title within MediaWiki.