diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-12-16 17:14:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-16 17:14:53 +0100 |
commit | b0c1460a1d7d71cb752637b42154cd515c2b489e (patch) | |
tree | eebdfc210a571cb08a9cc5f5b93237cd5a42c5b2 /lib | |
parent | f86f4eb98d1c30ee575997c47d4ada9fd2190270 (diff) | |
parent | 245501fb0c2aedd7b332a1c6978dac604992069c (diff) | |
download | nextcloud-server-b0c1460a1d7d71cb752637b42154cd515c2b489e.tar.gz nextcloud-server-b0c1460a1d7d71cb752637b42154cd515c2b489e.zip |
Merge pull request #2707 from nextcloud/clear_appstore_cache_on_upgrade
Clear appstore cache on version upgrade
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 15 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/CategoryFetcher.php | 8 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 17 | ||||
-rw-r--r-- | lib/private/Server.php | 3 |
4 files changed, 26 insertions, 17 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index b8efdef4336..9ebc12dbc27 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -28,9 +28,6 @@ use OCP\Http\Client\IClientService; use OCP\IConfig; class AppFetcher extends Fetcher { - /** @var IConfig */ - private $config; - /** * @param IAppData $appData * @param IClientService $clientService @@ -44,11 +41,11 @@ class AppFetcher extends Fetcher { parent::__construct( $appData, $clientService, - $timeFactory + $timeFactory, + $config ); $this->fileName = 'apps.json'; - $this->config = $config; $versionArray = explode('.', $this->config->getSystemValue('version')); $this->endpointUrl = sprintf( @@ -65,12 +62,8 @@ class AppFetcher extends Fetcher { * @return array */ protected function fetch() { - $client = $this->clientService->newClient(); - $response = $client->get($this->endpointUrl); - $responseJson = []; - $responseJson['data'] = json_decode($response->getBody(), true); - $responseJson['timestamp'] = $this->timeFactory->getTime(); - $response = $responseJson; + /** @var mixed[] $response */ + $response = parent::fetch(); $ncVersion = $this->config->getSystemValue('version'); $ncMajorVersion = explode('.', $ncVersion)[0]; diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index 74201ec3737..8b79259a66a 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -24,20 +24,24 @@ namespace OC\App\AppStore\Fetcher; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IAppData; use OCP\Http\Client\IClientService; +use OCP\IConfig; class CategoryFetcher extends Fetcher { /** * @param IAppData $appData * @param IClientService $clientService * @param ITimeFactory $timeFactory + * @param IConfig $config */ public function __construct(IAppData $appData, IClientService $clientService, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + IConfig $config) { parent::__construct( $appData, $clientService, - $timeFactory + $timeFactory, + $config ); $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 f82e1a253f6..2067242e817 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -25,6 +25,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; +use OCP\IConfig; abstract class Fetcher { const INVALIDATE_AFTER_SECONDS = 300; @@ -35,6 +36,8 @@ abstract class Fetcher { protected $clientService; /** @var ITimeFactory */ protected $timeFactory; + /** @var IConfig */ + protected $config; /** @var string */ protected $fileName; /** @var string */ @@ -44,13 +47,16 @@ abstract class Fetcher { * @param IAppData $appData * @param IClientService $clientService * @param ITimeFactory $timeFactory + * @param IConfig $config */ public function __construct(IAppData $appData, IClientService $clientService, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + IConfig $config) { $this->appData = $appData; $this->clientService = $clientService; $this->timeFactory = $timeFactory; + $this->config = $config; } /** @@ -64,6 +70,7 @@ abstract class Fetcher { $responseJson = []; $responseJson['data'] = json_decode($response->getBody(), true); $responseJson['timestamp'] = $this->timeFactory->getTime(); + $responseJson['ncversion'] = $this->config->getSystemValue('version'); return $responseJson; } @@ -80,8 +87,12 @@ abstract class Fetcher { $file = $rootFolder->getFile($this->fileName); $jsonBlob = json_decode($file->getContent(), true); if(is_array($jsonBlob)) { - // If the timestamp is older than 300 seconds request the files new - if((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { + /* + * If the timestamp is older than 300 seconds request the files new + * If the version changed (update!) also refresh + */ + if((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS) && + isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->config->getSystemValue('version', '0.0.0')) { return $jsonBlob['data']; } } diff --git a/lib/private/Server.php b/lib/private/Server.php index b2fa9691b16..969e5a25b9b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -360,7 +360,8 @@ class Server extends ServerContainer implements IServerContainer { return new CategoryFetcher( $this->getAppDataDir('appstore'), $this->getHTTPClientService(), - $this->query(TimeFactory::class) + $this->query(TimeFactory::class), + $this->getConfig() ); }); $this->registerService('UserCache', function ($c) { |