MediaWiki  REL1_24
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 
00056             return true;
00057         }
00058         $end = $db->selectField( 'logging', 'MAX(log_id)', false, __METHOD__ );
00059 
00060         # Do remaining chunk
00061         $end += $this->mBatchSize - 1;
00062         $blockStart = $start;
00063         $blockEnd = $start + $this->mBatchSize - 1;
00064         while ( $blockEnd <= $end ) {
00065             $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
00066             $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";
00067             $res = $db->select( array( 'logging', 'user' ),
00068                 array( 'log_id', 'user_name' ), $cond, __METHOD__ );
00069 
00070             $db->begin( __METHOD__ );
00071             foreach ( $res as $row ) {
00072                 $db->update( 'logging', array( 'log_user_text' => $row->user_name ),
00073                     array( 'log_id' => $row->log_id ), __METHOD__ );
00074             }
00075             $db->commit( __METHOD__ );
00076             $blockStart += $this->mBatchSize;
00077             $blockEnd += $this->mBatchSize;
00078             wfWaitForSlaves();
00079         }
00080         $this->output( "Done populating log_user_text field.\n" );
00081 
00082         return true;
00083     }
00084 }
00085 
00086 $maintClass = "PopulateLogUsertext";
00087 require_once RUN_MAINTENANCE_IF_MAIN;