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