2013-10-25 20:10:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Upgrade script to populate the rc_source field
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2014-04-22 21:07:08 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2013-10-25 20:10:42 +00:00
|
|
|
|
2020-05-01 00:36:46 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-03-30 20:46:06 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
|
|
|
|
|
2013-10-25 20:10:42 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to populate the rc_source field.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription(
|
|
|
|
|
'Populates rc_source field of the recentchanges table with the data in rc_type.' );
|
2013-10-25 20:10:42 +00:00
|
|
|
$this->setBatchSize( 100 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function doDBUpdates() {
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2017-11-08 03:35:11 +00:00
|
|
|
$batchSize = $this->getBatchSize();
|
2020-06-07 16:23:08 +00:00
|
|
|
if ( !$dbw->fieldExists( 'recentchanges', 'rc_source', __METHOD__ ) ) {
|
2013-10-25 20:10:42 +00:00
|
|
|
$this->error( 'rc_source field in recentchanges table does not exist.' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 18:37:26 +00:00
|
|
|
$start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', '', __METHOD__ );
|
2013-10-25 20:10:42 +00:00
|
|
|
if ( !$start ) {
|
|
|
|
|
$this->output( "Nothing to do.\n" );
|
2014-04-23 18:09:13 +00:00
|
|
|
|
2013-10-25 20:10:42 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2018-02-27 18:37:26 +00:00
|
|
|
$end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', '', __METHOD__ );
|
2017-11-08 03:35:11 +00:00
|
|
|
$end += $batchSize - 1;
|
2013-10-25 20:10:42 +00:00
|
|
|
$blockStart = $start;
|
2017-11-08 03:35:11 +00:00
|
|
|
$blockEnd = $start + $batchSize - 1;
|
2013-10-25 20:10:42 +00:00
|
|
|
|
|
|
|
|
$updatedValues = $this->buildUpdateCondition( $dbw );
|
|
|
|
|
|
|
|
|
|
while ( $blockEnd <= $end ) {
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'recentchanges',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $updatedValues ],
|
|
|
|
|
[
|
2013-10-25 20:10:42 +00:00
|
|
|
"rc_source = ''",
|
2017-12-08 19:35:38 +00:00
|
|
|
"rc_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2013-10-25 20:10:42 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->output( "." );
|
2020-05-01 00:36:46 +00:00
|
|
|
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
|
2013-10-25 20:10:42 +00:00
|
|
|
|
2017-11-08 03:35:11 +00:00
|
|
|
$blockStart += $batchSize;
|
|
|
|
|
$blockEnd += $batchSize;
|
2013-10-25 20:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output( "\nDone.\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getUpdateKey() {
|
|
|
|
|
return __CLASS__;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-30 20:46:06 +00:00
|
|
|
protected function buildUpdateCondition( IDatabase $dbw ) {
|
2013-10-25 20:10:42 +00:00
|
|
|
$rcNew = $dbw->addQuotes( RC_NEW );
|
|
|
|
|
$rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
|
|
|
|
|
$rcEdit = $dbw->addQuotes( RC_EDIT );
|
|
|
|
|
$rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
|
|
|
|
|
$rcLog = $dbw->addQuotes( RC_LOG );
|
|
|
|
|
$rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
|
|
|
|
|
$rcExternal = $dbw->addQuotes( RC_EXTERNAL );
|
|
|
|
|
$rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
|
|
|
|
|
|
|
|
|
|
return "rc_source = CASE
|
|
|
|
|
WHEN rc_type = $rcNew THEN $rcSrcNew
|
|
|
|
|
WHEN rc_type = $rcEdit THEN $rcSrcEdit
|
|
|
|
|
WHEN rc_type = $rcLog THEN $rcSrcLog
|
|
|
|
|
WHEN rc_type = $rcExternal THEN $rcSrcExternal
|
|
|
|
|
ELSE ''
|
|
|
|
|
END";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = PopulateRecentChangesSource::class;
|
2013-10-25 20:10:42 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|