82 $dbw = $this->file->repo->getPrimaryDB();
83 $result = $dbw->newSelectQueryBuilder()
84 ->select( [
'oi_archive_name' ] )
86 ->where( [
'oi_name' => $this->file->getName() ] )
87 ->caller( __METHOD__ )->fetchResultSet();
89 foreach ( $result as $row ) {
90 $this->
addOld( $row->oi_archive_name );
91 $archiveNames[] = $row->oi_archive_name;
119 [ $oldRels, $deleteCurrent ] = $this->
getOldRels();
121 if ( $deleteCurrent ) {
122 $hashes[
'.'] = $this->file->getSha1();
125 if ( count( $oldRels ) ) {
126 $dbw = $this->file->repo->getPrimaryDB();
127 $res = $dbw->newSelectQueryBuilder()
128 ->select( [
'oi_archive_name',
'oi_sha1' ] )
131 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ),
132 'oi_name' => $this->file->getName()
134 ->caller( __METHOD__ )->fetchResultSet();
136 foreach ( $res as $row ) {
137 if ( $row->oi_archive_name ===
'' ) {
139 $hashes[$row->oi_archive_name] =
false;
142 if ( rtrim( $row->oi_sha1,
"\0" ) ===
'' ) {
144 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
145 $props = $this->file->repo->getFileProps( $oldUrl );
147 if ( $props[
'fileExists'] ) {
149 $dbw->newUpdateQueryBuilder()
150 ->update(
'oldimage' )
151 ->set( [
'oi_sha1' => $props[
'sha1'] ] )
153 'oi_name' => $this->file->getName(),
154 'oi_archive_name' => $row->oi_archive_name,
156 ->caller( __METHOD__ )->execute();
157 $hashes[$row->oi_archive_name] = $props[
'sha1'];
159 $hashes[$row->oi_archive_name] =
false;
162 $hashes[$row->oi_archive_name] = $row->oi_sha1;
167 $missing = array_diff_key( $this->srcRels, $hashes );
169 foreach ( $missing as $name => $rel ) {
170 $status->
error(
'filedelete-old-unregistered', $name );
173 foreach ( $hashes as $name => $hash ) {
175 $status->
error(
'filedelete-missing', $this->srcRels[$name] );
176 unset( $hashes[$name] );
185 $dbw = $this->file->repo->getPrimaryDB();
189 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
190 $encUserId = $dbw->addQuotes( $this->user->getId() );
191 $encGroup = $dbw->addQuotes(
'deleted' );
192 $ext = $this->file->getExtension();
193 $dotExt = $ext ===
'' ?
'' :
".$ext";
194 $encExt = $dbw->addQuotes( $dotExt );
195 [ $oldRels, $deleteCurrent ] = $this->getOldRels();
198 if ( $this->suppress ) {
199 $bitfield = RevisionRecord::SUPPRESSED_ALL;
201 $bitfield =
'oi_deleted';
204 if ( $deleteCurrent ) {
205 $tables = [
'image' ];
207 'fa_storage_group' => $encGroup,
208 'fa_storage_key' => $dbw->conditional(
209 [
'img_sha1' =>
'' ],
210 $dbw->addQuotes(
'' ),
211 $dbw->buildConcat( [
"img_sha1", $encExt ] )
213 'fa_deleted_user' => $encUserId,
214 'fa_deleted_timestamp' => $encTimestamp,
215 'fa_deleted' => $this->suppress ? $bitfield : 0,
216 'fa_name' =>
'img_name',
217 'fa_archive_name' =>
'NULL',
218 'fa_size' =>
'img_size',
219 'fa_width' =>
'img_width',
220 'fa_height' =>
'img_height',
221 'fa_metadata' =>
'img_metadata',
222 'fa_bits' =>
'img_bits',
223 'fa_media_type' =>
'img_media_type',
224 'fa_major_mime' =>
'img_major_mime',
225 'fa_minor_mime' =>
'img_minor_mime',
226 'fa_description_id' =>
'img_description_id',
227 'fa_timestamp' =>
'img_timestamp',
228 'fa_sha1' =>
'img_sha1',
229 'fa_actor' =>
'img_actor',
233 $fields += array_map(
234 $dbw->addQuotes( ... ),
235 $commentStore->insert( $dbw,
'fa_deleted_reason', $this->reason )
238 $dbw->insertSelect(
'filearchive', $tables, $fields,
239 [
'img_name' => $this->file->getName() ], __METHOD__, [
'IGNORE' ], [], $joins );
242 if ( count( $oldRels ) ) {
246 ->where( [
'oi_name' => $this->file->getName() ] )
247 ->andWhere( [
'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ) ] );
248 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
249 if ( $res->numRows() ) {
250 $reason = $commentStore->createComment( $dbw, $this->reason );
252 foreach ( $res as $row ) {
253 $comment = $commentStore->getComment(
'oi_description', $row );
256 'fa_storage_group' =>
'deleted',
257 'fa_storage_key' => ( $row->oi_sha1 ===
'' )
259 :
"{$row->oi_sha1}{$dotExt}",
260 'fa_deleted_user' => $this->user->getId(),
261 'fa_deleted_timestamp' => $dbw->timestamp( $now ),
263 'fa_deleted' => $this->suppress ? $bitfield : $row->oi_deleted,
264 'fa_name' => $row->oi_name,
265 'fa_archive_name' => $row->oi_archive_name,
266 'fa_size' => $row->oi_size,
267 'fa_width' => $row->oi_width,
268 'fa_height' => $row->oi_height,
269 'fa_metadata' => $row->oi_metadata,
270 'fa_bits' => $row->oi_bits,
271 'fa_media_type' => $row->oi_media_type,
272 'fa_major_mime' => $row->oi_major_mime,
273 'fa_minor_mime' => $row->oi_minor_mime,
274 'fa_actor' => $row->oi_actor,
275 'fa_timestamp' => $row->oi_timestamp,
276 'fa_sha1' => $row->oi_sha1
277 ] + $commentStore->insert( $dbw,
'fa_deleted_reason', $reason )
278 + $commentStore->insert( $dbw,
'fa_description', $comment );
280 $dbw->newInsertQueryBuilder()
281 ->insertInto(
'filearchive' )
283 ->rows( $rowsInsert )
284 ->caller( __METHOD__ )->execute();
350 $repo = $this->file->getRepo();
351 $lockStatus = $this->file->acquireFileLock();
352 if ( !$lockStatus->isOK() ) {
355 $unlockScope =
new ScopedCallback(
function () {
356 $this->file->releaseFileLock();
359 $status = $this->file->repo->
newGood();
361 $hashes = $this->getHashes( $status );
362 $this->deletionBatch = [];
363 $ext = $this->file->getExtension();
364 $dotExt = $ext ===
'' ?
'' :
".$ext";
366 foreach ( $this->srcRels as $name => $srcRel ) {
368 if ( isset( $hashes[$name] ) ) {
369 $hash = $hashes[$name];
370 $key = $hash . $dotExt;
371 $dstRel = $repo->getDeletedHashPath( $key ) . $key;
372 $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
376 if ( !$repo->hasSha1Storage() ) {
379 $checkStatus = $this->removeNonexistentFiles( $this->deletionBatch );
380 if ( !$checkStatus->isGood() ) {
381 $status->merge( $checkStatus );
384 $this->deletionBatch = $checkStatus->value;
387 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
388 if ( !$status->isGood() ) {
389 $status->merge( $status );
393 if ( !$status->isOK() ) {
398 $dbw = $this->file->repo->getPrimaryDB();
400 $dbw->startAtomic( __METHOD__ );
403 $this->doDBInserts();
405 $this->doDBDeletes();
409 $dbw->endAtomic( __METHOD__ );
412 ScopedCallback::consume( $unlockScope );
425 foreach ( $batch as [ $src, ] ) {
426 $files[$src] = $this->file->repo->getVirtualUrl(
'public' ) .
'/' . rawurlencode( $src );
429 $result = $this->file->repo->fileExistsBatch( $files );
430 if ( in_array(
null, $result,
true ) ) {
431 return Status::newFatal(
'backend-fail-internal',
432 $this->file->repo->getBackend()->getName() );
436 foreach ( $batch as $batchItem ) {
437 if ( $result[$batchItem[0]] ) {
438 $newBatch[] = $batchItem;
442 return Status::newGood( $newBatch );