2013-01-15 23:21:39 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Remove invalid events from echo_event and echo_notification
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2019-04-17 12:12:56 +00:00
|
|
|
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
|
|
|
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
2013-01-15 23:21:39 +00:00
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
2017-06-20 02:41:30 +00:00
|
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maintenance script that removes invalid notifications
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2015-10-29 11:38:40 +00:00
|
|
|
class RemoveInvalidNotification extends Maintenance {
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2020-12-16 21:31:09 +00:00
|
|
|
/** @var string[] */
|
2016-12-05 18:51:07 +00:00
|
|
|
protected $invalidEventType = [ 'article-linked' ];
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2016-12-01 21:34:43 +00:00
|
|
|
public function __construct() {
|
2019-05-14 16:48:36 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
2019-03-27 05:07:48 +00:00
|
|
|
$this->addDescription( "Removes invalid notifications from the database." );
|
2020-12-17 18:27:43 +00:00
|
|
|
$this->setBatchSize( 500 );
|
2016-12-01 21:34:43 +00:00
|
|
|
$this->requireExtension( 'Echo' );
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
public function execute() {
|
2022-11-12 07:19:00 +00:00
|
|
|
$lbFactory = DbFactory::newFromDefault();
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( !$this->invalidEventType ) {
|
|
|
|
$this->output( "There is nothing to process\n" );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-03 07:28:02 +00:00
|
|
|
$dbw = $lbFactory->getEchoDb( DB_PRIMARY );
|
2019-04-17 12:12:56 +00:00
|
|
|
$dbr = $lbFactory->getEchoDb( DB_REPLICA );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2020-12-17 18:27:43 +00:00
|
|
|
$batchSize = $this->getBatchSize();
|
|
|
|
$count = $batchSize;
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2020-12-17 18:27:43 +00:00
|
|
|
while ( $count == $batchSize ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
$res = $dbr->select(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'echo_event' ],
|
|
|
|
[ 'event_id' ],
|
|
|
|
[
|
2013-01-15 23:21:39 +00:00
|
|
|
'event_type' => $this->invalidEventType,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2013-01-15 23:21:39 +00:00
|
|
|
__METHOD__,
|
2020-12-17 18:27:43 +00:00
|
|
|
[ 'LIMIT' => $batchSize ]
|
2013-01-15 23:21:39 +00:00
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$event = [];
|
2013-01-15 23:21:39 +00:00
|
|
|
$count = 0;
|
2015-10-01 13:48:52 +00:00
|
|
|
foreach ( $res as $row ) {
|
2020-11-20 03:59:57 +00:00
|
|
|
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( !in_array( $row->event_id, $event ) ) {
|
|
|
|
$event[] = $row->event_id;
|
|
|
|
}
|
|
|
|
$count++;
|
2020-01-14 05:09:42 +00:00
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
if ( $event ) {
|
2015-12-31 23:11:51 +00:00
|
|
|
$this->beginTransaction( $dbw, __METHOD__ );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
$dbw->delete(
|
|
|
|
'echo_event',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'event_id' => $event ],
|
2013-01-15 23:21:39 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$dbw->delete(
|
|
|
|
'echo_notification',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'notification_event' => $event ],
|
2013-01-15 23:21:39 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
|
2015-12-31 23:11:51 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
$this->output( "processing " . count( $event ) . " invalid events\n" );
|
2023-01-05 21:14:51 +00:00
|
|
|
$this->waitForReplication();
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup is not necessary for
|
2013-03-26 00:57:42 +00:00
|
|
|
// 1. echo_email_batch, invalid notification is removed during the cron
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 06:37:37 +00:00
|
|
|
$maintClass = RemoveInvalidNotification::class;
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|