Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserNotifier
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 notifyRegistration
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2declare( strict_types=1 );
3
4namespace MediaWiki\Extension\CampaignEvents\Notifications;
5
6use InvalidArgumentException;
7use MediaWiki\Deferred\DeferredUpdates;
8use MediaWiki\Extension\CampaignEvents\Event\ExistingEventRegistration;
9use MediaWiki\Extension\CampaignEvents\MWEntity\ICampaignsAuthority;
10use MediaWiki\Extension\CampaignEvents\MWEntity\MWPageProxy;
11use MediaWiki\Extension\Notifications\Model\Event;
12use MediaWiki\Title\Title;
13
14class 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}