2016-03-04 19:23:02 +00:00
|
|
|
<?php
|
2018-08-13 07:29:32 +00:00
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Controller;
|
|
|
|
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
2022-11-02 20:47:04 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
|
|
|
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
2022-11-13 07:48:43 +00:00
|
|
|
use MediaWiki\Extension\Notifications\NotifUser;
|
2016-09-12 16:05:33 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents the controller for moderating notifications
|
|
|
|
*/
|
2022-11-02 03:51:15 +00:00
|
|
|
class ModerationController {
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Moderate or unmoderate events
|
|
|
|
*
|
|
|
|
* @param int[] $eventIds
|
|
|
|
* @param bool $moderate Whether to moderate or unmoderate the events
|
|
|
|
*/
|
2019-10-23 10:44:35 +00:00
|
|
|
public static function moderate( array $eventIds, $moderate ) {
|
2016-03-04 19:23:02 +00:00
|
|
|
if ( !$eventIds ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
|
|
|
$notificationMapper = new NotificationMapper();
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
|
|
|
|
$eventMapper->toggleDeleted( $eventIds, $moderate );
|
|
|
|
|
2019-02-19 10:42:30 +00:00
|
|
|
$fname = __METHOD__;
|
|
|
|
|
2021-05-04 16:06:42 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( static function () use ( $affectedUserIds, $fname ) {
|
2016-09-20 05:44:25 +00:00
|
|
|
// 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 ] );
|
2019-02-19 10:42:30 +00:00
|
|
|
$lbFactory->flushReplicaSnapshots( $fname );
|
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 );
|
2022-11-13 07:48:43 +00:00
|
|
|
NotifUser::newFromUser( $user )->resetNotificationCount();
|
2016-09-12 16:05:33 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-03-04 19:23:02 +00:00
|
|
|
}
|
|
|
|
}
|