Debian Codegraph @

includes/deferred/HtmlFileCacheUpdate.php

raw symbols SCIP
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 */
20
21 namespace MediaWiki\Deferred;
22
23 use HTMLFileCache;
24 use MediaWiki\Cache\CacheKeyHelper;
25 use MediaWiki\Page\PageIdentity;
26 use Wikimedia\Assert\Assert;
27
28 /**
29 * HTMLFileCache purge update for a set of titles
30 *
31 * @ingroup Cache
32 * @since 1.35
33 */
34 class HtmlFileCacheUpdate implements DeferrableUpdate, MergeableUpdate {
35 /** @var PageIdentity[] List of pages */
36 private $pages;
37
38 /**
39 * @param PageIdentity[] $pages List of pages
40 */
41 private function __construct( array $pages ) {
42 $this->pages = $pages;
43 }
44
45 public function merge( MergeableUpdate $update ) {
46 /** @var self $update */
47 Assert::parameterType( __CLASS__, $update, '$update' );
48 '@phan-var self $update';
49
50 $this->pages = array_merge( $this->pages, $update->pages );
51 }
52
53 /**
54 * @since 1.37
55 * @param iterable<PageIdentity> $pages PageIdentity instances
56 *
57 * @return HtmlFileCacheUpdate
58 */
59 public static function newFromPages( $pages ) {
60 $pagesByKey = [];
61 foreach ( $pages as $pg ) {
62 $key = CacheKeyHelper::getKeyForPage( $pg );
63 $pagesByKey[$key] = $pg;
64 }
65
66 return new self( $pagesByKey );
67 }
68
69 public function doUpdate() {
70 foreach ( $this->pages as $pg ) {
71 HTMLFileCache::clearFileCache( $pg );
72 }
73 }
74 }
75
76 /** @deprecated class alias since 1.42 */
77 class_alias( HtmlFileCacheUpdate::class, 'HtmlFileCacheUpdate' );