Updating composer/semver (1.5.1 => 1.5.2)
[mediawiki.git] / maintenance / populateRecentChangesSource.php
blobc12b2df9ec4ef43381b96b0b75d13d0291eee1da
1 <?php
2 /**
3 * Upgrade script to populate the rc_source field
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.
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.
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
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 use MediaWiki\MediaWikiServices;
27 use Wikimedia\Rdbms\IDatabase;
29 /**
30 * Maintenance script to populate the rc_source field.
32 * @ingroup Maintenance
33 * @since 1.22
35 class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription(
39 'Populates rc_source field of the recentchanges table with the data in rc_type.' );
40 $this->setBatchSize( 100 );
43 protected function doDBUpdates() {
44 $dbw = $this->getDB( DB_MASTER );
45 $batchSize = $this->getBatchSize();
46 if ( !$dbw->fieldExists( 'recentchanges', 'rc_source', __METHOD__ ) ) {
47 $this->error( 'rc_source field in recentchanges table does not exist.' );
50 $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', '', __METHOD__ );
51 if ( !$start ) {
52 $this->output( "Nothing to do.\n" );
54 return true;
56 $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', '', __METHOD__ );
57 $end += $batchSize - 1;
58 $blockStart = $start;
59 $blockEnd = $start + $batchSize - 1;
61 $updatedValues = $this->buildUpdateCondition( $dbw );
63 while ( $blockEnd <= $end ) {
64 $dbw->update(
65 'recentchanges',
66 [ $updatedValues ],
68 "rc_source = ''",
69 "rc_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd
71 __METHOD__
74 $this->output( "." );
75 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
77 $blockStart += $batchSize;
78 $blockEnd += $batchSize;
81 $this->output( "\nDone.\n" );
84 protected function getUpdateKey() {
85 return __CLASS__;
88 protected function buildUpdateCondition( IDatabase $dbw ) {
89 $rcNew = $dbw->addQuotes( RC_NEW );
90 $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
91 $rcEdit = $dbw->addQuotes( RC_EDIT );
92 $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
93 $rcLog = $dbw->addQuotes( RC_LOG );
94 $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
95 $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
96 $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
98 return "rc_source = CASE
99 WHEN rc_type = $rcNew THEN $rcSrcNew
100 WHEN rc_type = $rcEdit THEN $rcSrcEdit
101 WHEN rc_type = $rcLog THEN $rcSrcLog
102 WHEN rc_type = $rcExternal THEN $rcSrcExternal
103 ELSE ''
104 END";
108 $maintClass = PopulateRecentChangesSource::class;
109 require_once RUN_MAINTENANCE_IF_MAIN;