Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PopulateRecentChangesSource | |
0.00% |
0 / 54 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
doDBUpdates | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
20 | |||
getUpdateKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
buildUpdateCondition | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Upgrade script to populate the rc_source field |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Maintenance |
22 | */ |
23 | |
24 | require_once __DIR__ . '/Maintenance.php'; |
25 | |
26 | use Wikimedia\Rdbms\IDatabase; |
27 | |
28 | /** |
29 | * Maintenance script to populate the rc_source field. |
30 | * |
31 | * @ingroup Maintenance |
32 | * @since 1.22 |
33 | */ |
34 | class PopulateRecentChangesSource extends LoggedUpdateMaintenance { |
35 | public function __construct() { |
36 | parent::__construct(); |
37 | $this->addDescription( |
38 | 'Populates rc_source field of the recentchanges table with the data in rc_type.' ); |
39 | $this->setBatchSize( 100 ); |
40 | } |
41 | |
42 | protected function doDBUpdates() { |
43 | $dbw = $this->getDB( DB_PRIMARY ); |
44 | $batchSize = $this->getBatchSize(); |
45 | if ( !$dbw->fieldExists( 'recentchanges', 'rc_source', __METHOD__ ) ) { |
46 | $this->error( 'rc_source field in recentchanges table does not exist.' ); |
47 | } |
48 | |
49 | $start = $dbw->newSelectQueryBuilder() |
50 | ->select( 'MIN(rc_id)' ) |
51 | ->from( 'recentchanges' ) |
52 | ->caller( __METHOD__ )->fetchField(); |
53 | if ( !$start ) { |
54 | $this->output( "Nothing to do.\n" ); |
55 | |
56 | return true; |
57 | } |
58 | $end = $dbw->newSelectQueryBuilder() |
59 | ->select( 'MAX(rc_id)' ) |
60 | ->from( 'recentchanges' ) |
61 | ->caller( __METHOD__ )->fetchField(); |
62 | $end += $batchSize - 1; |
63 | $blockStart = $start; |
64 | $blockEnd = $start + $batchSize - 1; |
65 | |
66 | $updatedValues = $this->buildUpdateCondition( $dbw ); |
67 | |
68 | while ( $blockEnd <= $end ) { |
69 | $dbw->newUpdateQueryBuilder() |
70 | ->update( 'recentchanges' ) |
71 | ->set( [ $updatedValues ] ) |
72 | ->where( [ |
73 | 'rc_source' => '', |
74 | $dbw->expr( 'rc_id', '>=', (int)$blockStart ), |
75 | $dbw->expr( 'rc_id', '<=', (int)$blockEnd ), |
76 | ] ) |
77 | ->caller( __METHOD__ ) |
78 | ->execute(); |
79 | |
80 | $this->output( "." ); |
81 | $this->waitForReplication(); |
82 | |
83 | $blockStart += $batchSize; |
84 | $blockEnd += $batchSize; |
85 | } |
86 | |
87 | $this->output( "\nDone.\n" ); |
88 | } |
89 | |
90 | protected function getUpdateKey() { |
91 | return __CLASS__; |
92 | } |
93 | |
94 | protected function buildUpdateCondition( IDatabase $dbw ) { |
95 | $rcNew = $dbw->addQuotes( RC_NEW ); |
96 | $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW ); |
97 | $rcEdit = $dbw->addQuotes( RC_EDIT ); |
98 | $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT ); |
99 | $rcLog = $dbw->addQuotes( RC_LOG ); |
100 | $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG ); |
101 | $rcExternal = $dbw->addQuotes( RC_EXTERNAL ); |
102 | $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL ); |
103 | |
104 | return "rc_source = CASE |
105 | WHEN rc_type = $rcNew THEN $rcSrcNew |
106 | WHEN rc_type = $rcEdit THEN $rcSrcEdit |
107 | WHEN rc_type = $rcLog THEN $rcSrcLog |
108 | WHEN rc_type = $rcExternal THEN $rcSrcExternal |
109 | ELSE '' |
110 | END"; |
111 | } |
112 | } |
113 | |
114 | $maintClass = PopulateRecentChangesSource::class; |
115 | require_once RUN_MAINTENANCE_IF_MAIN; |