2013-01-15 23:21:39 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Remove invalid events from echo_event and echo_notification
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
protected $batchSize = 500;
|
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() {
|
|
|
|
$this->mDescription = "Removes invalid notifications from the database.";
|
|
|
|
$this->requireExtension( 'Echo' );
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
public function execute() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-11 14:00:00 +00:00
|
|
|
global $wgEchoCluster;
|
|
|
|
|
2013-04-09 22:13:39 +00:00
|
|
|
$dbw = MWEchoDbFactory::getDB( DB_MASTER );
|
|
|
|
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
$count = $this->batchSize;
|
|
|
|
|
|
|
|
while ( $count == $this->batchSize ) {
|
|
|
|
$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__,
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'LIMIT' => $this->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 ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( !in_array( $row->event_id, $event ) ) {
|
|
|
|
$event[] = $row->event_id;
|
|
|
|
}
|
|
|
|
$count++;
|
|
|
|
};
|
|
|
|
|
|
|
|
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" );
|
2013-04-11 14:00:00 +00:00
|
|
|
wfWaitForSlaves( false, false, $wgEchoCluster );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 11:38:40 +00:00
|
|
|
$maintClass = 'RemoveInvalidNotification'; // Tells it to run the class
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|