MediaWiki
REL1_35
populateFilearchiveSha1.php
Go to the documentation of this file.
1
<?php
24
require_once __DIR__ .
'/Maintenance.php'
;
25
26
use
MediaWiki\MediaWikiServices
;
27
34
class
PopulateFilearchiveSha1
extends
LoggedUpdateMaintenance
{
35
public
function
__construct
() {
36
parent::__construct();
37
$this->
addDescription
(
'Populate the fa_sha1 field from fa_storage_key'
);
38
}
39
40
protected
function
getUpdateKey
() {
41
return
'populate fa_sha1'
;
42
}
43
44
protected
function
updateSkippedMessage
() {
45
return
'fa_sha1 column of filearchive table already populated.'
;
46
}
47
48
public
function
doDBUpdates
() {
49
$startTime = microtime(
true
);
50
$dbw = $this->
getDB
(
DB_MASTER
);
51
$table =
'filearchive'
;
52
$conds = [
'fa_sha1'
=>
''
,
'fa_storage_key IS NOT NULL'
];
53
54
if
( !$dbw->fieldExists( $table,
'fa_sha1'
, __METHOD__ ) ) {
55
$this->
output
(
"fa_sha1 column does not exist\n\n"
,
true
);
56
57
return
false
;
58
}
59
60
$this->
output
(
"Populating fa_sha1 field from fa_storage_key\n"
);
61
$endId = $dbw->selectField( $table,
'MAX(fa_id)'
,
''
, __METHOD__ );
62
63
$batchSize = $this->
getBatchSize
();
64
$done = 0;
65
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
66
67
do
{
68
$res
= $dbw->select(
69
$table,
70
[
'fa_id'
,
'fa_storage_key'
],
71
$conds,
72
__METHOD__,
73
[
'LIMIT'
=> $batchSize ]
74
);
75
76
$i = 0;
77
foreach
(
$res
as $row ) {
78
if
( $row->fa_storage_key ==
''
) {
79
// Revision was missing pre-deletion
80
continue
;
81
}
82
$sha1 =
LocalRepo::getHashFromKey
( $row->fa_storage_key );
83
$dbw->update( $table,
84
[
'fa_sha1'
=> $sha1 ],
85
[
'fa_id'
=> $row->fa_id ],
86
__METHOD__
87
);
88
$lastId = $row->fa_id;
89
$i++;
90
}
91
92
$done += $i;
93
if
( $i !== $batchSize ) {
94
break
;
95
}
96
97
// print status and let replica DBs catch up
98
$this->
output
( sprintf(
99
"id %d done (up to %d), %5.3f%% \r"
, $lastId, $endId, $lastId / $endId * 100 ) );
100
$lbFactory->waitForReplication();
101
}
while
(
true
);
102
103
$processingTime = microtime(
true
) - $startTime;
104
$this->
output
( sprintf(
"\nDone %d files in %.1f seconds\n"
, $done, $processingTime ) );
105
106
// we only updated *some* files, don't log
107
return
true
;
108
}
109
}
110
111
$maintClass
= PopulateFilearchiveSha1::class;
112
require_once
RUN_MAINTENANCE_IF_MAIN
;
getDB
getDB()
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition
Maintenance.php:38
LocalRepo\getHashFromKey
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
Definition
LocalRepo.php:183
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition
LoggedUpdateMaintenance.php:26
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:432
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition
Maintenance.php:364
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:325
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition
MediaWikiServices.php:152
PopulateFilearchiveSha1
Maintenance script to populate the fa_sha1 field.
Definition
populateFilearchiveSha1.php:34
PopulateFilearchiveSha1\__construct
__construct()
Default constructor.
Definition
populateFilearchiveSha1.php:35
PopulateFilearchiveSha1\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition
populateFilearchiveSha1.php:44
PopulateFilearchiveSha1\doDBUpdates
doDBUpdates()
Do the actual work.
Definition
populateFilearchiveSha1.php:48
PopulateFilearchiveSha1\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition
populateFilearchiveSha1.php:40
$maintClass
$maintClass
Definition
populateFilearchiveSha1.php:111
DB_MASTER
const DB_MASTER
Definition
defines.php:29
$res
$res
Definition
testCompression.php:57
maintenance
populateFilearchiveSha1.php
Generated on Sat Apr 6 2024 00:08:27 for MediaWiki by
1.9.8