]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure the AppFetcher fetches the new applist from the appstore
authorRoeland Jago Douma <roeland@famdouma.nl>
Tue, 2 May 2017 08:08:16 +0000 (10:08 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Tue, 2 May 2017 08:24:10 +0000 (10:24 +0200)
When in the upgrade process the version in the config is still the old
version. (Since we only upgrade it after the upgrade is complete).
However the app list fetched from the appstore must be the new list.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/App/AppStore/Fetcher/AppFetcher.php
lib/private/App/AppStore/Fetcher/Fetcher.php
lib/private/Server.php
lib/private/Updater.php

index 7c5efafc92facef3a67c98c85988fb92b04a96b9..e020390988e9ebad35e2f8919901302bf378741e 100644 (file)
@@ -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();
+       }
 }
index bde925b745f163d6108fd29a7d3497128113fb1b..5354d334eb101a0f3f9aaa5a596ddc5930175d26 100644 (file)
@@ -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;
+       }
 }
index 6bc9a1429cd11192181b42e66bae04c55a1a4a83..07e449ee4a9d4ca6864f52c4f5e53293166e6b1b 100644 (file)
@@ -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)
index c080ee0eb43d71b3287a73d6963506b5d66d2f5a..5c4a7725a1b208b395c62fa06627b264ac897e96 100644 (file)
@@ -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());