MediaWiki  1.23.2
populateFilearchiveSha1.php
Go to the documentation of this file.
1 <?php
24 require_once dirname( __FILE__ ) . '/Maintenance.php';
25 
33  public function __construct() {
34  parent::__construct();
35  $this->mDescription = "Populate the fa_sha1 field from fa_storage_key";
36  }
37 
38  protected function getUpdateKey() {
39  return 'populate fa_sha1';
40  }
41 
42  protected function updateSkippedMessage() {
43  return 'fa_sha1 column of filearchive table already populated.';
44  }
45 
46  public function doDBUpdates() {
47  $startTime = microtime( true );
48  $dbw = wfGetDB( DB_MASTER );
49  $table = 'filearchive';
50  $conds = array( 'fa_sha1' => '', 'fa_storage_key IS NOT NULL' );
51 
52  if ( !$dbw->fieldExists( $table, 'fa_sha1', __METHOD__ ) ) {
53  $this->output( "fa_sha1 column does not exist\n\n", true );
54  return false;
55  }
56 
57  $this->output( "Populating fa_sha1 field from fa_storage_key\n" );
58  $endId = $dbw->selectField( $table, 'MAX(fa_id)', false, __METHOD__ );
59 
60  $batchSize = $this->mBatchSize;
61  $done = 0;
62 
63  do {
64  $res = $dbw->select(
65  $table,
66  array( 'fa_id', 'fa_storage_key' ),
67  $conds,
68  __METHOD__,
69  array( 'LIMIT' => $batchSize )
70  );
71 
72  $i = 0;
73  foreach ( $res as $row ) {
74  if ( $row->fa_storage_key == '' ) {
75  // Revision was missing pre-deletion
76  continue;
77  }
78  $sha1 = LocalRepo::getHashFromKey( $row->fa_storage_key );
79  $dbw->update( $table,
80  array( 'fa_sha1' => $sha1 ),
81  array( 'fa_id' => $row->fa_id ),
82  __METHOD__
83  );
84  $lastId = $row->fa_id;
85  $i++;
86  }
87 
88  $done += $i;
89  if ( $i !== $batchSize ) {
90  break;
91  }
92 
93  // print status and let slaves catch up
94  $this->output( sprintf(
95  "id %d done (up to %d), %5.3f%% \r", $lastId, $endId, $lastId / $endId * 100 ) );
97  } while ( true );
98 
99  $processingTime = microtime( true ) - $startTime;
100  $this->output( sprintf( "\nDone %d files in %.1f seconds\n", $done, $processingTime ) );
101 
102  return true; // we only updated *some* files, don't log
103  }
104 }
105 
106 $maintClass = "PopulateFilearchiveSha1";
107 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:97
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
PopulateFilearchiveSha1\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateFilearchiveSha1.php:42
PopulateFilearchiveSha1\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateFilearchiveSha1.php:38
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
LocalRepo\getHashFromKey
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
Definition: LocalRepo.php:156
PopulateFilearchiveSha1\__construct
__construct()
Default constructor.
Definition: populateFilearchiveSha1.php:33
PopulateFilearchiveSha1\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateFilearchiveSha1.php:46
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1209
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3795
$maintClass
$maintClass
Definition: populateFilearchiveSha1.php:106
PopulateFilearchiveSha1
Maintenance script to populate the fa_sha1 field.
Definition: populateFilearchiveSha1.php:32
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
$res
$res
Definition: database.txt:21