protected function install(UpdateInfo $info, UpdateFile $file)
{
if (!$file->hashMatches($info->getChecksum())) {
throw new CouldNotUpdate(\__('Checksum mismatched'));
}
// Create a backup of the old Gadget:
\rename($this->filePath, $this->filePath . '.backup');
\rename($file->getPath(), $this->filePath);
$this->log('Begin install process', LogLevel::DEBUG, ['path' => $file->getPath(), 'hash' => $file->getHash(), 'version' => $file->getVersion(), 'size' => $file->getSize()]);
// Get metadata from the old version of this Gadget:
$oldAlias = Base64UrlSafe::encode(\random_bytes(48)) . '.phar';
$oldGadget = new \Phar($this->filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME);
$oldGadget->setAlias($oldAlias);
$oldMetadata = $oldGadget->getMetadata();
unset($oldGadget);
unset($oldAlias);
// Let's open the update package:
$newGadget = new \Phar($this->filePath, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, $this->pharAlias);
$newGadget->setAlias($this->pharAlias);
$metaData = $newGadget->getMetadata();
// We need to do this while we're replacing files.
$this->bringSiteDown();
Sandbox::safeRequire('phar://' . $this->pharAlias . '/update_trigger.php', $oldMetadata);
// Free up the updater alias
$garbageAlias = Base64UrlSafe::encode(\random_bytes(48)) . '.phar';
$newGadget->setAlias($garbageAlias);
unset($newGadget);
// Now bring it back up.
$this->bringSiteBackUp();
// Make sure we update the version info. in the DB cache:
$this->updateDBRecord('Gadget', $info);
if ($metaData) {
$this->updateJSON($info, $metaData);
}
self::$continuumLogger->store(LogLevel::INFO, 'Gadget update installed', $this->getLogContext($info, $file));
}