/**
  * Download the remote Phar file.
  *
  * @param Updater $updater Updater.
  *
  * @return void
  * @throws \LogicException When there is nothing to download.
  */
 public function download(Updater $updater)
 {
     if (!$this->remoteUrl) {
         throw new \LogicException('Run "hasUpdate()" on updater prior to downloading new version.');
     }
     file_put_contents($updater->getTempPharFile(), $this->downloadFile($this->remoteUrl));
 }
Example #2
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));
 }
 /**
  * @return Updater
  */
 private function createUpdater()
 {
     $config = $this->container->get('config');
     $pharUrl = $config['update']['pharUrl'];
     $versionUrl = $config['update']['vesionUrl'];
     $verifyKey = (bool) $config['update']['verifyPublicKey'];
     $updater = new Updater(null, $verifyKey);
     $updater->getStrategy()->setPharUrl($pharUrl);
     $updater->getStrategy()->setVersionUrl($versionUrl);
     return $updater;
 }
Example #4
0
 /**
  * Download the remote Phar file.
  *
  * @param Updater $updater
  * @return void
  */
 public function download(Updater $updater)
 {
     /** Switch remote request errors to HttpRequestExceptions */
     set_error_handler(array($updater, 'throwHttpRequestException'));
     $result = humbug_get_contents($this->remoteUrl);
     restore_error_handler();
     if (false === $result) {
         throw new HttpRequestException(sprintf('Request to URL failed: %s', $this->remoteUrl));
     }
     file_put_contents($updater->getTempPharFile(), $result);
 }
Example #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $updater = new Updater(null, false);
     $updater->setStrategyObject(new Update($this->getApplication()->getVersion(), true, 'http://fabioneves.github.io/backup-cli/manifest.json'));
     try {
         $result = $updater->update();
         $message = $result ? '<info>Updated successfully!</info>' : 'You already have the latest version.';
         $output->writeln($message);
     } catch (\Exception $e) {
         $output->writeln("<error>{$e->getMessage()}</error>");
         return;
     }
 }
Example #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $result = $this->updater->update();
         if ($result) {
             $output->writeln('<info>Victor is sucessfully updated.</info>');
         } else {
             $output->writeln('<info>You are using latest version of Victor no updates needed.</info>');
         }
     } catch (\Exception $e) {
         $output->writeln('<error>Ther is error when update is in progress. Please try it again later.</error>');
         return 255;
     }
 }
Example #7
0
 /**
  * Execute
  *
  * @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);
     $strategy = $updater->getStrategy();
     /* @var GithubStrategy $strategy */
     $strategy->setPackageName('TYPO3/Surf');
     $strategy->setPharName('surf.phar');
     $strategy->setCurrentLocalVersion($this->getApplication()->getVersion());
     $stability = $input->getOption('stability');
     if (empty($stability)) {
         // Unstable by default. Should be removed once we have a 2.0.0 final
         $stability = GithubStrategy::UNSTABLE;
     }
     $strategy->setStability($stability);
     if ($input->getOption('check')) {
         $result = $updater->hasUpdate();
         if ($result) {
             $output->writeln(sprintf('The %s build available remotely is: %s', $strategy->getStability() === GithubStrategy::ANY ? 'latest' : 'current ' . $strategy->getStability(), $updater->getNewVersion()));
         } elseif (false === $updater->getNewVersion()) {
             $output->writeln('There are no new builds available.');
         } else {
             $output->writeln(sprintf('You have the current %s build installed.', $strategy->getStability()));
         }
     } elseif ($input->getOption('rollback')) {
         $result = $updater->rollback();
         $result ? $output->writeln('Success!') : $output->writeln('Failure!');
     } else {
         $result = $updater->update();
         $result ? $output->writeln('Updated.') : $output->writeln('No update needed!');
     }
 }
Example #8
0
 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->rollback();
         if (!$result) {
             $output->writeln('<error>There was an error rolling back the update</error>');
             return;
         }
         $output->writeln('<info>Rollback successful</info>');
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new ConsoleLogger($output);
     $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
     /** @var GithubStrategy $strategy */
     $strategy = $updater->getStrategy();
     $strategy->setPackageName('icehawk/component-template-generator');
     $strategy->setPharName('icehawk-ctg.phar');
     $strategy->setCurrentLocalVersion('@package_version@');
     if ($updater->rollback()) {
         $logger->info('Roll back successful!');
     } else {
         $logger->alert('Roll back failed.');
     }
     return 0;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $result = $this->updater->rollback();
         if (!$result) {
             $output->writeln("Rollback failed!");
             return 1;
         }
     } catch (\Exception $e) {
         $output->writeln($e->getMessage());
         $output->writeln("Unable to rollback");
         return 1;
     }
     $output->writeln("Rollback successful");
     return 0;
 }
