MediaWiki  REL1_23
populateRecentChangesSource.php
Go to the documentation of this file.
00001 <?php
00024 require_once dirname( __FILE__ ) . '/Maintenance.php';
00025 
00032 class PopulateRecentChangesSource extends LoggedUpdateMaintenance {
00033     public function __construct() {
00034         parent::__construct();
00035         $this->mDescription = "Populates rc_source field of the recentchanges table with the data in rc_type.";
00036         $this->setBatchSize( 100 );
00037     }
00038 
00039     protected function doDBUpdates() {
00040         $dbw = $this->getDB( DB_MASTER );
00041         if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
00042             $this->error( 'rc_source field in recentchanges table does not exist.' );
00043         }
00044 
00045         $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
00046         if ( !$start ) {
00047             $this->output( "Nothing to do.\n" );
00048             return true;
00049         }
00050         $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
00051         $end += $this->mBatchSize - 1;
00052         $blockStart = $start;
00053         $blockEnd = $start + $this->mBatchSize - 1;
00054 
00055         $updatedValues = $this->buildUpdateCondition( $dbw );
00056 
00057         while ( $blockEnd <= $end ) {
00058             $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
00059 
00060             $dbw->update(
00061                 'recentchanges',
00062                 array( $updatedValues ),
00063                 array(
00064                     "rc_source = ''",
00065                     "rc_id BETWEEN $blockStart AND $blockEnd"
00066                 ),
00067                 __METHOD__
00068             );
00069 
00070             $this->output( "." );
00071             wfWaitForSlaves();
00072 
00073             $blockStart += $this->mBatchSize;
00074             $blockEnd += $this->mBatchSize;
00075         }
00076 
00077         $this->output( "\nDone.\n" );
00078     }
00079 
00080     protected function getUpdateKey() {
00081         return __CLASS__;
00082     }
00083 
00084     protected function buildUpdateCondition( DatabaseBase $dbw ) {
00085         $rcNew = $dbw->addQuotes( RC_NEW );
00086         $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
00087         $rcEdit = $dbw->addQuotes( RC_EDIT );
00088         $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
00089         $rcLog = $dbw->addQuotes( RC_LOG );
00090         $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
00091         $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
00092         $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
00093 
00094         return "rc_source = CASE
00095                     WHEN rc_type = $rcNew THEN $rcSrcNew
00096                     WHEN rc_type = $rcEdit THEN $rcSrcEdit
00097                     WHEN rc_type = $rcLog THEN $rcSrcLog
00098                     WHEN rc_type = $rcExternal THEN $rcSrcExternal
00099                     ELSE ''
00100                 END";
00101     }
00102 }
00103 
00104 $maintClass = "PopulateRecentChangesSource";
00105 require_once RUN_MAINTENANCE_IF_MAIN;