Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
HtmlFileCacheUpdate
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 merge
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 newFromPages
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 doUpdate
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
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 */
20
21namespace MediaWiki\Deferred;
22
23use HTMLFileCache;
24use MediaWiki\Cache\CacheKeyHelper;
25use MediaWiki\Page\PageIdentity;
26use Wikimedia\Assert\Assert;
27
28/**
29 * HTMLFileCache purge update for a set of titles
30 *
31 * @ingroup Cache
32 * @since 1.35
33 */
34class 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 */
77class_alias( HtmlFileCacheUpdate::class, 'HtmlFileCacheUpdate' );