diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 2e181d754f126d4886e77c45cd5e199dc8f1462b..63f63aaf695a90cf3abed3f60230515915296d96 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -26,23 +26,27 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\ILogger; class AppFetcher extends Fetcher { /** * @param Factory $appDataFactory * @param IClientService $clientService * @param ITimeFactory $timeFactory - * @param IConfig $config; + * @param IConfig $config + * @param ILogger $logger */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, - IConfig $config) { + IConfig $config, + ILogger $logger) { parent::__construct( $appDataFactory, $clientService, $timeFactory, - $config + $config, + $logger ); $this->fileName = 'apps.json'; diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index 4c78665283386c2c617ce36b3b4b9f969d5e7298..8c3c963462ce9ea2403136f0d7cfa8a76971fc74 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -25,6 +25,7 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\ILogger; class CategoryFetcher extends Fetcher { /** @@ -32,16 +33,19 @@ class CategoryFetcher extends Fetcher { * @param IClientService $clientService * @param ITimeFactory $timeFactory * @param IConfig $config + * @param ILogger $logger */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, - IConfig $config) { + IConfig $config, + ILogger $logger) { parent::__construct( $appDataFactory, $clientService, $timeFactory, - $config + $config, + $logger ); $this->fileName = 'categories.json'; $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json'; diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index ccf5162ed82c4806fe1172caf76c1757f08ab075..02c55ac9d9198f136f330b239ade9e54d4a023a1 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -22,12 +22,14 @@ namespace OC\App\AppStore\Fetcher; use OC\Files\AppData\Factory; +use GuzzleHttp\Exception\ConnectException; use OCP\AppFramework\Http; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\ILogger; abstract class Fetcher { const INVALIDATE_AFTER_SECONDS = 300; @@ -40,6 +42,8 @@ abstract class Fetcher { protected $timeFactory; /** @var IConfig */ protected $config; + /** @var Ilogger */ + protected $logger; /** @var string */ protected $fileName; /** @var string */ @@ -52,15 +56,18 @@ abstract class Fetcher { * @param IClientService $clientService * @param ITimeFactory $timeFactory * @param IConfig $config + * @param ILogger $logger */ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, - IConfig $config) { + IConfig $config, + ILogger $logger) { $this->appData = $appDataFactory->get('appstore'); $this->clientService = $clientService; $this->timeFactory = $timeFactory; $this->config = $config; + $this->logger = $logger; } /** @@ -153,6 +160,9 @@ abstract class Fetcher { $responseJson = $this->fetch($ETag, $content); $file->putContent(json_encode($responseJson)); return json_decode($file->getContent(), true)['data']; + } catch (ConnectException $e) { + $this->logger->logException($e, ['app' => 'appstoreFetcher']); + return []; } catch (\Exception $e) { return []; } diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index f3769fc09c36df56a9a5ef0fef17ae0576b3ff69..2efecef4dc77898dab7a81d6e6ad478db179d11e 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -32,6 +32,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; +use OCP\ILogger; use Test\TestCase; class AppFetcherTest extends TestCase { @@ -43,6 +44,8 @@ class AppFetcherTest extends TestCase { protected $timeFactory; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + protected $logger; /** @var AppFetcher */ protected $fetcher; /** @var string */ @@ -64,6 +67,7 @@ EOD; $this->clientService = $this->createMock(IClientService::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(ILogger::class); $this->config ->expects($this->at(0)) @@ -74,7 +78,8 @@ EOD; $factory, $this->clientService, $this->timeFactory, - $this->config + $this->config, + $this->logger ); } diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php index 6143da662dc9c4735ce7a70a612a13c75e679c0e..a1ce718520fa94bc53144d66a59c73b2cc5ab5d3 100644 --- a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php @@ -33,7 +33,8 @@ class CategoryFetcherTest extends FetcherBase { $this->appDataFactory, $this->clientService, $this->timeFactory, - $this->config + $this->config, + $this->logger ); } diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 3d89ae942abdbe559374efe03849c9e0c07a9529..bd19141ea9f227f19ecc06c27dc14a60569260ff 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -32,6 +32,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; +use OCP\ILogger; use Test\TestCase; abstract class FetcherBase extends TestCase { @@ -45,6 +46,8 @@ abstract class FetcherBase extends TestCase { protected $timeFactory; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + protected $logger; /** @var Fetcher */ protected $fetcher; /** @var string */ @@ -63,6 +66,7 @@ abstract class FetcherBase extends TestCase { $this->clientService = $this->createMock(IClientService::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(ILogger::class); } public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() {