2014-09-09 22:11:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This job is created when sending notifications to the target users. The purpose
|
|
|
|
* of this job is to delete older notifications when the number of notifications a
|
|
|
|
* user has is more than $wgEchoMaxUpdateCount, it does not make sense to have tons
|
|
|
|
* of notifications in the history while users wouldn't bother to click 'load more'
|
|
|
|
* like 100 times to see them. What we gain from this is we could run expensive
|
|
|
|
* queries otherwise that would requires adding index and data denormalization.
|
2015-06-17 07:22:42 +00:00
|
|
|
*
|
|
|
|
* The initial job contains multiple users, which will in turn have individual jobs
|
|
|
|
* queued for them.
|
2014-09-09 22:11:53 +00:00
|
|
|
*/
|
|
|
|
class EchoNotificationDeleteJob extends Job {
|
|
|
|
|
|
|
|
/**
|
2015-06-16 00:58:00 +00:00
|
|
|
* @param Title $title
|
|
|
|
* @param array $params
|
2014-09-09 22:11:53 +00:00
|
|
|
*/
|
2019-10-23 10:44:35 +00:00
|
|
|
public function __construct( Title $title, array $params ) {
|
2014-09-09 22:11:53 +00:00
|
|
|
parent::__construct( __CLASS__, $title, $params );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the job of finding & deleting older notifications
|
2017-10-13 11:48:05 +00:00
|
|
|
* @return true
|
2014-09-09 22:11:53 +00:00
|
|
|
*/
|
2015-06-16 00:58:00 +00:00
|
|
|
public function run() {
|
2014-09-09 22:11:53 +00:00
|
|
|
global $wgEchoMaxUpdateCount;
|
2019-06-05 15:54:58 +00:00
|
|
|
if ( count( $this->params['userIds'] ) > 1 ) {
|
2015-06-17 07:22:42 +00:00
|
|
|
// If there are multiple users, queue a single job for each one
|
2016-12-05 18:51:07 +00:00
|
|
|
$jobs = [];
|
2019-06-05 15:54:58 +00:00
|
|
|
foreach ( $this->params['userIds'] as $userId ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$jobs[] = new EchoNotificationDeleteJob( $this->title, [ 'userIds' => [ $userId ] ] );
|
2015-06-17 07:22:42 +00:00
|
|
|
}
|
|
|
|
JobQueueGroup::singleton()->push( $jobs );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2015-06-17 07:22:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-09-09 22:11:53 +00:00
|
|
|
|
2015-10-01 13:48:52 +00:00
|
|
|
$notifMapper = new EchoNotificationMapper();
|
2014-09-09 22:11:53 +00:00
|
|
|
|
2015-07-02 22:08:14 +00:00
|
|
|
// Back-compat for older jobs which used array( $userId => $userId );
|
2019-06-05 15:54:58 +00:00
|
|
|
$userIds = array_values( $this->params['userIds'] );
|
2015-07-02 22:08:14 +00:00
|
|
|
$userId = $userIds[0];
|
2015-06-17 07:22:42 +00:00
|
|
|
$user = User::newFromId( $userId );
|
|
|
|
$notif = $notifMapper->fetchByUserOffset( $user, $wgEchoMaxUpdateCount );
|
|
|
|
if ( $notif ) {
|
2018-06-28 18:15:04 +00:00
|
|
|
$notifMapper->deleteByUserEventOffset(
|
2015-06-17 07:22:42 +00:00
|
|
|
$user, $notif->getEvent()->getId()
|
|
|
|
);
|
2018-06-28 18:15:04 +00:00
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$notifUser->resetNotificationCount();
|
2014-09-09 22:11:53 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-09-09 22:11:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|