From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- maintenance/populateRecentChangesSource.php | 107 ++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 maintenance/populateRecentChangesSource.php (limited to 'maintenance/populateRecentChangesSource.php') diff --git a/maintenance/populateRecentChangesSource.php b/maintenance/populateRecentChangesSource.php new file mode 100644 index 00000000..25a51d72 --- /dev/null +++ b/maintenance/populateRecentChangesSource.php @@ -0,0 +1,107 @@ +mDescription = + "Populates rc_source field of the recentchanges table with the data in rc_type."; + $this->setBatchSize( 100 ); + } + + protected function doDBUpdates() { + $dbw = $this->getDB( DB_MASTER ); + if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) { + $this->error( 'rc_source field in recentchanges table does not exist.' ); + } + + $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ ); + if ( !$start ) { + $this->output( "Nothing to do.\n" ); + + return true; + } + $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ ); + $end += $this->mBatchSize - 1; + $blockStart = $start; + $blockEnd = $start + $this->mBatchSize - 1; + + $updatedValues = $this->buildUpdateCondition( $dbw ); + + while ( $blockEnd <= $end ) { + $cond = "rc_id BETWEEN $blockStart AND $blockEnd"; + + $dbw->update( + 'recentchanges', + array( $updatedValues ), + array( + "rc_source = ''", + "rc_id BETWEEN $blockStart AND $blockEnd" + ), + __METHOD__ + ); + + $this->output( "." ); + wfWaitForSlaves(); + + $blockStart += $this->mBatchSize; + $blockEnd += $this->mBatchSize; + } + + $this->output( "\nDone.\n" ); + } + + protected function getUpdateKey() { + return __CLASS__; + } + + protected function buildUpdateCondition( DatabaseBase $dbw ) { + $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"; + } +} + +$maintClass = "PopulateRecentChangesSource"; +require_once RUN_MAINTENANCE_IF_MAIN; -- cgit v1.2.3-54-g00ecf