MediaWiki
REL1_21
|
00001 <?php 00024 require_once( __DIR__ . '/Maintenance.php' ); 00025 00032 class PopulateRevisionLength extends LoggedUpdateMaintenance { 00033 public function __construct() { 00034 parent::__construct(); 00035 $this->mDescription = "Populates the rev_len field"; 00036 $this->setBatchSize( 200 ); 00037 } 00038 00039 protected function getUpdateKey() { 00040 return 'populate rev_len'; 00041 } 00042 00043 protected function updateSkippedMessage() { 00044 return 'rev_len column of revision table already populated.'; 00045 } 00046 00047 public function doDBUpdates() { 00048 $db = $this->getDB( DB_MASTER ); 00049 if ( !$db->tableExists( 'revision' ) ) { 00050 $this->error( "revision table does not exist", true ); 00051 } else if ( !$db->fieldExists( 'revision', 'rev_sha1', __METHOD__ ) ) { 00052 $this->output( "rev_sha1 column does not exist\n\n", true ); 00053 return false; 00054 } 00055 00056 $this->output( "Populating rev_len column\n" ); 00057 00058 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ ); 00059 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ ); 00060 if ( !$start || !$end ) { 00061 $this->output( "...revision table seems to be empty.\n" ); 00062 return true; 00063 } 00064 00065 # Do remaining chunks 00066 $blockStart = intval( $start ); 00067 $blockEnd = intval( $start ) + $this->mBatchSize - 1; 00068 $count = 0; 00069 $missing = 0; 00070 $fields = Revision::selectFields(); 00071 while ( $blockStart <= $end ) { 00072 $this->output( "...doing rev_id from $blockStart to $blockEnd\n" ); 00073 $res = $db->select( 'revision', 00074 $fields, 00075 array( "rev_id >= $blockStart", 00076 "rev_id <= $blockEnd", 00077 "rev_len IS NULL" ), 00078 __METHOD__ ); 00079 # Go through and update rev_len from these rows. 00080 foreach ( $res as $row ) { 00081 $rev = new Revision( $row ); 00082 $content = $rev->getContent(); 00083 if ( !$content ) { 00084 # This should not happen, but sometimes does (bug 20757) 00085 $this->output( "Content of revision {$row->rev_id} unavailable!\n" ); 00086 $missing++; 00087 } 00088 else { 00089 # Update the row... 00090 $db->update( 'revision', 00091 array( 'rev_len' => $content->getSize() ), 00092 array( 'rev_id' => $row->rev_id ), 00093 __METHOD__ ); 00094 $count++; 00095 } 00096 } 00097 $blockStart += $this->mBatchSize; 00098 $blockEnd += $this->mBatchSize; 00099 wfWaitForSlaves(); 00100 } 00101 00102 $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" ); 00103 return true; 00104 } 00105 } 00106 00107 $maintClass = "PopulateRevisionLength"; 00108 require_once( RUN_MAINTENANCE_IF_MAIN );