public function testDownloadOwncloudFailure()
 {
     $md5 = '911';
     $path = '/dev/null/o';
     $registry = new Registry();
     $registry->set('feed', new Feed($this->feedData));
     $badNewsException = new \Exception('Bad news');
     $fetcherMock = $this->getMockBuilder('Owncloud\\Updater\\Utils\\Fetcher')->disableOriginalConstructor()->getMock();
     $fetcherMock->method('getBaseDownloadPath')->willReturn($path);
     $fetcherMock->method('getOwncloud')->will($this->throwException($badNewsException));
     $fetcherMock->method('getMd5')->willReturn($md5 . '0');
     $fsHelperMock = $this->getMockBuilder('Owncloud\\Updater\\Utils\\FilesystemHelper')->disableOriginalConstructor()->getMock();
     $fsHelperMock->method('md5File')->willReturn($md5);
     $fsHelperMock->method('fileExists')->willReturn(true);
     $downloadController = new DownloadController($fetcherMock, $registry, $fsHelperMock);
     $result = $downloadController->downloadOwncloud();
     $this->assertArraySubset(['success' => false, 'data' => []], $result);
     $this->assertEquals($badNewsException, $result['exception']);
 }
Beispiel #2
0
 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($feed->getVersionString() . ' is found online');
         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;
     }
 }