| 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 |
|
| 14 |
|
| 15 |
class ModerationController { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 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 |
|
| 38 |
|
| 39 |
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
| 40 |
$lbFactory->waitForReplication( [ 'timeout' => 5 ] ); |
| 41 |
$lbFactory->flushReplicaSnapshots( $fname ); |
| 42 |
|
| 43 |
|
| 44 |
foreach ( $affectedUserIds as $userId ) { |
| 45 |
$user = User::newFromId( $userId ); |
| 46 |
NotifUser::newFromUser( $user )->resetNotificationCount(); |
| 47 |
} |
| 48 |
} ); |
| 49 |
} |
| 50 |
} |