131 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
133 if ( $deleteCurrent ) {
134 $hashes[
'.'] = $this->file->getSha1();
137 if ( count( $oldRels ) ) {
138 $dbw = $this->file->repo->getPrimaryDB();
141 [
'oi_archive_name',
'oi_sha1' ],
142 [
'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) ),
143 'oi_name' => $this->file->getName() ],
147 foreach (
$res as $row ) {
148 if ( rtrim( $row->oi_sha1,
"\0" ) ===
'' ) {
150 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
151 $props = $this->file->repo->getFileProps( $oldUrl );
153 if ( $props[
'fileExists'] ) {
155 $dbw->update(
'oldimage',
156 [
'oi_sha1' => $props[
'sha1'] ],
157 [
'oi_name' => $this->file->getName(),
'oi_archive_name' => $row->oi_archive_name ],
159 $hashes[$row->oi_archive_name] = $props[
'sha1'];
161 $hashes[$row->oi_archive_name] =
false;
164 $hashes[$row->oi_archive_name] = $row->oi_sha1;
169 $missing = array_diff_key( $this->srcRels,
$hashes );
171 foreach ( $missing as $name => $rel ) {
172 $this->status->error(
'filedelete-old-unregistered', $name );
175 foreach (
$hashes as $name => $hash ) {
177 $this->status->error(
'filedelete-missing', $this->srcRels[$name] );
187 $dbw = $this->file->repo->getPrimaryDB();
189 $commentStore = MediaWikiServices::getInstance()->getCommentStore();
191 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $now ) );
192 $encUserId = $dbw->addQuotes( $this->user->getId() );
193 $encGroup = $dbw->addQuotes(
'deleted' );
194 $ext = $this->file->getExtension();
195 $dotExt =
$ext ===
'' ?
'' :
".$ext";
196 $encExt = $dbw->addQuotes( $dotExt );
197 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
200 if ( $this->suppress ) {
201 $bitfield = RevisionRecord::SUPPRESSED_ALL;
203 $bitfield =
'oi_deleted';
206 if ( $deleteCurrent ) {
207 $tables = [
'image' ];
209 'fa_storage_group' => $encGroup,
210 'fa_storage_key' => $dbw->conditional(
211 [
'img_sha1' =>
'' ],
212 $dbw->addQuotes(
'' ),
213 $dbw->buildConcat( [
"img_sha1", $encExt ] )
215 'fa_deleted_user' => $encUserId,
216 'fa_deleted_timestamp' => $encTimestamp,
217 'fa_deleted' => $this->suppress ? $bitfield : 0,
218 'fa_name' =>
'img_name',
219 'fa_archive_name' =>
'NULL',
220 'fa_size' =>
'img_size',
221 'fa_width' =>
'img_width',
222 'fa_height' =>
'img_height',
223 'fa_metadata' =>
'img_metadata',
224 'fa_bits' =>
'img_bits',
225 'fa_media_type' =>
'img_media_type',
226 'fa_major_mime' =>
'img_major_mime',
227 'fa_minor_mime' =>
'img_minor_mime',
228 'fa_description_id' =>
'img_description_id',
229 'fa_timestamp' =>
'img_timestamp',
230 'fa_sha1' =>
'img_sha1',
231 'fa_actor' =>
'img_actor',
235 $fields += array_map(
236 [ $dbw,
'addQuotes' ],
237 $commentStore->insert( $dbw,
'fa_deleted_reason', $this->reason )
240 $dbw->insertSelect(
'filearchive', $tables, $fields,
241 [
'img_name' => $this->file->getName() ], __METHOD__, [], [], $joins );
244 if ( count( $oldRels ) ) {
247 $fileQuery[
'tables'],
248 $fileQuery[
'fields'],
250 'oi_name' => $this->file->getName(),
251 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) )
258 if (
$res->numRows() ) {
259 $reason = $commentStore->createComment( $dbw, $this->reason );
260 foreach (
$res as $row ) {
261 $comment = $commentStore->getComment(
'oi_description', $row );
265 'fa_storage_group' =>
'deleted',
266 'fa_storage_key' => ( $row->oi_sha1 ===
'' )
268 :
"{$row->oi_sha1}{$dotExt}",
269 'fa_deleted_user' => $this->user->getId(),
270 'fa_deleted_timestamp' => $dbw->timestamp( $now ),
272 'fa_deleted' => $this->suppress ? $bitfield : $row->oi_deleted,
273 'fa_name' => $row->oi_name,
274 'fa_archive_name' => $row->oi_archive_name,
275 'fa_size' => $row->oi_size,
276 'fa_width' => $row->oi_width,
277 'fa_height' => $row->oi_height,
278 'fa_metadata' => $row->oi_metadata,
279 'fa_bits' => $row->oi_bits,
280 'fa_media_type' => $row->oi_media_type,
281 'fa_major_mime' => $row->oi_major_mime,
282 'fa_minor_mime' => $row->oi_minor_mime,
283 'fa_actor' => $row->oi_actor,
284 'fa_timestamp' => $row->oi_timestamp,
285 'fa_sha1' => $row->oi_sha1
286 ] + $commentStore->insert( $dbw,
'fa_deleted_reason',
$reason )
287 + $commentStore->insert( $dbw,
'fa_description', $comment );
291 $dbw->insert(
'filearchive', $rowsInsert, __METHOD__ );
296 $dbw = $this->file->repo->getPrimaryDB();
297 list( $oldRels, $deleteCurrent ) = $this->
getOldRels();
299 if ( count( $oldRels ) ) {
300 $dbw->delete(
'oldimage',
302 'oi_name' => $this->file->getName(),
303 'oi_archive_name' => array_map(
'strval', array_keys( $oldRels ) )
307 if ( $deleteCurrent ) {
308 $dbw->delete(
'image', [
'img_name' => $this->file->getName() ], __METHOD__ );
317 $repo = $this->file->getRepo();
322 $this->deletionBatch = [];
323 $ext = $this->file->getExtension();
324 $dotExt =
$ext ===
'' ?
'' :
".$ext";
326 foreach ( $this->srcRels as $name => $srcRel ) {
328 if ( isset(
$hashes[$name] ) ) {
330 $key = $hash . $dotExt;
331 $dstRel = $repo->getDeletedHashPath( $key ) . $key;
332 $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
336 if ( !$repo->hasSha1Storage() ) {
340 if ( !$checkStatus->isGood() ) {
341 $this->status->merge( $checkStatus );
344 $this->deletionBatch = $checkStatus->value;
347 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
353 if ( !$this->status->isOK() ) {
355 $this->file->unlock();
366 $this->file->unlock();
377 $files = $newBatch = [];
379 foreach ( $batch as [ $src, ] ) {
380 $files[$src] = $this->file->repo->getVirtualUrl(
'public' ) .
'/' . rawurlencode( $src );
383 $result = $this->file->repo->fileExistsBatch( $files );
384 if ( in_array(
null, $result,
true ) ) {
385 return Status::newFatal(
'backend-fail-internal',
386 $this->file->repo->getBackend()->getName() );
389 foreach ( $batch as $batchItem ) {
390 if ( $result[$batchItem[0]] ) {
391 $newBatch[] = $batchItem;
395 return Status::newGood( $newBatch );