summaryrefslogtreecommitdiff
path: root/maintenance/tidyUpBug37714.php
blob: 1ad9c7ee25d1d736e0a0aad3d74961c7b9dae7dc (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
<?php
require_once __DIR__ . '/Maintenance.php';

/**
 * Fixes all rows affected by https://bugzilla.wikimedia.org/show_bug.cgi?id=37714
 */
class TidyUpBug37714 extends Maintenance {
	public function execute() {
		// Search for all log entries which are about changing the visability of other log entries.
		$result = wfGetDB( DB_SLAVE )->select(
			'logging',
			array( 'log_id', 'log_params' ),
			array(
				'log_type' => array( 'suppress', 'delete' ),
				'log_action' => 'event',
				'log_namespace' => NS_SPECIAL,
				'log_title' => SpecialPage::getTitleFor( 'Log' )->getText()
			),
			__METHOD__
		);

		foreach ( $result as $row ) {
			$paramLines = explode( "\n", $row->log_params );
			$ids = explode( ',', $paramLines[0] ); // Array dereferencing is PHP >= 5.4 :(
			$result = wfGetDB( DB_SLAVE )->select( // Work out what log entries were changed here.
				'logging',
				'log_type',
				array( 'log_id' => $ids ),
				__METHOD__,
				'DISTINCT'
			);
			if ( $result->numRows() === 1 ) {
				// If there's only one type, the target title can be set to include it.
				$logTitle = SpecialPage::getTitleFor( 'Log', $result->current()->log_type )->getText();
				$this->output( 'Set log_title to "' . $logTitle . '" for log entry ' . $row->log_id . ".\n" );
				wfGetDB( DB_MASTER )->update(
					'logging',
					array( 'log_title' => $logTitle ),
					array( 'log_id' => $row->log_id ),
					__METHOD__
				);
				wfWaitForSlaves();
			}
		}
	}
}

$maintClass = 'TidyUpBug37714';
require_once RUN_MAINTENANCE_IF_MAIN;