2016-06-06 18:27:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Remove rows from echo_event that don't have corresponding rows in echo_notification.
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
2016-06-06 18:27:23 +00:00
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
2017-06-20 02:41:30 +00:00
|
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
2016-06-06 18:27:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maintenance script that removes orphaned event rows
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
|
|
|
class RemoveOrphanedEvents extends LoggedUpdateMaintenance {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->mDescription = "Remove rows from echo_event that don't have corresponding rows in echo_notification";
|
|
|
|
|
|
|
|
$this->setBatchSize( 500 );
|
2016-12-01 21:34:43 +00:00
|
|
|
|
|
|
|
$this->requireExtension( 'Echo' );
|
2016-06-06 18:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUpdateKey() {
|
|
|
|
return __CLASS__;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doDBUpdates() {
|
|
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
|
|
|
$dbw = $dbFactory->getEchoDb( DB_MASTER );
|
2017-09-24 05:23:47 +00:00
|
|
|
$dbr = $dbFactory->getEchoDb( DB_REPLICA );
|
2016-06-06 18:27:23 +00:00
|
|
|
$iterator = new BatchRowIterator(
|
|
|
|
$dbr,
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'echo_event', 'echo_notification' ],
|
2016-06-06 18:27:23 +00:00
|
|
|
'event_id',
|
|
|
|
$this->mBatchSize
|
|
|
|
);
|
2016-12-05 18:51:07 +00:00
|
|
|
$iterator->addJoinConditions( [
|
|
|
|
'echo_notification' => [ 'LEFT JOIN', 'notification_event=event_id' ]
|
|
|
|
] );
|
|
|
|
$iterator->addConditions( [
|
2016-06-06 18:27:23 +00:00
|
|
|
'notification_user' => null
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2016-06-06 18:27:23 +00:00
|
|
|
|
|
|
|
$this->output( "Removing orphaned echo_event rows...\n" );
|
|
|
|
|
|
|
|
$processed = 0;
|
|
|
|
foreach ( $iterator as $batch ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$ids = [];
|
2016-06-06 18:27:23 +00:00
|
|
|
foreach ( $batch as $row ) {
|
|
|
|
$ids[] = $row->event_id;
|
|
|
|
}
|
|
|
|
$dbw->delete(
|
|
|
|
'echo_event',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'event_id' => $ids ]
|
2016-06-06 18:27:23 +00:00
|
|
|
|
|
|
|
);
|
|
|
|
$processed += $dbw->affectedRows();
|
|
|
|
$this->output( "Deleted $processed orphaned rows.\n" );
|
|
|
|
$dbFactory->waitForSlaves();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = 'RemoveOrphanedEvents';
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|