Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/OCM/Model/OCMProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OCMProvider implements IOCMProvider {
private bool $emittedEvent = false;

public function __construct(
protected IEventDispatcher $dispatcher,
protected ?IEventDispatcher $dispatcher,
) {
}

Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions lib/private/OCM/OCMDiscoveryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -56,15 +56,16 @@ public function discover(string $remote, bool $skipCache = false): IOCMProvider
}
}

$provider = new OCMProvider(null);
if (!$skipCache) {
try {
$cached = $this->cache->get($remote);
if ($cached === false) {
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
}
Expand All @@ -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) {
Expand All @@ -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;
}
}
Loading