Revision: Remove some unnecessary temporary variables for returns
[mediawiki.git] / maintenance / tidyUpT39714.php
blob06f4623e68c0855e55250ec1e686773b17a67a56
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 use MediaWiki\MediaWikiServices;
7 /**
8 * Fixes all rows affected by T39714
9 */
10 class TidyUpT39714 extends Maintenance {
11 public function execute() {
12 // Search for all log entries which are about changing the visability of other log entries.
13 $result = $this->getDB( DB_REPLICA )->select(
14 'logging',
15 [ 'log_id', 'log_params' ],
17 'log_type' => [ 'suppress', 'delete' ],
18 'log_action' => 'event',
19 'log_namespace' => NS_SPECIAL,
20 'log_title' => SpecialPage::getTitleFor( 'Log' )->getText()
22 __METHOD__
25 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
26 foreach ( $result as $row ) {
27 $ids = explode( ',', explode( "\n", $row->log_params )[0] );
28 // Work out what log entries were changed here.
29 $result = $this->getDB( DB_REPLICA )->select(
30 'logging',
31 'log_type',
32 [ 'log_id' => $ids ],
33 __METHOD__,
34 'DISTINCT'
36 if ( $result->numRows() === 1 ) {
37 // If there's only one type, the target title can be set to include it.
38 $logTitle = SpecialPage::getTitleFor( 'Log', $result->current()->log_type )->getText();
39 $this->output( 'Set log_title to "' . $logTitle . '" for log entry ' . $row->log_id . ".\n" );
40 $this->getDB( DB_MASTER )->update(
41 'logging',
42 [ 'log_title' => $logTitle ],
43 [ 'log_id' => $row->log_id ],
44 __METHOD__
46 $lbFactory->waitForReplication();
52 $maintClass = TidyUpT39714::class;
53 require_once RUN_MAINTENANCE_IF_MAIN;