163 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
165 if ( $deleteCurrent ) {
166 $hashes[
'.'] = $this->file->getSha1();
169 if ( count( $oldRels ) ) {
170 $dbw = $this->file->repo->getMasterDB();
173 [
'oi_archive_name',
'oi_sha1' ],
174 [
'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ),
175 'oi_name' => $this->file->getName() ],
179 foreach (
$res as $row ) {
180 if ( rtrim( $row->oi_sha1,
"\0" ) ===
'' ) {
182 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
183 $props = $this->file->repo->getFileProps( $oldUrl );
185 if ( $props[
'fileExists'] ) {
187 $dbw->update(
'oldimage',
188 [
'oi_sha1' => $props[
'sha1'] ],
189 [
'oi_name' => $this->file->getName(),
'oi_archive_name' => $row->oi_archive_name ],
191 $hashes[$row->oi_archive_name] = $props[
'sha1'];
193 $hashes[$row->oi_archive_name] =
false;
196 $hashes[$row->oi_archive_name] = $row->oi_sha1;
201 $missing = array_diff_key( $this->srcRels,
$hashes );
203 foreach ( $missing as $name => $rel ) {
204 $this->status->error(
'filedelete-old-unregistered', $name );
207 foreach (
$hashes as $name => $hash ) {
209 $this->status->error(
'filedelete-missing', $this->srcRels[$name] );
219 $dbw = $this->file->repo->getMasterDB();
221 $commentStore = MediaWikiServices::getInstance()->getCommentStore();
222 $actorMigration = ActorMigration::newMigration();
224 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
225 $encUserId = $dbw->addQuotes( $this->user->getId() );
226 $encGroup = $dbw->addQuotes(
'deleted' );
227 $ext = $this->file->getExtension();
228 $dotExt =
$ext ===
'' ?
'' :
".$ext";
229 $encExt = $dbw->addQuotes( $dotExt );
230 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
233 if ( $this->suppress ) {
234 $bitfield = RevisionRecord::SUPPRESSED_ALL;
236 $bitfield =
'oi_deleted';
239 if ( $deleteCurrent ) {
240 $tables = [
'image' ];
242 'fa_storage_group' => $encGroup,
243 'fa_storage_key' => $dbw->conditional(
244 [
'img_sha1' =>
'' ],
245 $dbw->addQuotes(
'' ),
246 $dbw->buildConcat( [
"img_sha1", $encExt ] )
248 'fa_deleted_user' => $encUserId,
249 'fa_deleted_timestamp' => $encTimestamp,
250 'fa_deleted' => $this->suppress ? $bitfield : 0,
251 'fa_name' =>
'img_name',
252 'fa_archive_name' =>
'NULL',
253 'fa_size' =>
'img_size',
254 'fa_width' =>
'img_width',
255 'fa_height' =>
'img_height',
256 'fa_metadata' =>
'img_metadata',
257 'fa_bits' =>
'img_bits',
258 'fa_media_type' =>
'img_media_type',
259 'fa_major_mime' =>
'img_major_mime',
260 'fa_minor_mime' =>
'img_minor_mime',
261 'fa_description_id' =>
'img_description_id',
262 'fa_timestamp' =>
'img_timestamp',
263 'fa_sha1' =>
'img_sha1',
264 'fa_actor' =>
'img_actor',
268 $fields += array_map(
269 [ $dbw,
'addQuotes' ],
270 $commentStore->insert( $dbw,
'fa_deleted_reason', $this->reason )
273 $dbw->insertSelect(
'filearchive', $tables, $fields,
274 [
'img_name' => $this->file->getName() ], __METHOD__, [], [], $joins );
277 if ( count( $oldRels ) ) {
280 $fileQuery[
'tables'],
281 $fileQuery[
'fields'],
283 'oi_name' => $this->file->getName(),
284 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) )
291 if (
$res->numRows() ) {
292 $reason = $commentStore->createComment( $dbw, $this->reason );
293 foreach (
$res as $row ) {
294 $comment = $commentStore->getComment(
'oi_description', $row );
298 'fa_storage_group' =>
'deleted',
299 'fa_storage_key' => ( $row->oi_sha1 ===
'' )
301 :
"{$row->oi_sha1}{$dotExt}",
302 'fa_deleted_user' => $this->user->getId(),
303 'fa_deleted_timestamp' => $dbw->timestamp( $now ),
305 'fa_deleted' => $this->suppress ? $bitfield : $row->oi_deleted,
306 'fa_name' => $row->oi_name,
307 'fa_archive_name' => $row->oi_archive_name,
308 'fa_size' => $row->oi_size,
309 'fa_width' => $row->oi_width,
310 'fa_height' => $row->oi_height,
311 'fa_metadata' => $row->oi_metadata,
312 'fa_bits' => $row->oi_bits,
313 'fa_media_type' => $row->oi_media_type,
314 'fa_major_mime' => $row->oi_major_mime,
315 'fa_minor_mime' => $row->oi_minor_mime,
316 'fa_timestamp' => $row->oi_timestamp,
317 'fa_sha1' => $row->oi_sha1
318 ] + $commentStore->insert( $dbw,
'fa_deleted_reason',
$reason )
319 + $commentStore->insert( $dbw,
'fa_description', $comment )
320 + $actorMigration->getInsertValues( $dbw,
'fa_user',
$user );
324 $dbw->insert(
'filearchive', $rowsInsert, __METHOD__ );
329 $dbw = $this->file->repo->getMasterDB();
330 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
332 if ( count( $oldRels ) ) {
333 $dbw->delete(
'oldimage',
335 'oi_name' => $this->file->getName(),
336 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) )
340 if ( $deleteCurrent ) {
341 $dbw->delete(
'image', [
'img_name' => $this->file->getName() ], __METHOD__ );
350 $repo = $this->file->getRepo();
355 $this->deletionBatch = [];
356 $ext = $this->file->getExtension();
357 $dotExt =
$ext ===
'' ?
'' :
".$ext";
359 foreach ( $this->srcRels as $name => $srcRel ) {
361 if ( isset(
$hashes[$name] ) ) {
363 $key = $hash . $dotExt;
364 $dstRel = $repo->getDeletedHashPath( $key ) . $key;
365 $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
369 if ( !$repo->hasSha1Storage() ) {
373 if ( !$checkStatus->isGood() ) {
374 $this->status->merge( $checkStatus );
377 $this->deletionBatch = $checkStatus->value;
380 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
386 if ( !$this->status->isOK() ) {
388 $this->file->unlock();
399 $this->file->unlock();
410 $files = $newBatch = [];
412 foreach ( $batch as $batchItem ) {
413 list( $src, ) = $batchItem;
414 $files[$src] = $this->file->repo->getVirtualUrl(
'public' ) .
'/' . rawurlencode( $src );
417 $result = $this->file->repo->fileExistsBatch( $files );
418 if ( in_array(
null, $result,
true ) ) {
419 return Status::newFatal(
'backend-fail-internal',
420 $this->file->repo->getBackend()->getName() );
423 foreach ( $batch as $batchItem ) {
424 if ( $result[$batchItem[0]] ) {
425 $newBatch[] = $batchItem;
429 return Status::newGood( $newBatch );