26require_once __DIR__ .
'/Maintenance.php';
35 parent::__construct();
37 $this->
addOption(
'force',
"Recalculate sha1 for rows that already have a value" );
38 $this->
addOption(
'multiversiononly',
"Calculate only for files with several versions" );
39 $this->
addOption(
'method',
"Use 'pipe' to pipe to mysql command line,\n" .
40 "\t\tdefault uses Database class",
false,
true );
43 'Fix for a specific file, without File: namespace prefixed',
50 return 'populate img_sha1';
54 return 'img_sha1 column of image table already populated.';
66 $method = $this->
getOption(
'method',
'normal' );
69 $isRegen = ( $force || $file !=
'' );
77 [
'img_name' => $file ],
83 $this->
output(
"Populating img_sha1 field for specified files\n" );
85 if ( $this->
hasOption(
'multiversiononly' ) ) {
87 $this->
output(
"Populating and recalculating img_sha1 field for versioned files\n" );
90 $this->
output(
"Populating and recalculating img_sha1 field\n" );
92 $conds = [
'img_sha1' =>
'' ];
93 $this->
output(
"Populating img_sha1 field\n" );
95 if ( $this->
hasOption(
'multiversiononly' ) ) {
96 $res = $dbw->select(
'oldimage',
97 [
'img_name' =>
'DISTINCT(oi_name)' ], $conds, __METHOD__ );
99 $res = $dbw->select(
'image', [
'img_name' ], $conds, __METHOD__ );
103 $imageTable = $dbw->tableName(
'image' );
104 $oldImageTable = $dbw->tableName(
'oldimage' );
106 if ( $method ==
'pipe' ) {
112 $cmd =
'mysql -u' . Shell::escape(
$wgDBuser ) .
115 $this->
output(
"Using pipe method\n" );
116 $pipe =
popen( $cmd,
'w' );
119 $numRows =
$res->numRows();
121 foreach (
$res as $row ) {
124 "Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100 ) );
134 $sha1 = $file->getRepo()->getFileSha1( $file->getPath() );
135 if (
strval( $sha1 ) !==
'' ) {
136 if ( $isRegen && $file->getSha1() !== $sha1 ) {
141 $sql =
"UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
142 " WHERE img_name=" . $dbw->addQuotes( $file->getName() );
143 if ( $method ==
'pipe' ) {
144 fwrite( $pipe,
"$sql;\n" );
146 $dbw->query( $sql, __METHOD__ );
151 foreach ( $file->getHistory() as $oldFile ) {
152 $sha1 = $oldFile->getRepo()->getFileSha1( $oldFile->getPath() );
153 if (
strval( $sha1 ) !==
'' ) {
154 if ( $isRegen && $oldFile->getSha1() !== $sha1 ) {
157 $oldFile->upgradeRow();
159 $sql =
"UPDATE $oldImageTable SET oi_sha1=" . $dbw->addQuotes( $sha1 ) .
160 " WHERE (oi_name=" . $dbw->addQuotes( $oldFile->getName() ) .
" AND" .
161 " oi_archive_name=" . $dbw->addQuotes( $oldFile->getArchiveName() ) .
")";
162 if ( $method ==
'pipe' ) {
163 fwrite( $pipe,
"$sql;\n" );
165 $dbw->query( $sql, __METHOD__ );
172 if ( $method ==
'pipe' ) {
177 $this->
output(
sprintf(
"\nDone %d files in %.1f seconds\n", $numRows,
$t ) );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgDBuser
Database username.
$wgDBserver
Database host name or IP address.
$wgDBpassword
Database user's password.
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
wfLocalFile( $title)
Get an object referring to a locally registered file.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script to populate the img_sha1 field.
execute()
Do the actual work.
doDBUpdates()
Do the actual work.
__construct()
Default constructor.
getUpdateKey()
Get the update key name to go in the update log table.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
require_once RUN_MAINTENANCE_IF_MAIN
controlled by the following MediaWiki still creates a BagOStuff but calls it to it are no ops If the cache daemon can t be it should also disable itself fairly $wgDBname
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file