Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
30.77% |
4 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PushNotifier | |
33.33% |
4 / 12 |
|
0.00% |
0 / 2 |
12.41 | |
0.00% |
0 / 1 |
notifyWithPush | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
createJob | |
50.00% |
4 / 8 |
|
0.00% |
0 / 1 |
4.12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Push; |
4 | |
5 | use MediaWiki\Extension\Notifications\Model\Event; |
6 | use MediaWiki\Extension\Notifications\Services; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\User\User; |
9 | |
10 | class PushNotifier { |
11 | |
12 | /** |
13 | * Submits a notification derived from an Echo event to each push notifications service |
14 | * subscription found for a user, via a configured service handler implementation |
15 | * @param User $user |
16 | * @param Event $event |
17 | */ |
18 | public static function notifyWithPush( User $user, Event $event ): void { |
19 | $attributeManager = Services::getInstance()->getAttributeManager(); |
20 | $userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' ); |
21 | if ( in_array( $event->getType(), $userEnabledEvents ) ) { |
22 | MediaWikiServices::getInstance()->getJobQueueGroup()->push( self::createJob( $user, $event ) ); |
23 | } |
24 | } |
25 | |
26 | /** |
27 | * @param User $user |
28 | * @param Event|null $event |
29 | * @return NotificationRequestJob |
30 | */ |
31 | private static function createJob( User $user, Event $event = null ): NotificationRequestJob { |
32 | $centralId = Utils::getPushUserId( $user ); |
33 | $params = [ 'centralId' => $centralId ]; |
34 | // below params are only needed for debug logging (T255068) |
35 | if ( $event !== null ) { |
36 | $params['eventId'] = $event->getId(); |
37 | $params['eventType'] = $event->getType(); |
38 | if ( $event->getAgent() !== null ) { |
39 | $params['agent'] = $event->getAgent()->getId(); |
40 | } |
41 | } |
42 | return new NotificationRequestJob( 'EchoPushNotificationRequest', $params ); |
43 | } |
44 | |
45 | } |
46 | |
47 | class_alias( PushNotifier::class, 'EchoPush\\PushNotifier' ); |