2016-07-27 14:52:18 +00:00
|
|
|
<?php
|
2018-08-13 07:29:32 +00:00
|
|
|
|
2022-11-13 07:48:43 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications;
|
|
|
|
|
|
|
|
use DeferrableUpdate;
|
|
|
|
use DeferredUpdates;
|
2022-11-02 03:51:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Controller\ModerationController;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2016-07-27 14:52:18 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-11-13 07:48:43 +00:00
|
|
|
class DeferredMarkAsDeletedUpdate implements DeferrableUpdate {
|
2016-07-27 14:52:18 +00:00
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* @var Event[]
|
2016-07-27 14:52:18 +00:00
|
|
|
*/
|
2016-12-05 18:51:07 +00:00
|
|
|
protected $events = [];
|
2016-07-27 14:52:18 +00:00
|
|
|
|
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* @param Event $event
|
2016-07-27 14:52:18 +00:00
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
public static function add( Event $event ) {
|
2016-07-27 14:52:18 +00:00
|
|
|
static $update;
|
|
|
|
if ( $update === null ) {
|
|
|
|
$update = new self();
|
|
|
|
DeferredUpdates::addUpdate( $update );
|
|
|
|
}
|
|
|
|
$update->addInternal( $event );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* @param Event $event
|
2016-07-27 14:52:18 +00:00
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
private function addInternal( Event $event ) {
|
2016-07-27 14:52:18 +00:00
|
|
|
$this->events[] = $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function filterEventsWithTitleDbLag() {
|
|
|
|
return array_filter(
|
|
|
|
$this->events,
|
2022-11-02 21:34:17 +00:00
|
|
|
static function ( Event $event ) {
|
2016-07-27 14:52:18 +00:00
|
|
|
if ( !$event->getTitle() && $event->getTitle( true ) ) {
|
|
|
|
// It is very likely this event was found
|
2022-06-23 09:17:10 +00:00
|
|
|
// unrenderable because of replica lag.
|
2016-07-27 14:52:18 +00:00
|
|
|
// Do not moderate it at this time.
|
|
|
|
LoggerFactory::getInstance( 'Echo' )->debug(
|
2022-11-13 07:48:43 +00:00
|
|
|
'DeferredMarkAsDeletedUpdate: Event {eventId} was found unrenderable' .
|
2021-05-13 00:04:54 +00:00
|
|
|
' but its associated title exists on primary database. Skipping.',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-07-27 14:52:18 +00:00
|
|
|
'eventId' => $event->getId(),
|
|
|
|
'title' => $event->getTitle()->getPrefixedText(),
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-07-27 14:52:18 +00:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks all queued notifications as read.
|
|
|
|
* Satisfies DeferrableUpdate interface
|
|
|
|
*/
|
|
|
|
public function doUpdate() {
|
|
|
|
$events = $this->filterEventsWithTitleDbLag();
|
|
|
|
|
|
|
|
$eventIds = array_map(
|
2022-11-02 21:34:17 +00:00
|
|
|
static function ( Event $event ) {
|
2016-07-27 14:52:18 +00:00
|
|
|
return $event->getId();
|
|
|
|
},
|
|
|
|
$events
|
|
|
|
);
|
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
ModerationController::moderate( $eventIds, true );
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->events = [];
|
2016-07-27 14:52:18 +00:00
|
|
|
}
|
|
|
|
}
|