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;
     }
 }
예제 #3
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!');
     }
 }
예제 #4
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)
 {
     $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;
 }
예제 #6
0
 protected function printVersion(Updater $updater)
 {
     $stability = 'stable';
     if ($updater->getStrategy() instanceof ShaStrategy) {
         $stability = 'development';
     } elseif ($updater->getStrategy() instanceof GithubStrategy && $updater->getStrategy()->getStability() == GithubStrategy::UNSTABLE) {
         $stability = 'pre-release';
     }
     try {
         if ($updater->hasUpdate()) {
             $this->output->writeln(sprintf('The current %s build available remotely is: <options=bold>%s</options=bold>', $stability, $updater->getNewVersion()));
         } elseif (false == $updater->getNewVersion()) {
             $this->output->writeln(sprintf('There are no %s builds available.', $stability));
         } else {
             $this->output->writeln(sprintf('You have the current %s build installed.', $stability));
         }
     } catch (\Exception $e) {
         $this->output->writeln(sprintf('Error: <fg=yellow>%s</fg=yellow>', $e->getMessage()));
     }
 }
예제 #7
0
 protected function printVersion(Updater $updater)
 {
     $stability = 'stable';
     $strategyInterface = $updater->getStrategy();
     if ($strategyInterface instanceof ShaStrategy) {
         $stability = 'development';
     } elseif ($strategyInterface instanceof GithubStrategy && $strategyInterface->getStability() == GithubStrategy::UNSTABLE) {
         $stability = 'pre-release';
     }
     try {
         if ($updater->hasUpdate()) {
             $this->io->text("The current {$stability} build available remotely is: " . $updater->getNewVersion());
         } elseif (false == $updater->getNewVersion()) {
             $this->io->text("There are no {$stability} builds available.");
         } else {
             $this->io->text("You have the current {$stability} build installed.");
         }
     } catch (\Exception $e) {
         $this->io->error("Error: " . $e->getMessage());
     }
 }
예제 #8
0
 private function printAvailableVersion(Updater $updater, OutputInterface $output)
 {
     $strategy = $updater->getStrategy();
     if (!$strategy instanceof GithubStrategy) {
         throw new \UnexpectedValueException('Unexpected strategy type');
     }
     /* @var $strategy GithubStrategy */
     $stability = $strategy->getStability() === GithubStrategy::STABLE ? 'stable' : 'pre-release';
     try {
         if ($updater->hasUpdate()) {
             $output->writeln(sprintf('The current %s build available is: <options=bold>%s</options=bold>', $stability, $updater->getNewVersion()));
         } elseif ($updater->getNewVersion() === false) {
             $output->writeln(sprintf('There are no %s builds available.', $stability));
         } else {
             $output->writeln(sprintf('You have the current %s build installed.', $stability));
         }
     } catch (\Exception $ex) {
         $output->writeln(sprintf('Error: <error>%s</error>', $ex->getMessage()));
     }
 }
예제 #9
0
 public function testThrowsExceptionOnInvalidRemoteVersion()
 {
     $this->setExpectedException('Humbug\\SelfUpdate\\Exception\\HttpRequestException', 'Version request returned incorrectly formatted response');
     $this->updater->getStrategy()->setVersionUrl('file://' . $this->files . '/bad.version');
     $this->assertTrue($this->updater->hasUpdate());
 }
예제 #10
0
 /**
  * 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;
 }