Platformsh\Cli\Command\CommandBase::checkUpdates PHP Метод

checkUpdates() защищенный Метод

Check for updates.
protected checkUpdates ( boolean $reset = false )
$reset boolean
    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('');
    }