+ $sql = "UPDATE $imageTable SET img_sha1=" . $dbw->addQuotes( $sha1 ) .
+ " WHERE img_name=" . $dbw->addQuotes( $file->getName() );
+ if ( $method == 'pipe' ) {
+ fwrite( $pipe, "$sql;\n" );
+ } else {
+ $dbw->query( $sql, __METHOD__ );
+ }
+ }
+ }
+ // Upgrade the old file versions...
+ foreach ( $file->getHistory() as $oldFile ) {
+ $sha1 = $oldFile->getRepo()->getFileSha1( $oldFile->getPath() );
+ if ( strval( $sha1 ) !== '' ) { // file on disk and hashed properly
+ if ( $isRegen && $oldFile->getSha1() !== $sha1 ) {
+ // The population was probably done already. If the old SHA1
+ // does not match, then both fix the SHA1 and the metadata.
+ $oldFile->upgradeRow();
+ } else {
+ $sql = "UPDATE $oldImageTable SET oi_sha1=" . $dbw->addQuotes( $sha1 ) .
+ " WHERE (oi_name=" . $dbw->addQuotes( $oldFile->getName() ) . " AND" .
+ " oi_archive_name=" . $dbw->addQuotes( $oldFile->getArchiveName() ) . ")";
+ if ( $method == 'pipe' ) {
+ fwrite( $pipe, "$sql;\n" );
+ } else {
+ $dbw->query( $sql, __METHOD__ );
+ }
+ }