Example #11
0
 /**
  * executes the command
  *
  * @return int
  */
 protected function handle()
 {
     $updater = new Updater(null, false);
     try {
         $result = $updater->rollback();
         if (!$result) {
             $this->error('Rollback failed!');
             // report failure!
             return 1;
         }
         return 0;
     } catch (\Exception $e) {
         $this->error($e->getMessage());
         // Report an error!
         return 1;
     }
 }
 /**
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $console->writeLine('Rolling back to a previous installed version...', Color::GREEN);
     $updater = new Updater();
     try {
         $result = $updater->rollback();
         if (!$result) {
             $console->writeLine('Rollback failed!', Color::RED);
             return 1;
         }
     } catch (Exception $e) {
         $console->writeLine('[ERROR] Could not rollback', Color::RED);
         return 1;
     }
     $console->writeLine('Rollback complete!', Color::GREEN);
     return 0;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $input->validate();
     $logger = new ConsoleLogger($output);
     $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
     /** @var GithubStrategy $strategy */
     $strategy = $updater->getStrategy();
     $strategy->setPackageName(PharTool::PACKAGE_NAME);
     $strategy->setPharName(PharTool::PHAR_NAME);
     $strategy->setCurrentLocalVersion('@package_version@');
     if ($updater->rollback()) {
         $logger->info('Roll back successful!');
     } else {
         $logger->alert('Roll back failed.');
     }
     return 0;
 }
 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;
 }
Example #15
0
 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)
 {
     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;
     }
 }
 /**
  * {@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);
 }
 /**
  * @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;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifestUrl = $input->getOption('manifest') ?: 'https://platform.sh/cli/manifest.json';
     $currentVersion = $input->getOption('current-version') ?: $this->getApplication()->getVersion();
     $allowMajor = $input->getOption('major');
     $allowUnstable = $input->getOption('unstable');
     if (!extension_loaded('Phar') || !($localPhar = \Phar::running(false))) {
         $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.');
         // Instructions for users who are running a global Composer install.
         if (file_exists(CLI_ROOT . '/../../autoload.php')) {
             $this->stdErr->writeln("Update using:\n\n  composer global update");
             $this->stdErr->writeln("\nOr you can switch to a Phar install (<options=bold>recommended</>):\n");
             $this->stdErr->writeln("  composer global remove platformsh/cli");
             $this->stdErr->writeln("  curl -sS https://platform.sh/cli/installer | php\n");
         }
         return 1;
     }
     $this->stdErr->writeln(sprintf('Checking for updates (current version: <info>%s</info>)', $currentVersion));
     $updater = new Updater(null, false);
     $strategy = new ManifestStrategy($currentVersion, $manifestUrl, $allowMajor, $allowUnstable);
     $updater->setStrategyObject($strategy);
     if (!$updater->hasUpdate()) {
         $this->stdErr->writeln('No updates found');
         return 0;
     }
     $newVersionString = $updater->getNewVersion();
     /** @var \Platformsh\Cli\Helper\PlatformQuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     if (!$questionHelper->confirm(sprintf('Update to version %s?', $newVersionString), $input, $output)) {
         return 1;
     }
     $this->stdErr->writeln(sprintf('Updating to version %s', $newVersionString));
     $updater->update();
     $this->stdErr->writeln("Successfully updated to version <info>{$newVersionString}</info>");
     // 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;
 }
Example #20
0
 /**
  * {@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)
 {
     $logger = new ConsoleLogger($output);
     $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
     /** @var GithubStrategy $strategy */
     $strategy = $updater->getStrategy();
     $strategy->setPackageName('icehawk/component-template-generator');
     $strategy->setPharName('icehawk-ctg.phar');
     $strategy->setCurrentLocalVersion('@package_version@');
     $stability = $input->getOption('stability');
     $strategy->setStability($stability);
     if ($updater->hasUpdate()) {
         $newVersion = $updater->getNewVersion();
         $logger->info(sprintf('The current stable version available is: %s', $newVersion));
         $logger->info('Updating...');
         if ($updater->update()) {
             $logger->info(sprintf('Successful! You now have version %s installed', $newVersion));
         }
     } elseif (false === $updater->getNewVersion()) {
         $logger->alert('There is no stable version available.');
     } else {
         $logger->info('@package_version@ is the latest stable version.');
     }
     return 0;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new ConsoleLogger($output);
     $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
     /** @var GithubStrategy $strategy */
     $strategy = $updater->getStrategy();
     $strategy->setPackageName(PharTool::PACKAGE_NAME);
     $strategy->setPharName(PharTool::PHAR_NAME);
     $strategy->setCurrentLocalVersion('@package_version@');
     $stability = $input->getOption('stability');
     $strategy->setStability($stability);
     try {
         if ($updater->hasUpdate()) {
             $newVersion = $updater->getNewVersion();
             $logger->info(sprintf('The current stable version available is: %s', $newVersion));
             $logger->info('Updating...');
             if ($updater->update()) {
                 $logger->info(sprintf('Successful! You now have version %s installed', $newVersion));
             }
         } elseif (false === $updater->getNewVersion()) {
             $logger->alert('There is no stable version available.');
         } else {
             $logger->info('@package_version@ is the latest stable version.');
         }
         return 0;
     } catch (HttpRequestException $e) {
         $logger->alert('Error fetching current version from remote repository.');
         return 1;
     }
 }
