diff options
Diffstat (limited to 'lib/private/App/AppStore/Fetcher')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 29 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 25 |
2 files changed, 43 insertions, 11 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 7c5efafc92f..e020390988e 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -46,14 +46,7 @@ class AppFetcher extends Fetcher { ); $this->fileName = 'apps.json'; - - $versionArray = explode('.', $this->config->getSystemValue('version')); - $this->endpointUrl = sprintf( - 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', - $versionArray[0], - $versionArray[1], - $versionArray[2] - ); + $this->setEndpoint(); } /** @@ -68,7 +61,7 @@ class AppFetcher extends Fetcher { /** @var mixed[] $response */ $response = parent::fetch($ETag, $content); - $ncVersion = $this->config->getSystemValue('version'); + $ncVersion = $this->getVersion(); $ncMajorVersion = explode('.', $ncVersion)[0]; foreach($response['data'] as $dataKey => $app) { $releases = []; @@ -118,4 +111,22 @@ class AppFetcher extends Fetcher { $response['data'] = array_values($response['data']); return $response; } + + private function setEndpoint() { + $versionArray = explode('.', $this->getVersion()); + $this->endpointUrl = sprintf( + 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', + $versionArray[0], + $versionArray[1], + $versionArray[2] + ); + } + + /** + * @param string $version + */ + public function setVersion($version) { + parent::setVersion($version); + $this->setEndpoint(); + } } diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index bde925b745f..5354d334eb1 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -43,6 +43,8 @@ abstract class Fetcher { protected $fileName; /** @var string */ protected $endpointUrl; + /** @var string */ + protected $version; /** * @param IAppData $appData @@ -95,7 +97,7 @@ abstract class Fetcher { } $responseJson['timestamp'] = $this->timeFactory->getTime(); - $responseJson['ncversion'] = $this->config->getSystemValue('version'); + $responseJson['ncversion'] = $this->getVersion(); if ($ETag !== '') { $responseJson['ETag'] = $ETag; } @@ -127,7 +129,7 @@ abstract class Fetcher { if (is_array($jsonBlob)) { // No caching when the version has been updated - if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->config->getSystemValue('version', '0.0.0')) { + if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { // If the timestamp is older than 300 seconds request the files new if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { @@ -154,4 +156,23 @@ abstract class Fetcher { return []; } } + + /** + * Get the currently Nextcloud version + * @return string + */ + protected function getVersion() { + if ($this->version === null) { + $this->version = $this->config->getSystemValue('version', '0.0.0'); + } + return $this->version; + } + + /** + * Set the current Nextcloud version + * @param string $version + */ + public function setVersion($version) { + $this->version = $version; + } } |