Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7428517
NotificationDeleteJob.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
NotificationDeleteJob.php
View Options
<?php
namespace
MediaWiki\Extension\Notifications\Jobs
;
use
MediaWiki\Extension\Notifications\Mapper\NotificationMapper
;
use
MediaWiki\Extension\Notifications\NotifUser
;
use
MediaWiki\JobQueue\Job
;
use
MediaWiki\JobQueue\JobQueueGroup
;
use
MediaWiki\Title\Title
;
use
MediaWiki\User\User
;
/**
* 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.
*
* The initial job contains multiple users, which will in turn have individual jobs
* queued for them.
*/
class
NotificationDeleteJob
extends
Job
{
private
JobQueueGroup
$jobQueueGroup
;
public
function
__construct
(
Title
$title
,
array
$params
,
JobQueueGroup
$jobQueueGroup
)
{
parent
::
__construct
(
'EchoNotificationDeleteJob'
,
$title
,
$params
);
$this
->
jobQueueGroup
=
$jobQueueGroup
;
}
/**
* Run the job of finding & deleting older notifications
* @return true
*/
public
function
run
()
{
global
$wgEchoMaxUpdateCount
;
if
(
count
(
$this
->
params
[
'userIds'
]
)
>
1
)
{
// If there are multiple users, queue a single job for each one
$jobs
=
[];
foreach
(
$this
->
params
[
'userIds'
]
as
$userId
)
{
$jobs
[]
=
new
NotificationDeleteJob
(
$this
->
title
,
[
'userIds'
=>
[
$userId
]
],
$this
->
jobQueueGroup
);
}
$this
->
jobQueueGroup
->
push
(
$jobs
);
return
true
;
}
$notifMapper
=
new
NotificationMapper
();
// Back-compat for older jobs which used [ $userId => $userId ];
$userIds
=
array_values
(
$this
->
params
[
'userIds'
]
);
$userId
=
$userIds
[
0
];
$user
=
User
::
newFromId
(
$userId
);
$notif
=
$notifMapper
->
fetchByUserOffset
(
$user
,
$wgEchoMaxUpdateCount
);
if
(
$notif
)
{
$notifMapper
->
deleteByUserEventOffset
(
$user
,
$notif
->
getEvent
()->
getId
()
);
$notifUser
=
NotifUser
::
newFromUser
(
$user
);
$notifUser
->
resetNotificationCount
();
}
return
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 09:30 (12 h, 15 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
de/45/6f0372e4d029a1e801e774260e1c
Default Alt Text
NotificationDeleteJob.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment