2016-03-04 19:23:02 +00:00
|
|
|
<?php
|
2018-08-13 07:29:32 +00:00
|
|
|
|
2016-09-12 16:05:33 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents the controller for moderating notifications
|
|
|
|
*/
|
|
|
|
class EchoModerationController {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moderate or unmoderate events
|
|
|
|
*
|
|
|
|
* @param int[] $eventIds
|
|
|
|
* @param bool $moderate Whether to moderate or unmoderate the events
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public static function moderate( $eventIds, $moderate ) {
|
|
|
|
if ( !$eventIds ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$eventMapper = new EchoEventMapper();
|
|
|
|
$notificationMapper = new EchoNotificationMapper();
|
|
|
|
|
|
|
|
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
|
|
|
|
$eventMapper->toggleDeleted( $eventIds, $moderate );
|
|
|
|
|
2016-09-20 05:44:25 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () use ( $affectedUserIds ) {
|
|
|
|
// This update runs after the main transaction round commits.
|
|
|
|
// Wait for the event deletions to be propagated to replica DBs
|
2016-09-12 16:05:33 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
|
|
$lbFactory->waitForReplication( [ 'timeout' => 5 ] );
|
2016-09-20 05:44:25 +00:00
|
|
|
$lbFactory->flushReplicaSnapshots( 'EchoModerationController::moderate' );
|
2016-09-12 16:05:33 +00:00
|
|
|
// Recompute the notification count for the
|
|
|
|
// users whose notifications have been moderated.
|
|
|
|
foreach ( $affectedUserIds as $userId ) {
|
|
|
|
$user = User::newFromId( $userId );
|
2018-05-30 22:38:51 +00:00
|
|
|
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
|
2016-09-12 16:05:33 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-03-04 19:23:02 +00:00
|
|
|
}
|
|
|
|
}
|