mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-24 13:44:40 +00:00
d8168ca071
Change-Id: I0beba40920e5ddc0abbf49f9765a1ef9e3d3d1e5
75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
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 EchoEvent[]
|
|
*/
|
|
protected $events = [];
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
*/
|
|
public static function add( EchoEvent $event ) {
|
|
static $update;
|
|
if ( $update === null ) {
|
|
$update = new self();
|
|
DeferredUpdates::addUpdate( $update );
|
|
}
|
|
$update->addInternal( $event );
|
|
}
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
*/
|
|
private function addInternal( EchoEvent $event ) {
|
|
$this->events[] = $event;
|
|
}
|
|
|
|
private function filterEventsWithTitleDbLag() {
|
|
return array_filter(
|
|
$this->events,
|
|
static function ( EchoEvent $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 ( EchoEvent $event ) {
|
|
return $event->getId();
|
|
},
|
|
$events
|
|
);
|
|
|
|
EchoModerationController::moderate( $eventIds, true );
|
|
$this->events = [];
|
|
}
|
|
}
|