82 $dbw = $this->file->repo->getPrimaryDB();
87 $result = $dbw->newSelectQueryBuilder()
88 ->select( [
'oi_archive_name' ] )
90 ->where( [
'oi_name' => $this->file->getName() ] )
91 ->caller( __METHOD__ )->fetchResultSet();
93 $result = $dbw->newSelectQueryBuilder()
94 ->select( [
'oi_archive_name' =>
'fr_archive_name' ] )
95 ->from(
'filerevision' )
96 ->join(
'file',
null,
'fr_file = file_id' )
97 ->where( [
'file_name' => $this->file->getName(),
'file_deleted' => 0,
'file_latest != fr_id' ] )
98 ->caller( __METHOD__ )->fetchResultSet();
101 foreach ( $result as $row ) {
102 $this->
addOld( $row->oi_archive_name );
103 $archiveNames[] = $row->oi_archive_name;
106 return $archiveNames;
131 [ $oldRels, $deleteCurrent ] = $this->
getOldRels();
133 if ( $deleteCurrent ) {
134 $hashes[
'.'] = $this->file->getSha1();
140 if ( count( $oldRels ) ) {
141 $dbw = $this->file->repo->getPrimaryDB();
143 $res = $dbw->newSelectQueryBuilder()
144 ->select( [
'oi_archive_name',
'oi_sha1' ] )
147 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ),
148 'oi_name' => $this->file->getName()
150 ->caller( __METHOD__ )->fetchResultSet();
152 $res = $dbw->newSelectQueryBuilder()
154 'oi_archive_name' =>
'fr_archive_name',
155 'oi_sha1' =>
'fr_sha1'
157 ->from(
'filerevision' )
158 ->join(
'file',
null,
'fr_file = file_id' )
160 'fr_archive_name' => array_map(
'strval', array_keys( $oldRels ) ),
161 'file_name' => $this->file->getName(),
163 'file_latest != fr_id',
165 ->caller( __METHOD__ )->fetchResultSet();
168 foreach ( $res as $row ) {
169 if ( $row->oi_archive_name ===
'' ) {
171 $hashes[$row->oi_archive_name] =
false;
174 if ( rtrim( $row->oi_sha1,
"\0" ) ===
'' ) {
176 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
177 $props = $this->file->repo->getFileProps( $oldUrl );
179 if ( $props[
'fileExists'] ) {
183 $dbw->newUpdateQueryBuilder()
184 ->update(
'oldimage' )
185 ->set( [
'oi_sha1' => $props[
'sha1'] ] )
187 'oi_name' => $this->file->getName(),
188 'oi_archive_name' => $row->oi_archive_name,
190 ->caller( __METHOD__ )->execute();
193 $dbw->newUpdateQueryBuilder()
194 ->update(
'filerevision' )
195 ->set( [
'fr_sha1' => $props[
'sha1'] ] )
197 'fr_file' => $this->file->getFileIdFromName(),
198 'fr_archive_name' => $row->oi_archive_name,
200 ->caller( __METHOD__ )->execute();
202 $hashes[$row->oi_archive_name] = $props[
'sha1'];
204 $hashes[$row->oi_archive_name] =
false;
207 $hashes[$row->oi_archive_name] = $row->oi_sha1;
212 $missing = array_diff_key( $this->srcRels, $hashes );
214 foreach ( $missing as $name => $rel ) {
215 $status->
error(
'filedelete-old-unregistered', $name );
218 foreach ( $hashes as $name => $hash ) {
220 $status->
error(
'filedelete-missing', $this->srcRels[$name] );
221 unset( $hashes[$name] );
230 $dbw = $this->file->repo->getPrimaryDB();
234 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
235 $encUserId = $dbw->addQuotes( $this->user->getId() );
236 $encGroup = $dbw->addQuotes(
'deleted' );
237 $ext = $this->file->getExtension();
238 $dotExt = $ext ===
'' ?
'' :
".$ext";
239 $encExt = $dbw->addQuotes( $dotExt );
240 [ $oldRels, $deleteCurrent ] = $this->getOldRels();
243 if ( $this->suppress ) {
244 $bitfield = RevisionRecord::SUPPRESSED_ALL;
246 $bitfield =
'oi_deleted';
249 if ( $deleteCurrent ) {
250 $tables = [
'image' ];
252 'fa_storage_group' => $encGroup,
253 'fa_storage_key' => $dbw->conditional(
254 [
'img_sha1' =>
'' ],
255 $dbw->addQuotes(
'' ),
256 $dbw->buildConcat( [
"img_sha1", $encExt ] )
258 'fa_deleted_user' => $encUserId,
259 'fa_deleted_timestamp' => $encTimestamp,
260 'fa_deleted' => $this->suppress ? $bitfield : 0,
261 'fa_name' =>
'img_name',
262 'fa_archive_name' =>
'NULL',
263 'fa_size' =>
'img_size',
264 'fa_width' =>
'img_width',
265 'fa_height' =>
'img_height',
266 'fa_metadata' =>
'img_metadata',
267 'fa_bits' =>
'img_bits',
268 'fa_media_type' =>
'img_media_type',
269 'fa_major_mime' =>
'img_major_mime',
270 'fa_minor_mime' =>
'img_minor_mime',
271 'fa_description_id' =>
'img_description_id',
272 'fa_timestamp' =>
'img_timestamp',
273 'fa_sha1' =>
'img_sha1',
274 'fa_actor' =>
'img_actor',
278 $fields += array_map(
279 $dbw->addQuotes( ... ),
280 $commentStore->insert( $dbw,
'fa_deleted_reason', $this->reason )
283 $dbw->insertSelect(
'filearchive', $tables, $fields,
284 [
'img_name' => $this->file->getName() ], __METHOD__, [
'IGNORE' ], [], $joins );
287 if ( count( $oldRels ) ) {
291 ->where( [
'oi_name' => $this->file->getName() ] )
292 ->andWhere( [
'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ) ] );
293 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
294 if ( $res->numRows() ) {
295 $reason = $commentStore->createComment( $dbw, $this->reason );
297 foreach ( $res as $row ) {
298 $comment = $commentStore->getComment(
'oi_description', $row );
301 'fa_storage_group' =>
'deleted',
302 'fa_storage_key' => ( $row->oi_sha1 ===
'' )
304 :
"{$row->oi_sha1}{$dotExt}",
305 'fa_deleted_user' => $this->user->getId(),
306 'fa_deleted_timestamp' => $dbw->timestamp( $now ),
308 'fa_deleted' => $this->suppress ? $bitfield : $row->oi_deleted,
309 'fa_name' => $row->oi_name,
310 'fa_archive_name' => $row->oi_archive_name,
311 'fa_size' => $row->oi_size,
312 'fa_width' => $row->oi_width,
313 'fa_height' => $row->oi_height,
314 'fa_metadata' => $row->oi_metadata,
315 'fa_bits' => $row->oi_bits,
316 'fa_media_type' => $row->oi_media_type,
317 'fa_major_mime' => $row->oi_major_mime,
318 'fa_minor_mime' => $row->oi_minor_mime,
319 'fa_actor' => $row->oi_actor,
320 'fa_timestamp' => $row->oi_timestamp,
321 'fa_sha1' => $row->oi_sha1
322 ] + $commentStore->insert( $dbw,
'fa_deleted_reason', $reason )
323 + $commentStore->insert( $dbw,
'fa_description', $comment );
325 $dbw->newInsertQueryBuilder()
326 ->insertInto(
'filearchive' )
328 ->rows( $rowsInsert )
329 ->caller( __METHOD__ )->execute();
399 $repo = $this->file->getRepo();
400 $lockStatus = $this->file->acquireFileLock();
401 if ( !$lockStatus->isOK() ) {
404 $unlockScope =
new ScopedCallback(
function () {
405 $this->file->releaseFileLock();
408 $status = $this->file->repo->
newGood();
410 $hashes = $this->getHashes( $status );
411 $this->deletionBatch = [];
412 $ext = $this->file->getExtension();
413 $dotExt = $ext ===
'' ?
'' :
".$ext";
415 foreach ( $this->srcRels as $name => $srcRel ) {
417 if ( isset( $hashes[$name] ) ) {
418 $hash = $hashes[$name];
419 $key = $hash . $dotExt;
420 $dstRel = $repo->getDeletedHashPath( $key ) . $key;
421 $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
425 if ( !$repo->hasSha1Storage() ) {
428 $checkStatus = $this->removeNonexistentFiles( $this->deletionBatch );
429 if ( !$checkStatus->isGood() ) {
430 $status->merge( $checkStatus );
433 $this->deletionBatch = $checkStatus->value;
436 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
437 if ( !$status->isGood() ) {
438 $status->merge( $status );
442 if ( !$status->isOK() ) {
447 $dbw = $this->file->repo->getPrimaryDB();
449 $dbw->startAtomic( __METHOD__ );
452 $this->doDBInserts();
454 $this->doDBDeletes();
458 $dbw->endAtomic( __METHOD__ );
461 ScopedCallback::consume( $unlockScope );
474 foreach ( $batch as [ $src, ] ) {
475 $files[$src] = $this->file->repo->getVirtualUrl(
'public' ) .
'/' . rawurlencode( $src );
478 $result = $this->file->repo->fileExistsBatch( $files );
479 if ( in_array(
null, $result,
true ) ) {
480 return Status::newFatal(
'backend-fail-internal',
481 $this->file->repo->getBackend()->getName() );
485 foreach ( $batch as $batchItem ) {
486 if ( $result[$batchItem[0]] ) {
487 $newBatch[] = $batchItem;
491 return Status::newGood( $newBatch );