Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
65.79% covered (warning)
65.79%
25 / 38
61.29% covered (warning)
61.29%
19 / 31
CRAP
0.00% covered (danger)
0.00%
0 / 1
NoWriteWatchedItemStore
67.57% covered (warning)
67.57%
25 / 37
61.29% covered (warning)
61.29%
19 / 31
63.78
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 countWatchedItems
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 countWatchers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 countVisitingWatchers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 countWatchersMultiple
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 countVisitingWatchersMultiple
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getWatchedItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 loadWatchedItem
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 loadWatchedItemsBatch
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getWatchedItemsForUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isWatched
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isTempWatched
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNotificationTimestampsBatch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 countUnreadNotifications
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 duplicateAllAssociatedEntries
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 duplicateEntry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addWatch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addWatchBatchForUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeWatch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNotificationTimestampsForUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 updateNotificationTimestamp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 resetAllNotificationTimestampsForUser
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 resetNotificationTimestamp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clearUserWatchedItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 mustClearWatchedItemsUsingJobQueue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 clearUserWatchedItemsUsingJobQueue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 maybeEnqueueWatchlistExpiryJob
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 removeWatchBatchForUser
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLatestNotificationTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 countExpired
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 removeExpired
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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 Watchlist
20 */
21
22namespace MediaWiki\Watchlist;
23
24use MediaWiki\User\UserIdentity;
25use Wikimedia\Rdbms\DBReadOnlyError;
26
27/**
28 * @internal
29 * @since 1.31
30 * @phan-file-suppress PhanPluginNeverReturnMethod
31 */
32class NoWriteWatchedItemStore implements WatchedItemStoreInterface {
33
34    private WatchedItemStoreInterface $actualStore;
35
36    private const DB_READONLY_ERROR = 'The watchlist is currently readonly.';
37
38    /**
39     * Initially set WatchedItemStore that will be used in cases where writing is not needed.
40     */
41    public function __construct( WatchedItemStoreInterface $actualStore ) {
42        $this->actualStore = $actualStore;
43    }
44
45    /** @inheritDoc */
46    public function countWatchedItems( UserIdentity $user ) {
47        return $this->actualStore->countWatchedItems( $user );
48    }
49
50    /** @inheritDoc */
51    public function countWatchers( $target ) {
52        return $this->actualStore->countWatchers( $target );
53    }
54
55    /** @inheritDoc */
56    public function countVisitingWatchers( $target, $threshold ) {
57        return $this->actualStore->countVisitingWatchers( $target, $threshold );
58    }
59
60    /** @inheritDoc */
61    public function countWatchersMultiple( array $targets, array $options = [] ) {
62        return $this->actualStore->countWatchersMultiple(
63            $targets,
64            $options
65        );
66    }
67
68    /** @inheritDoc */
69    public function countVisitingWatchersMultiple(
70        array $targetsWithVisitThresholds,
71        $minimumWatchers = null
72    ) {
73        return $this->actualStore->countVisitingWatchersMultiple(
74            $targetsWithVisitThresholds,
75            $minimumWatchers
76        );
77    }
78
79    /** @inheritDoc */
80    public function getWatchedItem( UserIdentity $user, $target ) {
81        return $this->actualStore->getWatchedItem( $user, $target );
82    }
83
84    /** @inheritDoc */
85    public function loadWatchedItem( UserIdentity $user, $target ) {
86        return $this->actualStore->loadWatchedItem( $user, $target );
87    }
88
89    /** @inheritDoc */
90    public function loadWatchedItemsBatch( UserIdentity $user, array $targets ) {
91        return $this->actualStore->loadWatchedItemsBatch( $user, $targets );
92    }
93
94    /** @inheritDoc */
95    public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ) {
96        return $this->actualStore->getWatchedItemsForUser( $user, $options );
97    }
98
99    /** @inheritDoc */
100    public function isWatched( UserIdentity $user, $target ) {
101        return $this->actualStore->isWatched( $user, $target );
102    }
103
104    /** @inheritDoc */
105    public function isTempWatched( UserIdentity $user, $target ): bool {
106        return $this->actualStore->isTempWatched( $user, $target );
107    }
108
109    /** @inheritDoc */
110    public function getNotificationTimestampsBatch( UserIdentity $user, array $targets ) {
111        return $this->actualStore->getNotificationTimestampsBatch( $user, $targets );
112    }
113
114    /** @inheritDoc */
115    public function countUnreadNotifications( UserIdentity $user, $unreadLimit = null ) {
116        return $this->actualStore->countUnreadNotifications( $user, $unreadLimit );
117    }
118
119    /** @inheritDoc */
120    public function duplicateAllAssociatedEntries( $oldTarget, $newTarget ) {
121        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
122    }
123
124    /** @inheritDoc */
125    public function duplicateEntry( $oldTarget, $newTarget ) {
126        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
127    }
128
129    /** @inheritDoc */
130    public function addWatch( UserIdentity $user, $target, ?string $expiry = null ) {
131        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
132    }
133
134    /** @inheritDoc */
135    public function addWatchBatchForUser(
136        UserIdentity $user,
137        array $targets,
138        ?string $expiry = null
139    ) {
140        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
141    }
142
143    /** @inheritDoc */
144    public function removeWatch( UserIdentity $user, $target ) {
145        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
146    }
147
148    /** @inheritDoc */
149    public function setNotificationTimestampsForUser(
150        UserIdentity $user,
151        $timestamp,
152        array $targets = []
153    ) {
154        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
155    }
156
157    /** @inheritDoc */
158    public function updateNotificationTimestamp(
159        UserIdentity $editor, $target, $timestamp
160    ) {
161        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
162    }
163
164    /** @inheritDoc */
165    public function resetAllNotificationTimestampsForUser( UserIdentity $user, $timestamp = null ) {
166        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
167    }
168
169    /** @inheritDoc */
170    public function resetNotificationTimestamp(
171        UserIdentity $user,
172        $title,
173        $force = '',
174        $oldid = 0
175    ) {
176        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
177    }
178
179    /** @inheritDoc */
180    public function clearUserWatchedItems( UserIdentity $user ) {
181        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
182    }
183
184    /** @inheritDoc */
185    public function mustClearWatchedItemsUsingJobQueue( UserIdentity $user ): bool {
186        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
187    }
188
189    /** @inheritDoc */
190    public function clearUserWatchedItemsUsingJobQueue( UserIdentity $user ) {
191        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
192    }
193
194    /** @inheritDoc */
195    public function maybeEnqueueWatchlistExpiryJob(): void {
196        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
197    }
198
199    /** @inheritDoc */
200    public function removeWatchBatchForUser( UserIdentity $user, array $targets ) {
201        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
202    }
203
204    /** @inheritDoc */
205    public function getLatestNotificationTimestamp(
206        $timestamp, UserIdentity $user, $target
207    ) {
208        return wfTimestampOrNull( TS_MW, $timestamp );
209    }
210
211    /** @inheritDoc */
212    public function countExpired(): int {
213        return $this->actualStore->countExpired();
214    }
215
216    /** @inheritDoc */
217    public function removeExpired( int $limit, bool $deleteOrphans = false ): void {
218        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
219    }
220}
221/** @deprecated class alias since 1.43 */
222class_alias( NoWriteWatchedItemStore::class, 'NoWriteWatchedItemStore' );