mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
df068ba075
echo_notification isn't the only table that refers to echo_event; echo_email_batch does too, so check it as well. Change-Id: I6663c8bb83a991ee663eb1616583fde8eee46751
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Remove rows from echo_event that don't have corresponding rows in echo_notification or echo_email_batch.
|
|
*
|
|
* @ingroup Maintenance
|
|
*/
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
|
|
|
/**
|
|
* Maintenance script that removes orphaned event rows
|
|
*
|
|
* @ingroup Maintenance
|
|
*/
|
|
class RemoveOrphanedEvents extends LoggedUpdateMaintenance {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->addDescription( "Remove rows from echo_event that don't have corresponding rows in echo_notification or echo_email_batch" );
|
|
|
|
$this->setBatchSize( 500 );
|
|
|
|
$this->requireExtension( 'Echo' );
|
|
}
|
|
|
|
public function getUpdateKey() {
|
|
return __CLASS__;
|
|
}
|
|
|
|
public function doDBUpdates() {
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
|
$dbw = $dbFactory->getEchoDb( DB_MASTER );
|
|
$dbr = $dbFactory->getEchoDb( DB_REPLICA );
|
|
$iterator = new BatchRowIterator(
|
|
$dbr,
|
|
[ 'echo_event', 'echo_notification', 'echo_email_batch' ],
|
|
'event_id',
|
|
$this->mBatchSize
|
|
);
|
|
$iterator->addJoinConditions( [
|
|
'echo_notification' => [ 'LEFT JOIN', 'notification_event=event_id' ],
|
|
'echo_email_batch' => [ 'LEFT JOIN', 'eeb_event_id=event_id' ],
|
|
] );
|
|
$iterator->addConditions( [
|
|
'notification_user' => null,
|
|
'eeb_user_id' => null,
|
|
] );
|
|
|
|
$this->output( "Removing orphaned echo_event rows...\n" );
|
|
|
|
$processed = 0;
|
|
foreach ( $iterator as $batch ) {
|
|
$ids = [];
|
|
foreach ( $batch as $row ) {
|
|
$ids[] = $row->event_id;
|
|
}
|
|
$dbw->delete(
|
|
'echo_event',
|
|
[ 'event_id' => $ids ]
|
|
|
|
);
|
|
$processed += $dbw->affectedRows();
|
|
$this->output( "Deleted $processed orphaned rows.\n" );
|
|
$dbFactory->waitForSlaves();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$maintClass = RemoveOrphanedEvents::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|