Merge pull request #49471 from nextcloud/backport/49311/stable29

This commit is contained in:
Kate 2024-11-25 13:27:00 +01:00 committed by GitHub
commit 7bebbc1e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,7 +72,12 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
if (!$skipCache) {
try {
$this->provider->import(json_decode($this->cache->get($remote) ?? '', true, 8, JSON_THROW_ON_ERROR) ?? []);
$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) ?? []);
if ($this->supportedAPIVersion($this->provider->getApiVersion())) {
return $this->provider; // if cache looks valid, we use it
}
@ -99,8 +104,10 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
$this->cache->set($remote, $body, 60 * 60 * 24);
}
} catch (JsonException|OCMProviderException $e) {
$this->cache->set($remote, false, 5 * 60);
throw new OCMProviderException('data returned by remote seems invalid - ' . ($body ?? ''));
} catch (\Exception $e) {
$this->cache->set($remote, false, 5 * 60);
$this->logger->warning('error while discovering ocm provider', [
'exception' => $e,
'remote' => $remote
@ -109,6 +116,7 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
}
if (!$this->supportedAPIVersion($this->provider->getApiVersion())) {
$this->cache->set($remote, false, 5 * 60);
throw new OCMProviderException('API version not supported');
}