TidyUpBug37714   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 37 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once __DIR__ . '/Maintenance.php';
3
4
/**
5
 * Fixes all rows affected by https://bugzilla.wikimedia.org/show_bug.cgi?id=37714
6
 */
7
class TidyUpBug37714 extends Maintenance {
8
	public function execute() {
9
		// Search for all log entries which are about changing the visability of other log entries.
10
		$result = $this->getDB( DB_REPLICA )->select(
11
			'logging',
12
			[ 'log_id', 'log_params' ],
13
			[
14
				'log_type' => [ 'suppress', 'delete' ],
15
				'log_action' => 'event',
16
				'log_namespace' => NS_SPECIAL,
17
				'log_title' => SpecialPage::getTitleFor( 'Log' )->getText()
18
			],
19
			__METHOD__
20
		);
21
22
		foreach ( $result as $row ) {
23
			$ids = explode( ',', explode( "\n", $row->log_params )[0] );
24
			$result = $this->getDB( DB_REPLICA )->select( // Work out what log entries were changed here.
25
				'logging',
26
				'log_type',
27
				[ 'log_id' => $ids ],
28
				__METHOD__,
29
				'DISTINCT'
30
			);
31
			if ( $result->numRows() === 1 ) {
32
				// If there's only one type, the target title can be set to include it.
33
				$logTitle = SpecialPage::getTitleFor( 'Log', $result->current()->log_type )->getText();
34
				$this->output( 'Set log_title to "' . $logTitle . '" for log entry ' . $row->log_id . ".\n" );
35
				$this->getDB( DB_MASTER )->update(
36
					'logging',
37
					[ 'log_title' => $logTitle ],
38
					[ 'log_id' => $row->log_id ],
39
					__METHOD__
40
				);
41
				wfWaitForSlaves();
0 ignored issues
show
Deprecated Code introduced by
The function wfWaitForSlaves() has been deprecated with message: since 1.27 Use LBFactory::waitForReplication

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
42
			}
43
		}
44
	}
45
}
46
47
$maintClass = 'TidyUpBug37714';
48
require_once RUN_MAINTENANCE_IF_MAIN;
49