mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
b73522549d
By running updateEchoSchemaForSuppression.php as an updater.
The patch-*.sql files already existed, they were added
in 2013(!) by 34fbeaf8c
but never applied.
Bug: T136427
Bug: T50059
Change-Id: Ied049681df4bab325f069c3a68cf704ee9a8f2c9
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Update event_page_id in echo_event based on event_page_title and
|
|
* event_page_namespace
|
|
*
|
|
* @ingroup Maintenance
|
|
*/
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
|
|
|
/**
|
|
* Maintenance script that populates the event_page_id column of echo_event
|
|
*
|
|
* @ingroup Maintenance
|
|
*/
|
|
class UpdateEchoSchemaForSuppression extends LoggedUpdateMaintenance {
|
|
|
|
/**
|
|
* @var string The table to update
|
|
*/
|
|
protected $table = 'echo_event';
|
|
|
|
/**
|
|
* @var string The primary key column of the table to update
|
|
*/
|
|
protected $idField = 'event_id';
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->setBatchSize( 500 );
|
|
$this->requireExtension( 'Echo' );
|
|
}
|
|
|
|
public function getUpdateKey() {
|
|
return __CLASS__;
|
|
}
|
|
|
|
public function doDBUpdates() {
|
|
global $wgEchoCluster;
|
|
|
|
$dbr = MWEchoDbFactory::getDB( DB_REPLICA );
|
|
$dbw = MWEchoDbFactory::getDB( DB_MASTER );
|
|
|
|
if ( !$dbw->fieldExists( 'echo_event', 'event_page_title' ) ) {
|
|
$this->output( "No event_page_title field, skipping migration from event_page_title to event_page_id\n" );
|
|
return true;
|
|
}
|
|
|
|
$reader = new BatchRowIterator( $dbr, $this->table, $this->idField, $this->mBatchSize );
|
|
$reader->addConditions( [
|
|
"event_page_title IS NOT NULL",
|
|
"event_page_id" => null,
|
|
] );
|
|
$reader->setFetchColumns( [ 'event_page_namespace', 'event_page_title', 'event_extra', 'event_type' ] );
|
|
|
|
$updater = new BatchRowUpdate(
|
|
$reader,
|
|
new BatchRowWriter( $dbw, $this->table, $wgEchoCluster ),
|
|
new EchoSuppressionRowUpdateGenerator
|
|
);
|
|
$updater->setOutput( function ( $text ) {
|
|
$this->output( $text );
|
|
} );
|
|
$updater->execute();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$maintClass = UpdateEchoSchemaForSuppression::class; // Tells it to run the class
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|