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