MediaWiki  REL1_22
populateLogUsertext.php
Go to the documentation of this file.
00001 <?php
00027 require_once __DIR__ . '/Maintenance.php';
00028 
00035 class PopulateLogUsertext extends LoggedUpdateMaintenance {
00036     public function __construct() {
00037         parent::__construct();
00038         $this->mDescription = "Populates the log_user_text field";
00039         $this->setBatchSize( 100 );
00040     }
00041 
00042     protected function getUpdateKey() {
00043         return 'populate log_usertext';
00044     }
00045 
00046     protected function updateSkippedMessage() {
00047         return 'log_user_text column of logging table already populated.';
00048     }
00049 
00050     protected function doDBUpdates() {
00051         $db = $this->getDB( DB_MASTER );
00052         $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
00053         if ( !$start ) {
00054             $this->output( "Nothing to do.\n" );
00055             return true;
00056         }
00057         $end = $db->selectField( 'logging', 'MAX(log_id)', false, __METHOD__ );
00058 
00059         # Do remaining chunk
00060         $end += $this->mBatchSize - 1;
00061         $blockStart = $start;
00062         $blockEnd = $start + $this->mBatchSize - 1;
00063         while ( $blockEnd <= $end ) {
00064             $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
00065             $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";
00066             $res = $db->select( array( 'logging', 'user' ),
00067                 array( 'log_id', 'user_name' ), $cond, __METHOD__ );
00068 
00069             $db->begin( __METHOD__ );
00070             foreach ( $res as $row ) {
00071                 $db->update( 'logging', array( 'log_user_text' => $row->user_name ),
00072                     array( 'log_id' => $row->log_id ), __METHOD__ );
00073             }
00074             $db->commit( __METHOD__ );
00075             $blockStart += $this->mBatchSize;
00076             $blockEnd += $this->mBatchSize;
00077             wfWaitForSlaves();
00078         }
00079         $this->output( "Done populating log_user_text field.\n" );
00080         return true;
00081     }
00082 }
00083 
00084 $maintClass = "PopulateLogUsertext";
00085 require_once RUN_MAINTENANCE_IF_MAIN;