/** * Updates the running Phar if any is available. * * @param string|Version $version The current version. * @param boolean $major Lock to current major version? * @param boolean $pre Allow pre-releases? * * @return boolean TRUE if an update was performed, FALSE if none available. */ public function update($version, $major = false, $pre = false, $newVersion = null) { if (false === $version instanceof Version) { $version = Parser::toVersion($version); } if ($newVersion !== null && false === $newVersion instanceof Version) { $newVersion = Parser::toVersion($newVersion); } if ($newVersion) { if (Comparator::isEqualTo($version, $newVersion)) { $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version)); } $update = $this->manifest->find($newVersion); if (null === $update) { $this->logger->error(sprintf('No update found for version "%s".', (string) $newVersion)); return false; } } else { $update = $this->manifest->findRecent($version, $major, $pre); } if (null === $update) { $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version)); return false; } if ($update instanceof Update) { if (!$this->downloadFile($update)) { return false; } } return true; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $manifest = Manifest::download($this->pharUpdateManifestUrl); $manager = new Manager($manifest, $this->getLocalFilesystem()); !$this->logger ?: $manager->setLogger($this->logger); $currentVersion = $this->getApplication()->getVersion(); $newVersion = null !== $input->getArgument('version') ? $input->getArgument('version') : null; $major = $input->getOption('major'); // Lock to current major version? $pre = true; //Allow pre-releases? $manager->update($currentVersion, $major, $pre, $newVersion); exit(0); // return immediately without use ConsoleTerminateEvent and EventDispatcher }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $manifest = Manifest::download($this->pharUpdateManifestUrl, $output->isDebug()); $manager = new Manager($manifest, $this->getLocalFilesystem()); !$this->logger ?: $manager->setLogger($this->logger); $currentVersion = $this->getApplication()->getVersion(); $newVersion = null !== $input->getArgument('version') ? $input->getArgument('version') : null; $major = $input->getOption('major'); // Lock to current major version? $pre = true; //Allow pre-releases? if (false === $manager->update($currentVersion, $major, $pre, $newVersion, $output->isDebug())) { return self::EXIT_ERROR; } return self::EXIT_SUCCESS; }