Merge "Add attributes parameter to ShowSearchHitTitle"
[lhc/web/wiklou.git] / includes / revisiondelete / RevDelFileList.php
1 <?php
2 /**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup RevisionDelete
20 */
21
22 use Wikimedia\Rdbms\IDatabase;
23
24 /**
25 * List for oldimage table items
26 */
27 class RevDelFileList extends RevDelList {
28 /** @var array */
29 public $storeBatch;
30
31 /** @var array */
32 public $deleteBatch;
33
34 /** @var array */
35 public $cleanupBatch;
36
37 public function getType() {
38 return 'oldimage';
39 }
40
41 public static function getRelationType() {
42 return 'oi_archive_name';
43 }
44
45 public static function getRestriction() {
46 return 'deleterevision';
47 }
48
49 public static function getRevdelConstant() {
50 return File::DELETED_FILE;
51 }
52
53 /**
54 * @param IDatabase $db
55 * @return mixed
56 */
57 public function doQuery( $db ) {
58 $archiveNames = [];
59 foreach ( $this->ids as $timestamp ) {
60 $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
61 }
62
63 $oiQuery = OldLocalFile::getQueryInfo();
64 return $db->select(
65 $oiQuery['tables'],
66 $oiQuery['fields'],
67 [
68 'oi_name' => $this->title->getDBkey(),
69 'oi_archive_name' => $archiveNames
70 ],
71 __METHOD__,
72 [ 'ORDER BY' => 'oi_timestamp DESC' ],
73 $oiQuery['joins']
74 );
75 }
76
77 public function newItem( $row ) {
78 return new RevDelFileItem( $this, $row );
79 }
80
81 public function clearFileOps() {
82 $this->deleteBatch = [];
83 $this->storeBatch = [];
84 $this->cleanupBatch = [];
85 }
86
87 public function doPreCommitUpdates() {
88 $status = Status::newGood();
89 $repo = RepoGroup::singleton()->getLocalRepo();
90 if ( $this->storeBatch ) {
91 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
92 }
93 if ( !$status->isOK() ) {
94 return $status;
95 }
96 if ( $this->deleteBatch ) {
97 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
98 }
99 if ( !$status->isOK() ) {
100 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
101 // modified (but destined for rollback) causes data loss
102 return $status;
103 }
104 if ( $this->cleanupBatch ) {
105 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
106 }
107
108 return $status;
109 }
110
111 public function doPostCommitUpdates( array $visibilityChangeMap ) {
112 $file = wfLocalFile( $this->title );
113 $file->purgeCache();
114 $file->purgeDescription();
115
116 // Purge full images from cache
117 $purgeUrls = [];
118 foreach ( $this->ids as $timestamp ) {
119 $archiveName = $timestamp . '!' . $this->title->getDBkey();
120 $file->purgeOldThumbnails( $archiveName );
121 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
122 }
123 DeferredUpdates::addUpdate(
124 new CdnCacheUpdate( $purgeUrls ),
125 DeferredUpdates::PRESEND
126 );
127
128 return Status::newGood();
129 }
130
131 public function getSuppressBit() {
132 return File::DELETED_RESTRICTED;
133 }
134 }