summaryrefslogtreecommitdiff
blob: dd8c966d7b879706080d58f8ac59cdbb557937d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?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;

		$reader = new BatchRowIterator( MWEchoDbFactory::getDB( DB_REPLICA ), $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( MWEchoDbFactory::getDB( DB_MASTER ), $this->table, $wgEchoCluster ),
			new EchoSuppressionRowUpdateGenerator
		);
		$updater->setOutput( function ( $text ) {
			$this->output( $text );
		} );
		$updater->execute();
		return true;
	}
}

$maintClass = 'UpdateEchoSchemaForSuppression'; // Tells it to run the class
require_once RUN_MAINTENANCE_IF_MAIN;