Debian Codegraph @

extensions/Echo/includes/Push/PushNotifier.php

raw symbols SCIP
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\UserIdentity;
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 UserIdentity $user
16 * @param Event $event
17 */
18 public static function notifyWithPush( UserIdentity $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 UserIdentity $user
28 * @param Event|null $event
29 * @return NotificationRequestJob
30 */
31 private static function createJob( UserIdentity $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' );