2013-05-09 18:50:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Update event_page_id in echo_event based on event_page_title and
|
|
|
|
* event_page_namespace
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2022-11-12 07:19:00 +00:00
|
|
|
|
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2022-11-13 07:53:42 +00:00
|
|
|
use MediaWiki\Extension\Notifications\SuppressionRowUpdateGenerator;
|
2022-11-12 07:19:00 +00:00
|
|
|
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
2013-05-09 18:50:05 +00:00
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
2017-06-20 02:41:30 +00:00
|
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
2013-05-09 18:50:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maintenance script that populates the event_page_id column of echo_event
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2016-06-06 21:02:03 +00:00
|
|
|
class UpdateEchoSchemaForSuppression extends LoggedUpdateMaintenance {
|
2013-05-09 18:50:05 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-14 10:03:09 +00:00
|
|
|
* @var string The table to update
|
2013-05-09 18:50:05 +00:00
|
|
|
*/
|
|
|
|
protected $table = 'echo_event';
|
|
|
|
|
|
|
|
/**
|
2015-12-14 10:03:09 +00:00
|
|
|
* @var string The primary key column of the table to update
|
2013-05-09 18:50:05 +00:00
|
|
|
*/
|
|
|
|
protected $idField = 'event_id';
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->setBatchSize( 500 );
|
2016-12-01 21:34:43 +00:00
|
|
|
$this->requireExtension( 'Echo' );
|
2013-05-09 18:50:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 21:02:03 +00:00
|
|
|
public function getUpdateKey() {
|
|
|
|
return __CLASS__;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doDBUpdates() {
|
2013-05-09 18:50:05 +00:00
|
|
|
global $wgEchoCluster;
|
2022-11-12 07:19:00 +00:00
|
|
|
$lbFactory = DbFactory::newFromDefault();
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2019-04-17 12:12:56 +00:00
|
|
|
$dbr = $lbFactory->getEchoDb( DB_REPLICA );
|
2021-05-03 07:28:02 +00:00
|
|
|
$dbw = $lbFactory->getEchoDb( DB_PRIMARY );
|
2022-08-08 17:46:16 +00:00
|
|
|
'@phan-var \Wikimedia\Rdbms\IMaintainableDatabase $dbw';
|
2016-06-06 21:56:53 +00:00
|
|
|
|
2020-06-07 00:59:39 +00:00
|
|
|
if ( !$dbw->fieldExists( 'echo_event', 'event_page_title', __METHOD__ ) ) {
|
2016-06-06 21:56:53 +00:00
|
|
|
$this->output( "No event_page_title field, skipping migration from event_page_title to event_page_id\n" );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-17 18:27:43 +00:00
|
|
|
$reader = new BatchRowIterator( $dbr, $this->table, $this->idField, $this->getBatchSize() );
|
2016-12-05 18:51:07 +00:00
|
|
|
$reader->addConditions( [
|
2013-05-09 18:50:05 +00:00
|
|
|
"event_page_title IS NOT NULL",
|
|
|
|
"event_page_id" => null,
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
|
|
|
$reader->setFetchColumns( [ 'event_page_namespace', 'event_page_title', 'event_extra', 'event_type' ] );
|
2020-09-05 02:02:17 +00:00
|
|
|
$reader->setCaller( __METHOD__ );
|
|
|
|
|
|
|
|
$writer = new BatchRowWriter( $dbw, $this->table, $wgEchoCluster );
|
|
|
|
$writer->setCaller( __METHOD__ );
|
2013-05-09 18:50:05 +00:00
|
|
|
|
2015-12-15 21:33:41 +00:00
|
|
|
$updater = new BatchRowUpdate(
|
2013-05-09 18:50:05 +00:00
|
|
|
$reader,
|
2020-09-05 02:02:17 +00:00
|
|
|
$writer,
|
2022-11-13 07:53:42 +00:00
|
|
|
new SuppressionRowUpdateGenerator
|
2013-05-09 18:50:05 +00:00
|
|
|
);
|
2016-06-06 21:02:03 +00:00
|
|
|
$updater->setOutput( function ( $text ) {
|
|
|
|
$this->output( $text );
|
|
|
|
} );
|
2013-05-09 18:50:05 +00:00
|
|
|
$updater->execute();
|
2016-06-06 21:02:03 +00:00
|
|
|
return true;
|
2013-05-09 18:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 06:37:37 +00:00
|
|
|
$maintClass = UpdateEchoSchemaForSuppression::class;
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|