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     * @param WatchedItemStoreInterface $actualStore
41     */
42    public function __construct( WatchedItemStoreInterface $actualStore ) {
43        $this->actualStore = $actualStore;
44    }
45
46    /** @inheritDoc */
47    public function countWatchedItems( UserIdentity $user ) {
48        return $this->actualStore->countWatchedItems( $user );
49    }
50
51    /** @inheritDoc */
52    public function countWatchers( $target ) {
53        return $this->actualStore->countWatchers( $target );
54    }
55
56    /** @inheritDoc */
57    public function countVisitingWatchers( $target, $threshold ) {
58        return $this->actualStore->countVisitingWatchers( $target, $threshold );
59    }
60
61    /** @inheritDoc */
62    public function countWatchersMultiple( array $targets, array $options = [] ) {
63        return $this->actualStore->countWatchersMultiple(
64            $targets,
65            $options
66        );
67    }
68
69    /** @inheritDoc */
70    public function countVisitingWatchersMultiple(
71        array $targetsWithVisitThresholds,
72        $minimumWatchers = null
73    ) {
74        return $this->actualStore->countVisitingWatchersMultiple(
75            $targetsWithVisitThresholds,
76            $minimumWatchers
77        );
78    }
79
80    /** @inheritDoc */
81    public function getWatchedItem( UserIdentity $user, $target ) {
82        return $this->actualStore->getWatchedItem( $user, $target );
83    }
84
85    /** @inheritDoc */
86    public function loadWatchedItem( UserIdentity $user, $target ) {
87        return $this->actualStore->loadWatchedItem( $user, $target );
88    }
89
90    /** @inheritDoc */
91    public function loadWatchedItemsBatch( UserIdentity $user, array $targets ) {
92        return $this->actualStore->loadWatchedItemsBatch( $user, $targets );
93    }
94
95    /** @inheritDoc */
96    public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ) {
97        return $this->actualStore->getWatchedItemsForUser( $user, $options );
98    }
99
100    /** @inheritDoc */
101    public function isWatched( UserIdentity $user, $target ) {
102        return $this->actualStore->isWatched( $user, $target );
103    }
104
105    /** @inheritDoc */
106    public function isTempWatched( UserIdentity $user, $target ): bool {
107        return $this->actualStore->isTempWatched( $user, $target );
108    }
109
110    /** @inheritDoc */
111    public function getNotificationTimestampsBatch( UserIdentity $user, array $targets ) {
112        return $this->actualStore->getNotificationTimestampsBatch( $user, $targets );
113    }
114
115    /** @inheritDoc */
116    public function countUnreadNotifications( UserIdentity $user, $unreadLimit = null ) {
117        return $this->actualStore->countUnreadNotifications( $user, $unreadLimit );
118    }
119
120    /** @inheritDoc */
121    public function duplicateAllAssociatedEntries( $oldTarget, $newTarget ) {
122        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
123    }
124
125    /** @inheritDoc */
126    public function duplicateEntry( $oldTarget, $newTarget ) {
127        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
128    }
129
130    /** @inheritDoc */
131    public function addWatch( UserIdentity $user, $target, ?string $expiry = null ) {
132        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
133    }
134
135    /** @inheritDoc */
136    public function addWatchBatchForUser(
137        UserIdentity $user,
138        array $targets,
139        ?string $expiry = null
140    ) {
141        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
142    }
143
144    /** @inheritDoc */
145    public function removeWatch( UserIdentity $user, $target ) {
146        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
147    }
148
149    /** @inheritDoc */
150    public function setNotificationTimestampsForUser(
151        UserIdentity $user,
152        $timestamp,
153        array $targets = []
154    ) {
155        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
156    }
157
158    /** @inheritDoc */
159    public function updateNotificationTimestamp(
160        UserIdentity $editor, $target, $timestamp
161    ) {
162        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
163    }
164
165    /** @inheritDoc */
166    public function resetAllNotificationTimestampsForUser( UserIdentity $user, $timestamp = null ) {
167        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
168    }
169
170    /** @inheritDoc */
171    public function resetNotificationTimestamp(
172        UserIdentity $user,
173        $title,
174        $force = '',
175        $oldid = 0
176    ) {
177        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
178    }
179
180    /** @inheritDoc */
181    public function clearUserWatchedItems( UserIdentity $user ) {
182        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
183    }
184
185    /** @inheritDoc */
186    public function mustClearWatchedItemsUsingJobQueue( UserIdentity $user ): bool {
187        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
188    }
189
190    /** @inheritDoc */
191    public function clearUserWatchedItemsUsingJobQueue( UserIdentity $user ) {
192        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
193    }
194
195    /** @inheritDoc */
196    public function maybeEnqueueWatchlistExpiryJob(): void {
197        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
198    }
199
200    /** @inheritDoc */
201    public function removeWatchBatchForUser( UserIdentity $user, array $targets ) {
202        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
203    }
204
205    /** @inheritDoc */
206    public function getLatestNotificationTimestamp(
207        $timestamp, UserIdentity $user, $target
208    ) {
209        return wfTimestampOrNull( TS_MW, $timestamp );
210    }
211
212    /** @inheritDoc */
213    public function countExpired(): int {
214        return $this->actualStore->countExpired();
215    }
216
217    /** @inheritDoc */
218    public function removeExpired( int $limit, bool $deleteOrphans = false ): void {
219        throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
220    }
221}
222/** @deprecated class alias since 1.43 */
223class_alias( NoWriteWatchedItemStore::class, 'NoWriteWatchedItemStore' );