diff --git a/lib/private/OCM/Model/OCMProvider.php b/lib/private/OCM/Model/OCMProvider.php index 99a3770faef65..3b34e635c0565 100644 --- a/lib/private/OCM/Model/OCMProvider.php +++ b/lib/private/OCM/Model/OCMProvider.php @@ -30,7 +30,7 @@ class OCMProvider implements IOCMProvider { private bool $emittedEvent = false; public function __construct( - protected IEventDispatcher $dispatcher, + protected ?IEventDispatcher $dispatcher, ) { } @@ -125,7 +125,7 @@ public function getResourceTypes(): array { if (!$this->emittedEvent) { $this->emittedEvent = true; $event = new ResourceTypeRegisterEvent($this); - $this->dispatcher->dispatchTyped($event); + $this->dispatcher?->dispatchTyped($event); } return $this->resourceTypes; diff --git a/lib/private/OCM/OCMDiscoveryService.php b/lib/private/OCM/OCMDiscoveryService.php index af6124163720e..6847512f98e86 100644 --- a/lib/private/OCM/OCMDiscoveryService.php +++ b/lib/private/OCM/OCMDiscoveryService.php @@ -11,6 +11,7 @@ use GuzzleHttp\Exception\ConnectException; use JsonException; +use OC\OCM\Model\OCMProvider; use OCP\AppFramework\Http; use OCP\Http\Client\IClientService; use OCP\ICache; @@ -31,7 +32,6 @@ public function __construct( ICacheFactory $cacheFactory, private IClientService $clientService, private IConfig $config, - private IOCMProvider $provider, private LoggerInterface $logger, ) { $this->cache = $cacheFactory->createDistributed('ocm-discovery'); @@ -56,6 +56,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider } } + $provider = new OCMProvider(null); if (!$skipCache) { try { $cached = $this->cache->get($remote); @@ -63,8 +64,8 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider throw new OCMProviderException('Previous discovery failed.'); } - $this->provider->import(json_decode($cached ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []); - return $this->provider; + $provider->import(json_decode($cached ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []); + return $provider; } catch (JsonException|OCMProviderException $e) { // we ignore cache on issues } @@ -84,7 +85,7 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider if ($response->getStatusCode() === Http::STATUS_OK) { $body = $response->getBody(); // update provider with data returned by the request - $this->provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []); + $provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []); $this->cache->set($remote, $body, 60 * 60 * 24); } } catch (JsonException|OCMProviderException $e) { @@ -99,6 +100,6 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider throw new OCMProviderException('error while requesting remote ocm provider'); } - return $this->provider; + return $provider; } }