Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ImmediateWatchTopicListener | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onAfterInsertExpectedChange | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getCurrentUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Data\Listener; |
4 | |
5 | use Flow\Model\Workflow; |
6 | use Flow\WatchedTopicItems; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\User\User; |
9 | |
10 | /** |
11 | * Class to immediately subscribe users to the article title when one of the |
12 | * actions specified in the constructor is inserted. |
13 | */ |
14 | class ImmediateWatchTopicListener extends AbstractTopicInsertListener { |
15 | /** |
16 | * @var WatchedTopicItems |
17 | */ |
18 | protected $watchedTopicItems; |
19 | |
20 | /** |
21 | * @param WatchedTopicItems $watchedTopicItems Helper class for watching titles |
22 | */ |
23 | public function __construct( WatchedTopicItems $watchedTopicItems ) { |
24 | $this->watchedTopicItems = $watchedTopicItems; |
25 | } |
26 | |
27 | /** |
28 | * @param string $changeType |
29 | * @param Workflow $workflow |
30 | */ |
31 | public function onAfterInsertExpectedChange( $changeType, Workflow $workflow ) { |
32 | $users = static::getUsersToSubscribe( $changeType, 'immediate', [ $this->watchedTopicItems ] ); |
33 | |
34 | foreach ( $users as $user ) { |
35 | if ( !$user instanceof User ) { |
36 | continue; |
37 | } |
38 | $title = $workflow->getArticleTitle(); |
39 | |
40 | // see https://phabricator.wikimedia.org/T223165 |
41 | MediaWikiServices::getInstance()->getWatchlistManager()->addWatch( $user, $title ); |
42 | $this->watchedTopicItems->addOverrideWatched( $title ); |
43 | } |
44 | } |
45 | |
46 | /** |
47 | * @param WatchedTopicItems $watchedTopicItems |
48 | * @return User[] |
49 | */ |
50 | public static function getCurrentUser( WatchedTopicItems $watchedTopicItems ) { |
51 | return [ $watchedTopicItems->getUser() ]; |
52 | } |
53 | } |