| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Jobs; |
| 4 |
|
| 5 |
use Job; |
| 6 |
use JobQueueGroup; |
| 7 |
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper; |
| 8 |
use MediaWiki\Extension\Notifications\NotifUser; |
| 9 |
use MediaWiki\Title\Title; |
| 10 |
use MediaWiki\User\User; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class NotificationDeleteJob extends Job { |
| 24 |
private JobQueueGroup $jobQueueGroup; |
| 25 |
|
| 26 |
public function __construct( |
| 27 |
Title $title, |
| 28 |
array $params, |
| 29 |
JobQueueGroup $jobQueueGroup |
| 30 |
) { |
| 31 |
parent::__construct( 'EchoNotificationDeleteJob', $title, $params ); |
| 32 |
$this->jobQueueGroup = $jobQueueGroup; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function run() { |
| 40 |
global $wgEchoMaxUpdateCount; |
| 41 |
if ( count( $this->params['userIds'] ) > 1 ) { |
| 42 |
|
| 43 |
$jobs = []; |
| 44 |
foreach ( $this->params['userIds'] as $userId ) { |
| 45 |
$jobs[] = new NotificationDeleteJob( |
| 46 |
$this->title, |
| 47 |
[ 'userIds' => [ $userId ] ], |
| 48 |
$this->jobQueueGroup |
| 49 |
); |
| 50 |
} |
| 51 |
$this->jobQueueGroup->push( $jobs ); |
| 52 |
|
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
$notifMapper = new NotificationMapper(); |
| 57 |
|
| 58 |
|
| 59 |
$userIds = array_values( $this->params['userIds'] ); |
| 60 |
$userId = $userIds[0]; |
| 61 |
$user = User::newFromId( $userId ); |
| 62 |
$notif = $notifMapper->fetchByUserOffset( $user, $wgEchoMaxUpdateCount ); |
| 63 |
if ( $notif ) { |
| 64 |
$notifMapper->deleteByUserEventOffset( |
| 65 |
$user, $notif->getEvent()->getId() |
| 66 |
); |
| 67 |
$notifUser = NotifUser::newFromUser( $user ); |
| 68 |
$notifUser->resetNotificationCount(); |
| 69 |
} |
| 70 |
|
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
} |