setAllowMajor() public method

Set the updater to allow major version updates.
public setAllowMajor ( boolean $allowMajor = true )
$allowMajor boolean
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifestUrl = $input->getOption('manifest') ?: self::$config->get('application.manifest_url');
     $currentVersion = $input->getOption('current-version') ?: self::$config->get('application.version');
     $cliUpdater = new SelfUpdater($input, $output, self::$config, $this->getHelper('question'));
     $cliUpdater->setAllowMajor(!$input->getOption('no-major'));
     $cliUpdater->setAllowUnstable((bool) $input->getOption('unstable'));
     $cliUpdater->setTimeout($input->getOption('timeout'));
     $result = $cliUpdater->update($manifestUrl, $currentVersion);
     if ($result === false) {
         return 1;
     }
     // Phar cannot load more classes after the update has occurred. So to
     // avoid errors from classes loaded after this (e.g.
     // ConsoleTerminateEvent), we exit directly now.
     exit(0);
 }
示例#2
0
 /**
  * Check for updates.
  *
  * @param bool $reset
  */
 protected function checkUpdates($reset = false)
 {
     if (!$reset && self::$checkedUpdates) {
         return;
     }
     self::$checkedUpdates = true;
     // Check that this instance of the CLI was installed as a Phar.
     if (!extension_loaded('Phar') || !\Phar::running(false)) {
         return;
     }
     $timestamp = time();
     if (!self::$config->get('updates.check')) {
         return;
     } elseif (!$reset && self::$config->get('updates.last_checked') > $timestamp - self::$config->get('updates.check_interval')) {
         return;
     }
     self::$config->writeUserConfig(['updates' => ['check' => true, 'last_checked' => $timestamp]]);
     // Ensure classes are auto-loaded if they may be needed after the
     // update.
     /** @var \Platformsh\Cli\Helper\ShellHelper $shellHelper */
     $shellHelper = $this->getHelper('shell');
     /** @var \Platformsh\Cli\Helper\QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $currentVersion = self::$config->get('application.version');
     $cliUpdater = new SelfUpdater($this->input, $this->output, self::$config, $questionHelper);
     $cliUpdater->setAllowMajor(true);
     $cliUpdater->setTimeout(10);
     try {
         $newVersion = $cliUpdater->update(null, $currentVersion);
     } catch (\RuntimeException $e) {
         if (strpos($e->getMessage(), 'Failed to download') !== false) {
             $this->stdErr->writeln('<error>' . $e->getMessage() . '</error>');
             $newVersion = false;
         } else {
             throw $e;
         }
     }
     // If the update was successful, and it's not a major version change,
     // then prompt the user to continue after updating.
     if ($newVersion !== false) {
         $exitCode = 0;
         list($currentMajorVersion, ) = explode('.', $currentVersion, 2);
         list($newMajorVersion, ) = explode('.', $newVersion, 2);
         if ($newMajorVersion === $currentMajorVersion && isset($GLOBALS['argv'])) {
             $originalCommand = implode(' ', array_map('escapeshellarg', $GLOBALS['argv']));
             $questionText = "\n" . 'Original command: <info>' . $originalCommand . '</info>' . "\n\n" . 'Continue?';
             if ($questionHelper->confirm($questionText)) {
                 $this->stdErr->writeln('');
                 $exitCode = $shellHelper->executeSimple($originalCommand);
             }
         }
         exit($exitCode);
     }
     $this->stdErr->writeln('');
 }