/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new ConsoleIO($input, $output);
if ($this->isInstalledAsPhar() === false) {
$io->error('Self-update is available only for PHAR version');
return 1;
}
$manifest = $this->getManifestFile();
$remoteVersion = $manifest['version'];
$localVersion = $this->getApplication()->getVersion();
if ($localVersion === $remoteVersion) {
$io->success('Spress is already up to date');
return;
}
$remoteFilename = $manifest['url'];
$localFilename = $_SERVER['argv'][0];
$tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
$io->newLine();
$io->write('Downloading Spress...');
$io->newLine();
$this->downloadRemoteFilename($remoteFilename);
try {
copy($remoteFilename, $tempFilename);
chmod($tempFilename, 0777 & ~umask());
$phar = new \Phar($tempFilename);
unset($phar);
if (@rename($tempFilename, $localFilename) !== true) {
$io->error(sprintf('Cannot rename "%s" to "%s" probably because permission denied.', $tempFilename, $localFilename));
return 1;
}
$io->success(sprintf('Spress updated from %s to %s.', $localVersion, $remoteVersion));
if (isset($manifest['changelog_url']) === true) {
$io->write(sprintf('<comment>Go to <info>%s</info> for more details.</comment>', $manifest['changelog_url']));
}
} catch (\Exception $e) {
if ($e instanceof \UnexpectedValueException === false && $e instanceof \PharException === false) {
throw $e;
}
unlink($tempFilename);
$io->error([sprintf('The download is corrupt (%s).', $e->getMessage()), 'Please re-run the self-update command to try again.']);
return 1;
}
}