Example #23
0
 /**
  * Configure updater to use unstable builds.
  *
  * @param Updater $updater
  */
 private function stable(Updater $updater)
 {
     $updater->setStrategy(Updater::STRATEGY_GITHUB);
     $updater->getStrategy()->setPackageName('nanbando/core');
     $updater->getStrategy()->setPharName('nanbando.phar');
     $updater->getStrategy()->setCurrentLocalVersion('@git_version@');
     $updater->getStrategy()->setStability(GithubStrategy::STABLE);
 }
Example #24
0
 /**
  * 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);
 }
Example #25
0
 /**
  * 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;
     }
 }
Example #26
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
     $updater->getStrategy()->setPackageName('friendsofphp/pickle');
     $updater->getStrategy()->setPharName(self::PHAR_NAME);
     $updater->getStrategy()->setCurrentLocalVersion($this->getApplication()->getVersion());
     if ($input->getOption('unstable')) {
         $updater->getStrategy()->setStability('unstable');
     }
     if ($updater->update() === false) {
         $output->writeln('<info>Already up-to-date.</info>');
     } else {
         $output->writeln('<info>' . $updater->getLocalPharFileBasename() . ' has been updated!</info>');
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $updater = new Updater();
     $updater->setStrategy(Updater::STRATEGY_GITHUB);
     $updater->getStrategy()->setPackageName('relamptk/git-deployer');
     $updater->getStrategy()->setPharName('git-deployer.phar');
     $updater->getStrategy()->setCurrentLocalVersion($this->getApplication()->getVersion());
     $result = $updater->update();
     if ($result) {
         $new = $updater->getNewVersion();
         $output->writeln('<info>Git-Deployer</info> updated to version ' . $new . '.');
     } else {
         $output->writeln('<info>Git-Deployer</info> is already on the latest version!');
     }
 }
Example #28
0
 /**
  * Execute Command.
  *
  * @param InputInterface  $consoleInput
  * @param OutputInterface $consoleOutput
  *
  * @return int|null|void
  */
 public function execute(InputInterface $consoleInput, OutputInterface $consoleOutput)
 {
     $updater = new Updater();
     $updater->setStrategy(Updater::STRATEGY_GITHUB);
     $updater->getStrategy()->setPackageName('kriskbx/wyn');
     $updater->getStrategy()->setPharName('wyn.phar');
     $updater->getStrategy()->setCurrentLocalVersion($GLOBALS['wynVersion']);
     try {
         $result = $updater->rollback();
         $result ? exit('Success!') : exit('Failure!');
     } catch (\Exception $e) {
         exit('Well, something happened! Either an oopsie or something involving hackers.');
     }
 }
 /**
  * Run the command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $updater = new Updater(null, false);
     $updater->setStrategyObject(new CurlGithubStrategy());
     $updater->getStrategy()->setPackageName('inetprocess/sugarcli');
     $updater->getStrategy()->setPharName('sugarcli.phar');
     $updater->getStrategy()->setCurrentLocalVersion($this->getApplication()->getVersion());
     if ($input->getOption('rollback')) {
         $updater->rollback();
     } else {
         $result = $updater->update();
         if ($result) {
             $output->writeln('Successfuly updated');
         } else {
             $output->writeln('Already up to date');
         }
     }
 }
 /**
  * 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;
 }