Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UserNotifier | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
notifyRegistration | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | declare( strict_types=1 ); |
3 | |
4 | namespace MediaWiki\Extension\CampaignEvents\Notifications; |
5 | |
6 | use InvalidArgumentException; |
7 | use MediaWiki\Deferred\DeferredUpdates; |
8 | use MediaWiki\Extension\CampaignEvents\Event\ExistingEventRegistration; |
9 | use MediaWiki\Extension\CampaignEvents\MWEntity\ICampaignsAuthority; |
10 | use MediaWiki\Extension\CampaignEvents\MWEntity\MWPageProxy; |
11 | use MediaWiki\Extension\Notifications\Model\Event; |
12 | use MediaWiki\Title\Title; |
13 | |
14 | class UserNotifier { |
15 | public const SERVICE_NAME = 'CampaignEventsUserNotifier'; |
16 | |
17 | private bool $isEchoLoaded; |
18 | |
19 | /** |
20 | * @param bool $isEchoLoaded |
21 | */ |
22 | public function __construct( bool $isEchoLoaded ) { |
23 | $this->isEchoLoaded = $isEchoLoaded; |
24 | } |
25 | |
26 | /** |
27 | * @param ICampaignsAuthority $performer |
28 | * @param ExistingEventRegistration $event |
29 | */ |
30 | public function notifyRegistration( ICampaignsAuthority $performer, ExistingEventRegistration $event ): void { |
31 | if ( $this->isEchoLoaded ) { |
32 | $eventPage = $event->getPage(); |
33 | if ( !$eventPage instanceof MWPageProxy ) { |
34 | throw new InvalidArgumentException( "Unexpected Page implementation" ); |
35 | } |
36 | DeferredUpdates::addCallableUpdate( static function () use ( $performer, $event, $eventPage ) { |
37 | Event::create( [ |
38 | 'type' => RegistrationNotificationPresentationModel::NOTIFICATION_NAME, |
39 | 'title' => Title::castFromPageIdentity( $eventPage->getPageIdentity() ), |
40 | 'extra' => [ |
41 | 'user' => $performer->getLocalUserID(), |
42 | 'event-id' => $event->getID() |
43 | ] |
44 | ] ); |
45 | } ); |
46 | } |
47 | } |
48 | } |