mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
1fec0793e1
As Krinkle points out, it always writes to DB_MASTER, so it doesn't make much sense to offer an option to read from DB_REPLICA. This also resolves the race condition that I believe arises from the one caller that passes in DB_REPLICA. Change-Id: I6976e5479debc3f4a8f28d53b1616c01475772be
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* 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 );
|
|
|
|
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
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
$lbFactory->waitForReplication( [ 'timeout' => 5 ] );
|
|
$lbFactory->flushReplicaSnapshots( 'EchoModerationController::moderate' );
|
|
// Recompute the notification count for the
|
|
// users whose notifications have been moderated.
|
|
foreach ( $affectedUserIds as $userId ) {
|
|
$user = User::newFromId( $userId );
|
|
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
|
|
}
|
|
} );
|
|
}
|
|
}
|