MediaWiki
REL1_24
|
00001 <?php 00024 require_once dirname( __FILE__ ) . '/Maintenance.php'; 00025 00032 class PopulateFilearchiveSha1 extends LoggedUpdateMaintenance { 00033 public function __construct() { 00034 parent::__construct(); 00035 $this->mDescription = "Populate the fa_sha1 field from fa_storage_key"; 00036 } 00037 00038 protected function getUpdateKey() { 00039 return 'populate fa_sha1'; 00040 } 00041 00042 protected function updateSkippedMessage() { 00043 return 'fa_sha1 column of filearchive table already populated.'; 00044 } 00045 00046 public function doDBUpdates() { 00047 $startTime = microtime( true ); 00048 $dbw = wfGetDB( DB_MASTER ); 00049 $table = 'filearchive'; 00050 $conds = array( 'fa_sha1' => '', 'fa_storage_key IS NOT NULL' ); 00051 00052 if ( !$dbw->fieldExists( $table, 'fa_sha1', __METHOD__ ) ) { 00053 $this->output( "fa_sha1 column does not exist\n\n", true ); 00054 00055 return false; 00056 } 00057 00058 $this->output( "Populating fa_sha1 field from fa_storage_key\n" ); 00059 $endId = $dbw->selectField( $table, 'MAX(fa_id)', false, __METHOD__ ); 00060 00061 $batchSize = $this->mBatchSize; 00062 $done = 0; 00063 00064 do { 00065 $res = $dbw->select( 00066 $table, 00067 array( 'fa_id', 'fa_storage_key' ), 00068 $conds, 00069 __METHOD__, 00070 array( 'LIMIT' => $batchSize ) 00071 ); 00072 00073 $i = 0; 00074 foreach ( $res as $row ) { 00075 if ( $row->fa_storage_key == '' ) { 00076 // Revision was missing pre-deletion 00077 continue; 00078 } 00079 $sha1 = LocalRepo::getHashFromKey( $row->fa_storage_key ); 00080 $dbw->update( $table, 00081 array( 'fa_sha1' => $sha1 ), 00082 array( 'fa_id' => $row->fa_id ), 00083 __METHOD__ 00084 ); 00085 $lastId = $row->fa_id; 00086 $i++; 00087 } 00088 00089 $done += $i; 00090 if ( $i !== $batchSize ) { 00091 break; 00092 } 00093 00094 // print status and let slaves catch up 00095 $this->output( sprintf( 00096 "id %d done (up to %d), %5.3f%% \r", $lastId, $endId, $lastId / $endId * 100 ) ); 00097 wfWaitForSlaves(); 00098 } while ( true ); 00099 00100 $processingTime = microtime( true ) - $startTime; 00101 $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $done, $processingTime ) ); 00102 00103 return true; // we only updated *some* files, don't log 00104 } 00105 } 00106 00107 $maintClass = "PopulateFilearchiveSha1"; 00108 require_once RUN_MAINTENANCE_IF_MAIN;