Debian Codegraph @

extensions/Echo/includes/Controller/ModerationController.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Controller;
4
5 use MediaWiki\Deferred\DeferredUpdates;
6 use MediaWiki\Extension\Notifications\Mapper\EventMapper;
7 use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
8 use MediaWiki\Extension\Notifications\NotifUser;
9 use MediaWiki\MediaWikiServices;
10 use MediaWiki\User\User;
11
12 /**
13 * This class represents the controller for moderating notifications
14 */
15 class ModerationController {
16
17 /**
18 * Moderate or unmoderate events
19 *
20 * @param int[] $eventIds
21 * @param bool $moderate Whether to moderate or unmoderate the events
22 */
23 public static function moderate( array $eventIds, $moderate ) {
24 if ( !$eventIds ) {
25 return;
26 }
27
28 $eventMapper = new EventMapper();
29 $notificationMapper = new NotificationMapper();
30
31 $affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
32 $eventMapper->toggleDeleted( $eventIds, $moderate );
33
34 $fname = __METHOD__;
35
36 DeferredUpdates::addCallableUpdate( static function () use ( $affectedUserIds, $fname ) {
37 // This update runs after the main transaction round commits.
38 // Wait for the event deletions to be propagated to replica DBs
39 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
40 $lbFactory->waitForReplication( [ 'timeout' => 5 ] );
41 $lbFactory->flushReplicaSnapshots( $fname );
42 // Recompute the notification count for the
43 // users whose notifications have been moderated.
44 foreach ( $affectedUserIds as $userId ) {
45 $user = User::newFromId( $userId );
46 NotifUser::newFromUser( $user )->resetNotificationCount();
47 }
48 } );
49 }
50 }