Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PopulateGlobalRenameLogSearch
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
20
 insert
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CentralAuth\Maintenance;
4
5use LogEntryBase;
6use MediaWiki\Maintenance\Maintenance;
7
8$IP = getenv( 'MW_INSTALL_PATH' );
9if ( $IP === false ) {
10    $IP = __DIR__ . '/../../..';
11}
12require_once "$IP/maintenance/Maintenance.php";
13
14/**
15 * Script to back-populate log_search for global rename entries
16 */
17class PopulateGlobalRenameLogSearch extends Maintenance {
18
19    public function __construct() {
20        parent::__construct();
21        $this->requireExtension( 'CentralAuth' );
22        $this->setBatchSize( 50 );
23    }
24
25    public function execute() {
26        $dbr = $this->getDB( DB_REPLICA );
27        $rows = $dbr->newSelectQueryBuilder()
28            ->select( [ 'log_id', 'log_params' ] )
29            ->from( 'logging' )
30            ->leftJoin( 'log_search', null, 'log_id=ls_log_id' )
31            ->where( [
32                'log_type' => 'gblrename',
33                'log_action' => 'rename',
34                'ls_field' => null,
35            ] )
36            ->caller( __METHOD__ )
37            ->fetchResultSet();
38
39        $insert = [];
40
41        foreach ( $rows as $row ) {
42            $params = LogEntryBase::extractParams( $row->log_params );
43            $insert[] = [
44                'ls_field' => 'oldname',
45                'ls_value' => $params['4::olduser'],
46                'ls_log_id' => $row->log_id,
47            ];
48            if ( count( $insert ) >= $this->mBatchSize ) {
49                $this->insert( $insert );
50                $insert = [];
51            }
52        }
53        if ( $insert ) {
54            $this->insert( $insert );
55        }
56    }
57
58    /**
59     * @param array $rows
60     */
61    private function insert( array $rows ) {
62        $count = count( $rows );
63        $this->output( "Inserting $count rows into log_search\n" );
64        $dbw = $this->getPrimaryDB();
65        $dbw->newInsertQueryBuilder()
66            ->insertInto( 'log_search' )
67            ->ignore()
68            ->rows( $rows )
69            ->caller( __METHOD__ )
70            ->execute();
71        $this->waitForReplication();
72    }
73}
74
75$maintClass = PopulateGlobalRenameLogSearch::class;
76require_once RUN_MAINTENANCE_IF_MAIN;