public function downloadOwncloud($progressCallback = null)
 {
     $response = $this->getDefaultResponse();
     if (is_null($progressCallback)) {
         $progressCallback = function () {
         };
     }
     try {
         $feed = $this->getFeed();
         $path = $this->fetcher->getBaseDownloadPath($feed);
         // Fixme: Daily channel has no checksum
         $isDailyChannel = $this->fetcher->getUpdateChannel() == 'daily';
         if (!$isDailyChannel) {
             $md5 = $this->fetcher->getMd5($feed);
         } else {
             // We can't check md5 so we don't trust the cache
             $this->fsHelper->removeIfExists($path);
         }
         if ($isDailyChannel || !$this->checkIntegrity($path, $md5)) {
             $this->fetcher->getOwncloud($feed, $progressCallback);
         }
         if ($isDailyChannel || $this->checkIntegrity($path, $md5)) {
             $response['success'] = true;
             $response['data']['path'] = $path;
         } else {
             $response['exception'] = new \Exception('Deleted ' . $feed->getDownloadedFileName() . ' due to wrong checksum');
         }
     } catch (\Exception $e) {
         if (isset($path)) {
             $this->fsHelper->removeIfExists($path);
         }
         $response['exception'] = $e;
     }
     return $response;
 }
 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;
     }
 }