mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-15 03:35:01 +00:00
5611662f06
Depends-On: Id28792658de950b99a8786f881563476def59eba Change-Id: Ib57ea2db947285946f31fa9912b37181044df9d3
77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Notifications\Controller\ModerationController;
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
|
|
/**
|
|
* Mark event notifications as deleted at the end of a request. Used to queue up
|
|
* individual events to mark due to formatting failures.
|
|
*/
|
|
class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
|
|
/**
|
|
* @var Event[]
|
|
*/
|
|
protected $events = [];
|
|
|
|
/**
|
|
* @param Event $event
|
|
*/
|
|
public static function add( Event $event ) {
|
|
static $update;
|
|
if ( $update === null ) {
|
|
$update = new self();
|
|
DeferredUpdates::addUpdate( $update );
|
|
}
|
|
$update->addInternal( $event );
|
|
}
|
|
|
|
/**
|
|
* @param Event $event
|
|
*/
|
|
private function addInternal( Event $event ) {
|
|
$this->events[] = $event;
|
|
}
|
|
|
|
private function filterEventsWithTitleDbLag() {
|
|
return array_filter(
|
|
$this->events,
|
|
static function ( Event $event ) {
|
|
if ( !$event->getTitle() && $event->getTitle( true ) ) {
|
|
// It is very likely this event was found
|
|
// unrenderable because of replica lag.
|
|
// Do not moderate it at this time.
|
|
LoggerFactory::getInstance( 'Echo' )->debug(
|
|
'EchoDeferredMarkAsDeletedUpdate: Event {eventId} was found unrenderable' .
|
|
' but its associated title exists on primary database. Skipping.',
|
|
[
|
|
'eventId' => $event->getId(),
|
|
'title' => $event->getTitle()->getPrefixedText(),
|
|
]
|
|
);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Marks all queued notifications as read.
|
|
* Satisfies DeferrableUpdate interface
|
|
*/
|
|
public function doUpdate() {
|
|
$events = $this->filterEventsWithTitleDbLag();
|
|
|
|
$eventIds = array_map(
|
|
static function ( Event $event ) {
|
|
return $event->getId();
|
|
},
|
|
$events
|
|
);
|
|
|
|
ModerationController::moderate( $eventIds, true );
|
|
$this->events = [];
|
|
}
|
|
}
|