diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-05-02 10:45:04 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 10:45:04 -0300 |
commit | 705483e7123e2e2da6421d7f02c4a5b899cade3d (patch) | |
tree | aa34102fa61968a6070d1aa5ee0da9d4011bbc24 | |
parent | 94c2f12226ed005fc2a1e9c440ec70346e9c272a (diff) | |
parent | 73b4ef53f07c7b4de3f669117904b45f1db61347 (diff) | |
download | nextcloud-server-705483e7123e2e2da6421d7f02c4a5b899cade3d.tar.gz nextcloud-server-705483e7123e2e2da6421d7f02c4a5b899cade3d.zip |
Merge pull request #4651 from nextcloud/fix_appfetcher_update
Make sure the AppFetcher fetches the new applist from the appstore
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 29 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 25 | ||||
-rw-r--r-- | lib/private/Server.php | 7 | ||||
-rw-r--r-- | lib/private/Updater.php | 4 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 30 | ||||
-rw-r--r-- | version.php | 2 |
6 files changed, 61 insertions, 36 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; + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 6bc9a1429cd..07e449ee4a9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -420,7 +420,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('AppHelper', function ($c) { return new \OC\AppHelper(); }); - $this->registerService('AppFetcher', function ($c) { + $this->registerService(AppFetcher::class, function ($c) { return new AppFetcher( $this->getAppDataDir('appstore'), $this->getHTTPClientService(), @@ -428,6 +428,8 @@ class Server extends ServerContainer implements IServerContainer { $this->getConfig() ); }); + $this->registerAlias('AppFetcher', AppFetcher::class); + $this->registerService('CategoryFetcher', function ($c) { return new CategoryFetcher( $this->getAppDataDir('appstore'), @@ -821,9 +823,6 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService(BundleFetcher::class, function () { return new BundleFetcher($this->getL10N('lib')); }); - $this->registerService(AppFetcher::class, function() { - return $this->getAppFetcher(); - }); $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { return new Manager( $c->query(IValidator::class) diff --git a/lib/private/Updater.php b/lib/private/Updater.php index c080ee0eb43..5c4a7725a1b 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -32,6 +32,7 @@ namespace OC; +use OC\App\AppStore\Fetcher\AppFetcher; use OC\Hooks\BasicEmitter; use OC\IntegrityCheck\Checker; use OC_App; @@ -246,6 +247,9 @@ class Updater extends BasicEmitter { $this->checkAppsRequirements(); $this->doAppUpgrade(); + // Update the appfetchers version so it downloads the correct list from the appstore + \OC::$server->getAppFetcher()->setVersion($currentVersion); + // upgrade appstore apps $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index 4a5222fa915..6c0d079a204 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -72,26 +72,16 @@ EOD; } public function testGetWithFilter() { - $this->config - ->expects($this->at(0)) - ->method('getSystemValue') - ->with('appstoreenabled', true) - ->willReturn(true); - $this->config - ->expects($this->at(1)) - ->method('getSystemValue') - ->with('appstoreenabled', true) - ->willReturn(true); - $this->config - ->expects($this->at(2)) - ->method('getSystemValue') - ->with('version') - ->willReturn('11.0.0.2'); - $this->config - ->expects($this->at(3)) - ->method('getSystemValue') - ->with('version') - ->willReturn('11.0.0.2'); + $this->config->method('getSystemValue') + ->willReturnCallback(function($key, $default) { + if ($key === 'appstoreenabled') { + return true; + } else if ($key === 'version') { + return '11.0.0.2'; + } else { + return $default; + } + }); $file = $this->createMock(ISimpleFile::class); $folder = $this->createMock(ISimpleFolder::class); diff --git a/version.php b/version.php index b7e8b1ac6d8..c1b989c8790 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(12, 0, 0, 16); +$OC_Version = array(12, 0, 0, 17); // The human readable string $OC_VersionString = '12.0 beta 1'; |