Example #1
0
 public function testGetGarbageFeed()
 {
     $responseMock = $this->getResponseMock('<!DOCTYPE html><html lang="en"> <head><meta charset="utf-8">');
     $this->httpClient->method('get')->willReturn($responseMock);
     $fetcher = new Fetcher($this->httpClient, $this->locator, $this->configReader);
     $feed = $fetcher->getFeed();
     $this->assertInstanceOf('Owncloud\\Updater\\Utils\\Feed', $feed);
     $this->assertFalse($feed->isValid());
 }
 /**
  * Get a Feed instance
  * @param bool $useCache
  * @return \Owncloud\Updater\Utils\Feed
  */
 protected function getFeed($useCache = true)
 {
     if ($useCache && !is_null($this->registry->get('feed'))) {
         return $this->registry->get('feed');
     }
     return $this->fetcher->getFeed();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $registry = $this->container['utils.registry'];
     $registry->set('feed', false);
     $fsHelper = $this->container['utils.filesystemhelper'];
     $downloadController = new DownloadController($this->fetcher, $registry, $fsHelper);
     try {
         $currentVersion = $this->configReader->getByPath('system.version');
         if (!strlen($currentVersion)) {
             throw new \UnexpectedValueException('Could not detect installed version.');
         }
         $this->getApplication()->getLogger()->info('ownCloud ' . $currentVersion . ' found');
         $output->writeln('Current version is ' . $currentVersion);
         $feedData = $downloadController->checkFeed();
         if (!$feedData['success']) {
             // Network errors, etc
             $output->writeln("Can't fetch feed.");
             $output->writeln($feedData['exception']->getMessage());
             $this->getApplication()->logException($feedData['exception']);
             // Return a number to stop the queue
             return $input->getOption('exit-if-none') ? 4 : null;
         }
         $feed = $feedData['data']['feed'];
         if (!$feed->isValid()) {
             // Feed is empty. Means there are no updates
             $output->writeln('No updates found online.');
             return $input->getOption('exit-if-none') ? 4 : null;
         }
         $registry->set('feed', $feed);
         $output->writeln(sprintf('Online version is %s [%s]', $feed->getVersion(), $this->fetcher->getUpdateChannel()));
         if ($input->getOption('only-check')) {
             return;
         }
         $action = $this->ask($input, $output);
         if ($action === 'abort') {
             $output->writeln('Exiting on user command.');
             return 128;
         }
         $this->output = $output;
         $packageData = $downloadController->downloadOwncloud([$this, 'progress']);
         //Empty line, in order not to overwrite the progress message
         $this->output->writeln('');
         if (!$packageData['success']) {
             $registry->set('feed', null);
             throw $packageData['exception'];
         }
         if ($action === 'download') {
             $output->writeln('Downloading has been completed. Exiting.');
             return 64;
         }
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         $this->getApplication()->getLogger()->error($e->getMessage());
         $output->writeln('<error>Network error</error>');
         $output->writeln(sprintf('<error>Error %d: %s while fetching an URL %s</error>', $e->getCode(), $e->getResponse()->getReasonPhrase(), $e->getResponse()->getEffectiveUrl()));
         return 2;
     } catch (\Exception $e) {
         $this->getApplication()->getLogger()->error($e->getMessage());
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return 2;
     }
 }