Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / deferred / MessageCacheUpdate.php
1 <?php
2 /**
3 * Message cache purging and in-place update handler for specific message page changes
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 use Wikimedia\Assert\Assert;
24
25 /**
26 * Message cache purging and in-place update handler for specific message page changes
27 *
28 * @ingroup Cache
29 * @since 1.32
30 */
31 class MessageCacheUpdate implements DeferrableUpdate, MergeableUpdate {
32 /** @var array[] Map of (language code => list of (DB key, DB key without code)) */
33 private $replacements = [];
34
35 /**
36 * @param string $code Language code
37 * @param string $title Message cache key with initial uppercase letter
38 * @param string $msg Message cache key with initial uppercase letter and without the code
39 */
40 public function __construct( $code, $title, $msg ) {
41 $this->replacements[$code][] = [ $title, $msg ];
42 }
43
44 public function merge( MergeableUpdate $update ) {
45 /** @var self $update */
46 Assert::parameterType( __CLASS__, $update, '$update' );
47 '@phan-var self $update';
48
49 foreach ( $update->replacements as $code => $messages ) {
50 $this->replacements[$code] = array_merge( $this->replacements[$code] ?? [], $messages );
51 }
52 }
53
54 public function doUpdate() {
55 $messageCache = MessageCache::singleton();
56 foreach ( $this->replacements as $code => $replacements ) {
57 $messageCache->refreshAndReplaceInternal( $code, $replacements );
58 }
59 }
60 }