Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
WatchlistUpdater | |
100.00% |
19 / 19 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
optionallyWatchEditedSchema | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
optionallyWatchNewSchema | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace EntitySchema\DataAccess; |
6 | |
7 | use EntitySchema\Domain\Model\EntitySchemaId; |
8 | use MediaWiki\Title\Title; |
9 | use MediaWiki\User\Options\UserOptionsLookup; |
10 | use MediaWiki\User\User; |
11 | use MediaWiki\Watchlist\WatchlistManager; |
12 | |
13 | /** |
14 | * @license GPL-2.0-or-later |
15 | */ |
16 | class WatchlistUpdater { |
17 | |
18 | private UserOptionsLookup $userOptionsLookup; |
19 | private WatchlistManager $watchlistManager; |
20 | |
21 | public function __construct( |
22 | UserOptionsLookup $userOptionsLookup, |
23 | WatchlistManager $watchlistManager |
24 | ) { |
25 | $this->userOptionsLookup = $userOptionsLookup; |
26 | $this->watchlistManager = $watchlistManager; |
27 | } |
28 | |
29 | public function optionallyWatchEditedSchema( User $user, EntitySchemaId $entitySchemaId ): void { |
30 | if ( !$user->isNamed() ) { |
31 | return; |
32 | } |
33 | if ( $this->userOptionsLookup->getOption( $user, 'watchdefault' ) ) { |
34 | $this->watchlistManager->setWatch( |
35 | true, |
36 | $user, |
37 | Title::makeTitle( NS_ENTITYSCHEMA_JSON, $entitySchemaId->getId() ) |
38 | ); |
39 | } |
40 | } |
41 | |
42 | public function optionallyWatchNewSchema( User $user, EntitySchemaId $entitySchemaId ): void { |
43 | if ( !$user->isNamed() ) { |
44 | return; |
45 | } |
46 | if ( $this->userOptionsLookup->getOption( $user, 'watchcreations' ) |
47 | || $this->userOptionsLookup->getOption( $user, 'watchdefault' ) ) { |
48 | $this->watchlistManager->setWatch( |
49 | true, |
50 | $user, |
51 | Title::makeTitle( NS_ENTITYSCHEMA_JSON, $entitySchemaId->getId() ) |
52 | ); |
53 | } |
54 | } |
55 | |
56 | } |