mDescription = "Populate the fa_sha1 field from fa_storage_key"; } protected function getUpdateKey() { return 'populate fa_sha1'; } protected function updateSkippedMessage() { return 'fa_sha1 column of filearchive table already populated.'; } public function doDBUpdates() { $startTime = microtime( true ); $dbw = wfGetDB( DB_MASTER ); $table = 'filearchive'; $conds = array( 'fa_sha1' => '', 'fa_storage_key IS NOT NULL' ); if ( !$dbw->fieldExists( $table, 'fa_sha1', __METHOD__ ) ) { $this->output( "fa_sha1 column does not exist\n\n", true ); return false; } $this->output( "Populating fa_sha1 field from fa_storage_key\n" ); $endId = $dbw->selectField( $table, 'MAX(fa_id)', false, __METHOD__ ); $batchSize = $this->mBatchSize; $done = 0; do { $res = $dbw->select( $table, array( 'fa_id', 'fa_storage_key' ), $conds, __METHOD__, array( 'LIMIT' => $batchSize ) ); $i = 0; foreach ( $res as $row ) { if ( $row->fa_storage_key == '' ) { // Revision was missing pre-deletion continue; } $sha1 = LocalRepo::getHashFromKey( $row->fa_storage_key ); $dbw->update( $table, array( 'fa_sha1' => $sha1 ), array( 'fa_id' => $row->fa_id ), __METHOD__ ); $lastId = $row->fa_id; $i++; } $done += $i; if ( $i !== $batchSize ) { break; } // print status and let slaves catch up $this->output( sprintf( "id %d done (up to %d), %5.3f%% \r", $lastId, $endId, $lastId / $endId * 100 ) ); wfWaitForSlaves(); } while ( true ); $processingTime = microtime( true ) - $startTime; $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $done, $processingTime ) ); return true; // we only updated *some* files, don't log } } $maintClass = "PopulateFilearchiveSha1"; require_once RUN_MAINTENANCE_IF_MAIN;