Exemplo n.º 1
0
 /**
  * Updates the running Phar if any is available.
  *
  * @param string|Version $version  The current version.
  * @param boolean        $major    Lock to current major version?
  * @param boolean        $pre      Allow pre-releases?
  *
  * @return boolean TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false)
 {
     if (false === $version instanceof Version) {
         $version = Version::create($version);
     }
     if (null !== ($update = $this->manifest->findRecent($version, $major, $pre))) {
         $update->getFile();
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifest = $input->getOption('manifest') ?: 'https://platform.sh/cli/manifest.json';
     $currentVersion = $input->getOption('current-version') ?: $this->getApplication()->getVersion();
     if (extension_loaded('Phar') && !($localPhar = \Phar::running(false))) {
         $this->stdErr->writeln('This instance of the CLI was not installed as a Phar archive.');
         if (file_exists(CLI_ROOT . '/../../autoload.php')) {
             $this->stdErr->writeln('Update using: <info>composer global update</info>');
         }
         return 1;
     }
     $manager = new Manager(Manifest::loadFile($manifest));
     if (isset($localPhar)) {
         $manager->setRunningFile($localPhar);
     }
     $onlyMinor = !$input->getOption('major');
     $updated = $manager->update($currentVersion, $onlyMinor);
     if ($updated) {
         $this->stdErr->writeln("Successfully updated");
         $localPhar = $manager->getRunningFile();
         passthru('php ' . escapeshellarg($localPhar) . ' --version');
     } else {
         $this->stdErr->writeln("No updates found. The Platform.sh CLI is up-to-date.");
     }
     return 0;
 }
Exemplo n.º 3
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance.
  * @param OutputInterface $output An OutputInterface instance.
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $application = $this->getApplication();
     $manifest = Manifest::loadFile(self::MANIFEST_FILE);
     $manager = new Manager($manifest);
     $manager->update($application->getVersion(), true);
     return 0;
 }
 /**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return int|null|void
  *
  * @throws Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ('phar://' !== substr(__DIR__, 0, 7)) {
         $output->writeln('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     $manager->update($this->getApplication()->getVersion(), true);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new Manager(Manifest::loadFile(self::DRUPAL_CONSOLE_MANIFEST));
     if ($manager->update($this->getApplication()->getVersion(), true)) {
         $output->writeln($this->trans('commands.self-update.messages.success'));
     } else {
         $output->writeln(sprintf($this->trans('commands.self-update.messages.current-version'), $this->getApplication()->getVersion()));
     }
 }
Exemplo n.º 6
0
 /**
  * Returns manager instance or exit with status code 1 on failure.
  *
  * @param OutputInterface $output
  *
  * @return \Herrera\Phar\Update\Manager
  */
 private function createManager(OutputInterface $output)
 {
     try {
         return new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     } catch (FileException $e) {
         $output->writeln('<error>Unable to search for updates.</error>');
         exit(1);
     }
 }
Exemplo n.º 7
0
 /**
  * @param \Peanut\Console\Application $app
  */
 public function execute(\Peanut\Console\Application $app)
 {
     $manager = new Manager($manifest = Manifest::loadFile('https://raw.githubusercontent.com/yejune/bootapp/master/manifest.json'));
     $result = $manager->update($app->getApplicationVersion(), true, true);
     if ($result) {
         $this->message('Update successful!');
     } else {
         $this->message('Already up-to-date.');
     }
 }
Exemplo n.º 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Update is currently broken, debug info follows');
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     $output->writeln('Looking for updates...');
     $currentVersion = $this->getApplication()->getVersion();
     if ($manager->update($currentVersion, true)) {
         $output->writeln('<info>Updated to latest version</info>');
     } else {
         $output->writeln('<comment>Already up-to-date.</comment>');
     }
 }
Exemplo n.º 9
0
 public function testLoadFile()
 {
     file_put_contents($file = $this->createFile(), json_encode(array(array('name' => 'test.phar', 'sha1' => 'abcdefabcdefabcdefabcdefabcdefabcdefabcd', 'url' => 'http://example.com/test-1.2.3.phar', 'version' => '1.2.3'), array('name' => 'test.phar', 'sha1' => '0123456789012345678901234567890123456789', 'url' => 'http://example.com/test-4.5.6.phar', 'version' => '4.5.6'))));
     try {
         $updates = Manifest::loadFile($file)->getUpdates();
     } catch (JsonException $exception) {
         print_r($exception->getErrors());
         throw $exception;
     }
     $this->assertEquals('abcdefabcdefabcdefabcdefabcdefabcdefabcd', $updates[0]->getSha1());
     $this->assertEquals('0123456789012345678901234567890123456789', $updates[1]->getSha1());
 }
Exemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!Application::isInstalledAsPhar()) {
         $output->writeln('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     $manager = new Manager(Manifest::loadFile(Application::MANIFEST_FILE));
     if ($manager->update($this->getApplication()->getVersion(), true)) {
         $output->writeln(sprintf('<info>Application was successfully updated</info>'));
     } else {
         $output->writeln(sprintf('<error>Updating failed or you already have latest version</error>'));
     }
 }
Exemplo n.º 11
0
 /**
  * Execute the command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     if ($manager->update($this->getApplication()->getVersion(), true)) {
         $output->writeln('');
         $output->writeln($this->messages->translator->trans('update.command.was.updated'));
         $output->writeln('');
     } else {
         $output->writeln('');
         $output->writeln($this->messages->translator->trans('update.command.already.updated', ['version' => $this->getApplication()->getVersion()]));
         $output->writeln('');
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifest = Manifest::loadFile(self::MANIFEST_FILE);
     $currentVersion = Parser::toVersion($this->getApplication()->getVersion());
     $update = $manifest->findRecent($currentVersion, true);
     if (false === $update instanceof Update) {
         $output->writeln(sprintf('You are already using the latest version: <info>%s</info>', $currentVersion));
         return 0;
     }
     $output->writeln(sprintf('Updating to version <info>%s</info>', $update->getVersion()));
     $manager = new Manager($manifest);
     $manager->update($this->getApplication()->getVersion(), true);
     $output->writeln(sprintf('SHA1 verified <info>%s</info>', $update->getSha1()));
 }
Exemplo n.º 13
0
 /**
  * Perform a self-update on the phar file
  *
  * @param Route $route
  * @param Console $console
  * @return int
  */
 public function __invoke(Route $route, Console $console)
 {
     $manifest = UpdateManifest::loadFile(self::MANIFEST_FILE);
     $manager = new UpdateManager($manifest);
     if (!$manager->update($this->version, true, true)) {
         $console->writeLine('No updates available.', Color::YELLOW);
         return 0;
     }
     $version = new Version($this->version);
     $update = $manifest->findRecent($version);
     $console->write('Updated to version ');
     $console->writeLine($update->getVersion(), Color::GREEN);
     return 0;
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $currentVersion = $this->getApplication()->getVersion();
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     $lockMajor = false;
     $allowPreRelease = false;
     if (substr($currentVersion, 0, 1) == 0) {
         $allowPreRelease = true;
     }
     if ($manager->update($currentVersion, $lockMajor, $allowPreRelease)) {
         $newVersion = $this->getNewVersion($currentVersion, $manager, $lockMajor, $allowPreRelease);
         $this->output->writeln(sprintf('<info>Updated Slack CLI from <fg=yellow>%s</fg=yellow> to <fg=yellow>%s</fg=yellow></info>', $currentVersion, $newVersion));
     } else {
         $this->output->writeln(sprintf('<comment>You are already using the latest version (%s)</comment>', $currentVersion));
     }
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Looking for updates...');
     try {
         $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     } catch (FileException $e) {
         return $output->writeln('<error>Unable to search for updates</error>');
     }
     $currentVersion = trim($this->getApplication()->getVersion(), 'v');
     $allowMajor = $input->getOption('major');
     if ($manager->update($currentVersion, $allowMajor)) {
         $output->writeln('<info>Updated to latest version</info>');
     } else {
         $output->writeln('<comment>Already up-to-date</comment>');
     }
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $manifest = Manifest::loadFile(self::MANIFEST_FILE);
         $manager = new Manager($manifest);
     } catch (FileException $e) {
         $output->writeln('<error>Unable to search for updates</error>');
         return 1;
     }
     $currentVersion = $this->getApplication()->getVersion();
     if ($manager->update($currentVersion, true)) {
         $output->writeln('<info>Updated to latest version</info>');
     } else {
         $output->writeln('<comment>Already up-to-date</comment>');
     }
 }
Exemplo n.º 17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Looking for updates...');
     try {
         $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     } catch (FileException $e) {
         if ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) {
             $output->writeln('<error>' . $e->getMessage() . '</error>');
         }
         $output->writeln('<error>Unable to search for updates</error>');
         return 1;
     }
     if ($manager->update($this->getApplication()->getVersion(), true)) {
         $output->writeln('<info>Updated to latest version</info>');
     } else {
         $output->writeln('<comment>Already up-to-date</comment>');
     }
     return 0;
 }
Exemplo n.º 18
0
 public function execute($options, $arguments, $app)
 {
     $manifest = Config::get('manifest');
     if ($manifest === false) {
         $this->writeln('Manifest URL not defined');
         return 1;
     }
     $this->writeln('Checking for updates ...');
     try {
         $manager = new UpdateManager(Manifest::loadFile($manifest));
         if (Config::get('pubkeyhash') !== false) {
             $manager->setPublicKeyHash(Config::get('pubkeyhash'));
         }
     } catch (FileException $e) {
         $this->writeln('Unable to search for updates');
         return 1;
     }
     if ($manager->update($app->version, true)) {
         $this->writeln('Updated to latest version');
     } else {
         $this->writeln('Already up-to-date');
     }
     return 0;
 }
Exemplo n.º 19
0
 /**
  * Returns the update manager.
  *
  * @param string $uri The manifest file URI.
  *
  * @return Manager The update manager.
  */
 public function getManager($uri)
 {
     return new Manager(Manifest::loadFile($uri));
 }
Exemplo n.º 20
0
 /**
  * @return Manager
  */
 private function createUpdateManager()
 {
     return new Manager(Manifest::loadFile(self::MANIFEST_URL));
 }
Exemplo n.º 21
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     $manager->update($this->getApplication()->getVersion());
 }
Exemplo n.º 22
0
 public function update()
 {
     $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE));
     if ($manager->update($this->getApplication()->getVersion(), true)) {
         $this->out('Updated to latest version!', 'success');
     } else {
         $this->out('mysqldumper up-to-date', 'warning');
     }
 }