3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup RevisionDelete
22 use Wikimedia\Rdbms\IDatabase
;
25 * List for oldimage table items
27 class RevDelFileList
extends RevDelList
{
37 public function getType() {
41 public static function getRelationType() {
42 return 'oi_archive_name';
45 public static function getRestriction() {
46 return 'deleterevision';
49 public static function getRevdelConstant() {
50 return File
::DELETED_FILE
;
54 * @param IDatabase $db
57 public function doQuery( $db ) {
59 foreach ( $this->ids
as $timestamp ) {
60 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
65 OldLocalFile
::selectFields(),
67 'oi_name' => $this->title
->getDBkey(),
68 'oi_archive_name' => $archiveNames
71 [ 'ORDER BY' => 'oi_timestamp DESC' ]
75 public function newItem( $row ) {
76 return new RevDelFileItem( $this, $row );
79 public function clearFileOps() {
80 $this->deleteBatch
= [];
81 $this->storeBatch
= [];
82 $this->cleanupBatch
= [];
85 public function doPreCommitUpdates() {
86 $status = Status
::newGood();
87 $repo = RepoGroup
::singleton()->getLocalRepo();
88 if ( $this->storeBatch
) {
89 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
91 if ( !$status->isOK() ) {
94 if ( $this->deleteBatch
) {
95 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
97 if ( !$status->isOK() ) {
98 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
99 // modified (but destined for rollback) causes data loss
102 if ( $this->cleanupBatch
) {
103 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
109 public function doPostCommitUpdates( array $visibilityChangeMap ) {
110 $file = wfLocalFile( $this->title
);
112 $file->purgeDescription();
114 // Purge full images from cache
116 foreach ( $this->ids
as $timestamp ) {
117 $archiveName = $timestamp . '!' . $this->title
->getDBkey();
118 $file->purgeOldThumbnails( $archiveName );
119 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
121 DeferredUpdates
::addUpdate(
122 new CdnCacheUpdate( $purgeUrls ),
123 DeferredUpdates
::PRESEND
126 return Status
::newGood();
129 public function getSuppressBit() {
130 return File
::DELETED_RESTRICTED
;