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' \n" );
117 list( $timestamp, $filename ) = $bits;
119 if ( $this->oldName != $filename ) {
120 wfDebug(
"Old file name doesn't match: '$oldName' \n" );
132 "{$archiveBase}/{$this->oldHash}{$oldName}",
133 "{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
137 return $archiveNames;
145 $repo = $this->file->repo;
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 );
197 wfDebugLog(
'imagemove',
"Renamed {$this->file->getName()} in database: " .
198 "{$statusDb->successCount} successes, {$statusDb->failCount} failures" );
201 $this->file->unlock();
218 $repo = $this->file->repo;
224 [
'img_name' => $this->oldName ],
227 $oldRowCount = $dbw->lockForUpdate(
229 [
'oi_name' => $this->oldName ],
238 $status->successCount += $oldRowCount;
242 $status->failCount += max( 0, $this->oldCount - $oldRowCount );
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 ) ) {
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" );
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 );