Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4128580
removeInvalidNotification.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
removeInvalidNotification.php
View Options
<?php
/**
* Remove invalid events from echo_event and echo_notification
*
* @ingroup Maintenance
*/
use
MediaWiki\Extension\Notifications\DbFactory
;
use
MediaWiki\Maintenance\Maintenance
;
require_once
getenv
(
'MW_INSTALL_PATH'
)
!==
false
?
getenv
(
'MW_INSTALL_PATH'
)
.
'/maintenance/Maintenance.php'
:
__DIR__
.
'/../../../maintenance/Maintenance.php'
;
/**
* Maintenance script that removes invalid notifications
*
* @ingroup Maintenance
*/
class
RemoveInvalidNotification
extends
Maintenance
{
/** @var string[] */
protected
$invalidEventType
=
[
'article-linked'
];
public
function
__construct
()
{
parent
::
__construct
();
$this
->
addDescription
(
"Removes invalid notifications from the database."
);
$this
->
setBatchSize
(
500
);
$this
->
requireExtension
(
'Echo'
);
}
public
function
execute
()
{
$lbFactory
=
DbFactory
::
newFromDefault
();
if
(
!
$this
->
invalidEventType
)
{
$this
->
output
(
"There is nothing to process
\n
"
);
return
;
}
$dbw
=
$lbFactory
->
getEchoDb
(
DB_PRIMARY
);
$dbr
=
$lbFactory
->
getEchoDb
(
DB_REPLICA
);
$batchSize
=
$this
->
getBatchSize
();
$count
=
$batchSize
;
while
(
$count
==
$batchSize
)
{
$res
=
$dbr
->
newSelectQueryBuilder
()
->
select
(
'event_id'
)
->
from
(
'echo_event'
)
->
where
(
[
'event_type'
=>
$this
->
invalidEventType
,
]
)
->
limit
(
$batchSize
)
->
caller
(
__METHOD__
)
->
fetchResultSet
();
$event
=
[];
$count
=
0
;
foreach
(
$res
as
$row
)
{
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable
if
(
!
in_array
(
$row
->
event_id
,
$event
)
)
{
$event
[]
=
$row
->
event_id
;
}
$count
++;
}
if
(
$event
)
{
$this
->
beginTransaction
(
$dbw
,
__METHOD__
);
$dbw
->
newDeleteQueryBuilder
()
->
deleteFrom
(
'echo_event'
)
->
where
(
[
'event_id'
=>
$event
]
)
->
caller
(
__METHOD__
)
->
execute
();
$dbw
->
newDeleteQueryBuilder
()
->
deleteFrom
(
'echo_notification'
)
->
where
(
[
'notification_event'
=>
$event
]
)
->
caller
(
__METHOD__
)
->
execute
();
$this
->
commitTransaction
(
$dbw
,
__METHOD__
);
$this
->
output
(
"processing "
.
count
(
$event
)
.
" invalid events
\n
"
);
$this
->
waitForReplication
();
}
// Cleanup is not necessary for
// 1. echo_email_batch, invalid notification is removed during the cron
}
}
}
$maintClass
=
RemoveInvalidNotification
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 09:19 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fc/62/b86b0d4aff5a2be6092f875325e3
Default Alt Text
removeInvalidNotification.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment