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