Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
RevDelFileList | |
0.00% |
0 / 45 |
|
0.00% |
0 / 10 |
306 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRelationType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRestriction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRevdelConstant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doQuery | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
newItem | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
clearFileOps | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
doPreCommitUpdates | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
doPostCommitUpdates | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 |
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 MediaWiki\Cache\HTMLCacheUpdater; |
23 | use MediaWiki\Context\IContextSource; |
24 | use MediaWiki\FileRepo\File\FileSelectQueryBuilder; |
25 | use MediaWiki\Page\PageIdentity; |
26 | use MediaWiki\Status\Status; |
27 | use Wikimedia\Rdbms\IReadableDatabase; |
28 | use Wikimedia\Rdbms\IResultWrapper; |
29 | use Wikimedia\Rdbms\LBFactory; |
30 | use Wikimedia\Rdbms\SelectQueryBuilder; |
31 | |
32 | /** |
33 | * List for oldimage table items |
34 | */ |
35 | class RevDelFileList extends RevDelList { |
36 | |
37 | protected const SUPPRESS_BIT = File::DELETED_RESTRICTED; |
38 | |
39 | /** @var HTMLCacheUpdater */ |
40 | private $htmlCacheUpdater; |
41 | |
42 | /** @var RepoGroup */ |
43 | private $repoGroup; |
44 | |
45 | /** @var array */ |
46 | public $storeBatch; |
47 | |
48 | /** @var array */ |
49 | public $deleteBatch; |
50 | |
51 | /** @var array */ |
52 | public $cleanupBatch; |
53 | |
54 | /** |
55 | * @param IContextSource $context |
56 | * @param PageIdentity $page |
57 | * @param array $ids |
58 | * @param LBFactory $lbFactory |
59 | * @param HTMLCacheUpdater $htmlCacheUpdater |
60 | * @param RepoGroup $repoGroup |
61 | */ |
62 | public function __construct( |
63 | IContextSource $context, |
64 | PageIdentity $page, |
65 | array $ids, |
66 | LBFactory $lbFactory, |
67 | HTMLCacheUpdater $htmlCacheUpdater, |
68 | RepoGroup $repoGroup |
69 | ) { |
70 | parent::__construct( $context, $page, $ids, $lbFactory ); |
71 | $this->htmlCacheUpdater = $htmlCacheUpdater; |
72 | $this->repoGroup = $repoGroup; |
73 | } |
74 | |
75 | public function getType() { |
76 | return 'oldimage'; |
77 | } |
78 | |
79 | public static function getRelationType() { |
80 | return 'oi_archive_name'; |
81 | } |
82 | |
83 | public static function getRestriction() { |
84 | return 'deleterevision'; |
85 | } |
86 | |
87 | public static function getRevdelConstant() { |
88 | return File::DELETED_FILE; |
89 | } |
90 | |
91 | /** |
92 | * @param IReadableDatabase $db |
93 | * @return IResultWrapper |
94 | */ |
95 | public function doQuery( $db ) { |
96 | $archiveNames = []; |
97 | foreach ( $this->ids as $timestamp ) { |
98 | $archiveNames[] = $timestamp . '!' . $this->page->getDBkey(); |
99 | } |
100 | |
101 | $queryBuilder = FileSelectQueryBuilder::newForOldFile( $db ); |
102 | $queryBuilder |
103 | ->where( [ 'oi_name' => $this->page->getDBkey(), 'oi_archive_name' => $archiveNames ] ) |
104 | ->orderBy( 'oi_timestamp', SelectQueryBuilder::SORT_DESC ); |
105 | return $queryBuilder->caller( __METHOD__ )->fetchResultSet(); |
106 | } |
107 | |
108 | public function newItem( $row ) { |
109 | return new RevDelFileItem( $this, $row ); |
110 | } |
111 | |
112 | public function clearFileOps() { |
113 | $this->deleteBatch = []; |
114 | $this->storeBatch = []; |
115 | $this->cleanupBatch = []; |
116 | } |
117 | |
118 | public function doPreCommitUpdates() { |
119 | $status = Status::newGood(); |
120 | $repo = $this->repoGroup->getLocalRepo(); |
121 | if ( $this->storeBatch ) { |
122 | $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) ); |
123 | } |
124 | if ( !$status->isOK() ) { |
125 | return $status; |
126 | } |
127 | if ( $this->deleteBatch ) { |
128 | $status->merge( $repo->deleteBatch( $this->deleteBatch ) ); |
129 | } |
130 | if ( !$status->isOK() ) { |
131 | // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already |
132 | // modified (but destined for rollback) causes data loss |
133 | return $status; |
134 | } |
135 | if ( $this->cleanupBatch ) { |
136 | $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) ); |
137 | } |
138 | |
139 | return $status; |
140 | } |
141 | |
142 | public function doPostCommitUpdates( array $visibilityChangeMap ) { |
143 | $file = $this->repoGroup->getLocalRepo()->newFile( $this->page ); |
144 | $file->purgeCache(); |
145 | $file->purgeDescription(); |
146 | |
147 | // Purge full images from cache |
148 | $purgeUrls = []; |
149 | foreach ( $this->ids as $timestamp ) { |
150 | $archiveName = $timestamp . '!' . $this->page->getDBkey(); |
151 | $file->purgeOldThumbnails( $archiveName ); |
152 | $purgeUrls[] = $file->getArchiveUrl( $archiveName ); |
153 | } |
154 | |
155 | $this->htmlCacheUpdater->purgeUrls( |
156 | $purgeUrls, |
157 | HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED |
158 | ); |
159 | |
160 | return Status::newGood(); |
161 | } |
162 | |
163 | } |