public function testCanDetectNewRemoteVersionAndStoreVersions() { $this->updater->getStrategy()->setVersionUrl('file://' . $this->files . '/good.version'); $this->assertTrue($this->updater->hasUpdate()); $this->assertEquals('da39a3ee5e6b4b0d3255bfef95601890afd80709', $this->updater->getOldVersion()); $this->assertEquals('1af1b9c94dea1ff337587bfa9109f1dad1ec7b9b', $this->updater->getNewVersion()); }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new PuliStrategy(); $updateStrategy->setStability($this->getStability($args)); // false: disable signed releases, otherwise the updater will look for // a *.pubkey file for the PHAR $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); return 0; } $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); return 0; }
/** * @param Updater $updater */ protected function update(Updater $updater) { $this->output->writeln('Updating...' . PHP_EOL); try { $result = $updater->update(); $newVersion = $updater->getNewVersion(); $oldVersion = $updater->getOldVersion(); if (strlen($newVersion) == 40) { $newVersion = 'dev-' . $newVersion; } if (strlen($oldVersion) == 40) { $oldVersion = 'dev-' . $oldVersion; } if ($result) { $this->output->writeln('<fg=green>Skype has been updated.</fg=green>'); $this->output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $newVersion)); $this->output->writeln(sprintf('<fg=green>Previous version was:</fg=green> <options=bold>%s</options=bold>.', $oldVersion)); } else { $this->output->writeln('<fg=green>Skype is currently up to date.</fg=green>'); $this->output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $oldVersion)); } } catch (\Exception $e) { $this->output->writeln(sprintf('Error: <fg=yellow>%s</fg=yellow>', $e->getMessage())); } $this->output->write(PHP_EOL); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $application = $this->getApplication(); $manifest = $input->getOption('manifest') ?: 'http://drupalconsole.com/manifest.json'; $currentVersion = $input->getOption('current-version') ?: $application->getVersion(); $major = $input->getOption('major'); if (!extension_loaded('Phar') || !\Phar::running(false)) { $io->error($this->trans('commands.self-update.messages.not-phar')); $io->block($this->trans('commands.self-update.messages.instructions')); return 1; } $io->info(sprintf($this->trans('commands.self-update.messages.check'), $currentVersion)); $updater = new Updater(null, false); $strategy = new ManifestStrategy($currentVersion, $major, $manifest); $updater->setStrategyObject($strategy); if (!$updater->hasUpdate()) { $io->info(sprintf($this->trans('commands.self-update.messages.current-version'), $currentVersion)); return 0; } $oldVersion = $updater->getOldVersion(); $newVersion = $updater->getNewVersion(); if (!$io->confirm(sprintf($this->trans('commands.self-update.questions.update'), $oldVersion, $newVersion), true)) { return 1; } $io->comment(sprintf($this->trans('commands.self-update.messages.update'), $newVersion)); $updater->update(); $io->success(sprintf($this->trans('commands.self-update.messages.success'), $oldVersion, $newVersion)); // Errors appear if new classes are instantiated after this stage // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP // can't read files properly from the overwritten Phar, or perhaps it's // because the autoloader's name has changed. We avoid the problem by // terminating now. exit; }
protected function execute(InputInterface $input, OutputInterface $output) { if (PHP_VERSION_ID < 50600) { $message = 'Self updating is not available in PHP versions under 5.6.' . "\n"; $message .= 'The latest version can be found at ' . self::PHAR_URL; $output->writeln(sprintf('<error>%s</error>', $message)); return 1; } elseif (Application::VERSION === '@' . 'package_version' . '@') { $output->writeln('<error>Self updating has been disabled in source version.</error>'); return 1; } $exitCode = 0; $updater = new Updater(); $updater->getStrategy()->setPharUrl(self::PHAR_URL); $updater->getStrategy()->setVersionUrl(self::PHAR_VERSION_URL); try { if ($input->getOption('rollback')) { $result = $updater->rollback(); } else { $result = $updater->update(); } if ($result) { $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $output->writeln(sprintf('Updated from %s to %s', $old, $new)); } else { $exitCode = 1; } } catch (Exception $e) { $exitCode = 1; $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); } return $exitCode; }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('puli/cli'); $updateStrategy->setStability($this->getStability($args)); $updateStrategy->setPharName('puli.phar'); $updateStrategy->setCurrentLocalVersion(PuliApplicationConfig::VERSION); $updater = new Updater(); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); } else { $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); } return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $updater = new Updater(); $updater->rollback(); $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $output->writeln(sprintf('Rolled back from %s to %s', $old, $new)); }
/** * Handles the "self-update" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('puli/cli'); $updateStrategy->setStability($this->getStability($args)); $updateStrategy->setPharName('puli.phar'); $updateStrategy->setCurrentLocalVersion(PuliApplicationConfig::VERSION); // false: disable signed releases, otherwise the updater will look for // a *.pubkey file for the PHAR $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $io->writeLine(sprintf('Updated from version %s to version %s.', $updater->getOldVersion(), $updater->getNewVersion())); return 0; } $io->writeLine(sprintf('Version %s is the latest version. No update required.', $updater->getOldVersion())); return 0; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { try { $result = $this->updater->update(); if (!$result) { $output->writeln('No update needed.'); return 0; } $new = $this->updater->getNewVersion(); $old = $this->updater->getOldVersion(); $output->writeln(sprintf('Updated from SHA-1 %s to SHA-1 %s. Please run again', $old, $new)); return 0; } catch (\Exception $e) { $output->writeln("Unable to update. Please check your connection"); $this->printException($output, $e); return 1; } }
public function processCommand() { try { echo "\rChecks for updates..."; $result = $this->updater->update(); if ($result) { $new = $this->updater->getNewVersion(); $old = $this->updater->getOldVersion(); printf("\rUpdated from %s to %s.", $old, $new); exit(0); } printf("\rYou are already using last version (%s).", $this->version); exit(0); } catch (\Exception $e) { echo $e->getMessage(); exit(1); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $application = $this->getApplication(); $pharName = 'drupal.phar'; $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('drupal/console'); $updateStrategy->setStability(GithubStrategy::STABLE); $updateStrategy->setPharName($pharName); $updateStrategy->setCurrentLocalVersion($application::VERSION); $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $output->success(sprintf($this->trans('commands.self-update.messages.success'), $updater->getOldVersion(), $pharName)); } else { $output->warning(sprintf($this->trans('commands.self-update.messages.current-version'), $updater->getOldVersion())); } $this->getApplication()->setDispatcher(null); }
/** * Execute the self-update command * * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $updater = new Updater(null, false); $updater->setStrategy(Updater::STRATEGY_GITHUB); $updater->getStrategy()->setPackageName('studioforty9/modrepo'); $updater->getStrategy()->setPharName('modrepo.phar'); $updater->getStrategy()->setCurrentLocalVersion($this->getApplication()->getVersion()); $updater->getStrategy()->setStability('stable'); try { $result = $updater->update(); if ($result) { $output->writeln('<fg=green>Modrepo has been updated.</fg=green>'); $output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $updater->getNewVersion())); $output->writeln(sprintf('<fg=green>Previous version was:</fg=green> <options=bold>%s</options=bold>.', $updater->getOldVersion())); } else { $output->writeln('<fg=green>Modrepo is currently up to date.</fg=green>'); $output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $updater->getOldVersion())); } } catch (\Exception $e) { $output->writeln(sprintf('Error: <fg=yellow>%s</fg=yellow>', $e->getMessage())); } $output->write(PHP_EOL); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $updateStrategy = new GithubStrategy(); $updateStrategy->setPackageName('drupal/console'); $updateStrategy->setStability(GithubStrategy::STABLE); $updateStrategy->setPharName('console.phar'); $updateStrategy->setCurrentLocalVersion(Application::VERSION); $updater = new Updater(null, false); $updater->setStrategyObject($updateStrategy); if ($updater->update()) { $output->writeln(sprintf($this->trans('commands.self-update.messages.success'), $updater->getOldVersion(), $updater->getNewVersion())); } else { $output->writeln(sprintf($this->trans('commands.self-update.messages.current-version'), $updater->getOldVersion())); } // Recommended by Commerce Guys CLI // https://github.com/platformsh/platformsh-cli/blob/7a122d3f3226d5e6ed0a0b74803158c51b31ad5e/src/Command/Self/SelfUpdateCommand.php#L72-L77 // Errors appear if new classes are instantiated after this stage // (namely, Symfony's ConsoleTerminateEvent). This suggests PHP // can't read files properly from the overwritten Phar, or perhaps it's // because the autoloader's name has changed. We avoid the problem by // terminating now. exit; }
protected function execute(InputInterface $input, OutputInterface $output) { $updater = new Updater(); $updater->getStrategy()->setPharUrl('https://gilbitron.github.io/Handle/handle.phar'); $updater->getStrategy()->setVersionUrl('https://gilbitron.github.io/Handle/handle.phar.version'); try { $result = $updater->update(); if (!$result) { $output->writeln('<info>No update available</info>'); return; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $output->writeln(sprintf('<info>Updated from %s to %s</info>', $old, $new)); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return void * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $updater = new Updater(); $strategy = $updater->getStrategy(); if ($strategy instanceof ShaStrategy) { $strategy->setPharUrl('http://lucascherifi.github.io/gitaski/gitaski.phar'); $strategy->setVersionUrl('http://lucascherifi.github.io/gitaski/gitaski.phar.version'); } $result = $updater->update(); if (!$result) { $io = new SymfonyStyle($input, $output); $io->success('No update needed.'); return; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $io->success(sprintf('Updated from %s to %s', $old, $new)); return; }
/** * executes the command * * @return int */ protected function handle() { $updater = new Updater(null, false); /** @var \Humbug\SelfUpdate\Strategy\ShaStrategy $strategy */ $strategy = $updater->getStrategy(); $strategy->setPharUrl(self::UPDATE_PHAR_URL); $strategy->setVersionUrl(self::UPDATE_VERSION_URL); try { $result = $updater->update(); if (!$result) { // No update needed! return 0; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $this->info(sprintf('Updated from %s to %s', $old, $new)); return 0; } catch (\Exception $e) { // Report an error! $this->error($e->getMessage()); return 1; } }
function exec() { try { $updater = new Updater(); //$updater->setStrategy(Updater::STRATEGY_GITHUB); //use packagist.org //$updater->getStrategy()->setStability('any'); //$updater->getStrategy()->setPackageName('redcatphp/artist'); //$updater->getStrategy()->setPharName('artist.phar'); //$updater->getStrategy()->setCurrentLocalVersion('@package_version@'); $updater->getStrategy()->setPharUrl('https://raw.githubusercontent.com/redcatphp/artist/master/artist.phar'); $updater->getStrategy()->setVersionUrl('https://raw.githubusercontent.com/redcatphp/artist/master/artist.version'); $result = $updater->update(); if (!$result) { $this->output->writeln('allready up to date'); return; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); printf('Updated from %s to %s', $old, $new); } catch (FilesystemException $e) { echo "you must run this command as sudo (root)\n"; throw $e; } }
/** * @param Route $route * @param Console $console * @return int */ public function __invoke(Route $route, Console $console) { if (version_compare(\PHP_VERSION, '5.6', 'lt')) { $console->writeLine(sprintf('self-update requires PHP >=5.6 (version %s was used); aborting', \PHP_VERSION), Color::RED); exit(1); } $updater = new Updater(); $updater->getStrategy()->setPharUrl(self::URL_PHAR); $updater->getStrategy()->setVersionUrl(self::URL_VERSION); try { $result = $updater->update(); if (!$result) { $console->writeLine('No updated needed!', Color::GREEN); return 0; } $new = $updater->getNewVersion(); $old = $updater->getOldVersion(); $console->writeLine(sprintf('Updated from %s to %s', $old, $new), Color::GREEN); return 0; } catch (Exception $e) { $console->writeLine('[ERROR] Could not update', Color::RED); return 1; } }
protected function update(Updater $updater) { $this->output->writeln('Updating...' . PHP_EOL); try { $result = $updater->update(); $newVersion = $updater->getNewVersion(); $oldVersion = $updater->getOldVersion(); if (strlen($newVersion) == 40) { $newVersion = 'dev-' . $newVersion; } if (strlen($oldVersion) == 40) { $oldVersion = 'dev-' . $oldVersion; } if ($result) { $this->output->writeln('<fg=green>Humbug has been updated.</fg=green>'); $this->output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $newVersion)); $this->output->writeln(sprintf('<fg=green>Previous version was:</fg=green> <options=bold>%s</options=bold>.', $oldVersion)); } else { $this->output->writeln('<fg=green>Humbug is currently up to date.</fg=green>'); $this->output->writeln(sprintf('<fg=green>Current version is:</fg=green> <options=bold>%s</options=bold>.', $oldVersion)); } } catch (\Exception $e) { $this->output->writeln(sprintf('Error: <fg=yellow>%s</fg=yellow>', $e->getMessage())); } $this->output->write(PHP_EOL); $this->output->writeln('You can also select update stability using --dev, --pre (alpha/beta/rc) or --stable.'); }
protected function update(Updater $updater) { $this->io->title("Updating Spaceport"); try { $result = $updater->update(); $newVersion = $updater->getNewVersion(); $oldVersion = $updater->getOldVersion(); if (strlen($newVersion) == 40) { $newVersion = 'dev-' . $newVersion; } if (strlen($oldVersion) == 40) { $oldVersion = 'dev-' . $oldVersion; } if ($result) { $this->io->success("Spaceport has been updated from {$oldVersion} to {$newVersion}"); } else { $this->io->success("Spaceport is currently up to date at {$oldVersion}"); } } catch (\Exception $e) { $this->io->error("Error: " . $e->getMessage()); } $this->io->note('You can also select update stability using --dev, --pre (alpha/beta/rc) or --stable.'); }
protected function update(Updater $updater) { $this->dialogProvider->logCommand("Updating Skylab"); try { $result = $updater->update(); $newVersion = $updater->getNewVersion(); $oldVersion = $updater->getOldVersion(); if (strlen($newVersion) == 40) { $newVersion = 'dev-' . $newVersion; } if (strlen($oldVersion) == 40) { $oldVersion = 'dev-' . $oldVersion; } if ($result) { $this->dialogProvider->logTask("Skylab has been updated from {$oldVersion} to {$newVersion}"); } else { $this->dialogProvider->logTask("Skylab is currently up to date at {$oldVersion}"); } } catch (\Exception $e) { $this->dialogProvider->logError("Error: " . $e->getMessage()); } $this->dialogProvider->logNotice('You can also select update stability using --dev, --pre (alpha/beta/rc) or --stable.'); }
private function selfUpdate() { $phar = \Phar::running(false); if ($phar === '') { $this->stdio->errln('<<red>>Self-updating only works when running the PHAR version of phormat.<<reset>>'); exit(Status::UNAVAILABLE); } $updater = new Updater($phar, false); $strategy = new GithubStrategy(); $strategy->setPackageName('nochso/phormat'); $strategy->setPharName('phormat.phar'); $strategy->setCurrentLocalVersion($this->version->getVersion()); $updater->setStrategyObject($strategy); try { if ($updater->update()) { $this->stdio->success(sprintf('Successfully updated phormat from <<yellow>>%s<<reset>> to <<yellow>>%s<<reset>>.', $updater->getOldVersion(), $updater->getNewVersion())); exit(Status::SUCCESS); } $this->stdio->neutral('There is no update available.'); exit(Status::SUCCESS); } catch (\Exception $e) { $this->stdio->error(sprintf("Self-update failed:\n%s<<reset>>", $e->getMessage())); } }