/**
  * {@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;
 }
Exemple #2
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;
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * @runInSeparateProcess
  */
 public function testUpdatePhar()
 {
     if (!extension_loaded('openssl')) {
         $this->markTestSkipped('This test requires the openssl extension to run.');
     }
     $this->createTestPharAndKey();
     $this->assertEquals('old', $this->getPharOutput($this->tmp . '/old.phar'));
     $updater = new Updater($this->tmp . '/old.phar');
     $updater->setStrategyObject(new GithubTestStrategy());
     $updater->getStrategy()->setPharName('new.phar');
     $updater->getStrategy()->setPackageName('');
     // not used in this test
     $updater->getStrategy()->setCurrentLocalVersion('1.0.0');
     $this->assertTrue($updater->update());
     $this->assertEquals('new', $this->getPharOutput($this->tmp . '/old.phar'));
 }
 /**
  * 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;
 }
 /**
  * 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');
         }
     }
 }
 /**
  * {@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);
 }
 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;
 }
 /**
  * {@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;
 }
Exemple #11
0
 public function selfUpdate()
 {
     if (!extension_loaded('Phar') || !\Phar::running(false)) {
         $this->yell('Can only update Phar version. Update via a vcs');
         return;
     }
     $updater = new Updater(null, false);
     $updater->setStrategyObject(new BitBucketStrategy($updater));
     //Yep, that sucks
     $updater->getStrategy()->setPackageName('twhiston/tg');
     $updater->getStrategy()->setPharName('tg.phar');
     $updater->getStrategy()->setCurrentLocalVersion(TgApp::VERSION);
     try {
         $this->yell('Updating', 100, 'green');
         $result = $updater->update();
         if (!$result) {
             $this->yell('You have the most recent version', 100, 'yellow');
         }
     } catch (\Exception $e) {
         $this->yell('Error updating: ' . $e->getMessage(), 100, 'red');
     }
 }
Exemple #12
0
 /**
  * Custom Strategies
  */
 public function testCanSetCustomStrategyObjects()
 {
     $this->updater->setStrategyObject(new FooStrategy());
     $this->assertTrue($this->updater->getStrategy() instanceof FooStrategy);
 }
Exemple #13
0
 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()));
     }
 }
 /**
  * Run the update.
  *
  * @param string|null $manifestUrl
  * @param string|null $currentVersion
  *
  * @return false|string
  *   The new version number, or false if there was no update.
  */
 public function update($manifestUrl = null, $currentVersion = null)
 {
     $currentVersion = $currentVersion ?: $this->config->get('application.version');
     $manifestUrl = $manifestUrl ?: $this->config->get('application.manifest_url');
     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 (defined('CLI_ROOT') && 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 " . $this->config->get('application.package_name'));
             $this->stdErr->writeln("  curl -sS " . $this->config->get('application.installer_url') . " | php\n");
         }
         return false;
     }
     $this->stdErr->writeln(sprintf('Checking for updates (current version: <info>%s</info>)', $currentVersion));
     $updater = new Updater(null, false);
     $strategy = new ManifestStrategy($currentVersion, $manifestUrl, $this->allowMajor, $this->allowUnstable);
     $strategy->setManifestTimeout($this->timeout);
     $updater->setStrategyObject($strategy);
     if (!$updater->hasUpdate()) {
         $this->stdErr->writeln('No updates found');
         return false;
     }
     $newVersionString = $updater->getNewVersion();
     if ($notes = $strategy->getUpdateNotes($updater)) {
         $this->stdErr->writeln('');
         $this->stdErr->writeln(sprintf('Version <info>%s</info> is available. Update notes:', $newVersionString));
         $this->stdErr->writeln(preg_replace('/^/m', '  ', $notes));
         $this->stdErr->writeln('');
     }
     if (!$this->questionHelper->confirm(sprintf('Update to version %s?', $newVersionString))) {
         return false;
     }
     $this->stdErr->writeln(sprintf('Updating to version %s', $newVersionString));
     $updater->update();
     $this->stdErr->writeln("Successfully updated to version <info>{$newVersionString}</info>");
     return $newVersionString;
 }