]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow to update to nightly 20741/head
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Thu, 30 Apr 2020 07:43:33 +0000 (09:43 +0200)
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Fri, 7 Aug 2020 11:51:39 +0000 (13:51 +0200)
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
core/Command/App/Disable.php
core/Command/App/Enable.php
core/Command/App/Install.php
core/Command/App/Remove.php
core/Command/App/Update.php
lib/private/App/AppStore/Fetcher/AppFetcher.php
lib/private/App/AppStore/Fetcher/Fetcher.php
lib/private/Installer.php
tests/Core/Command/Apps/AppsDisableTest.php
tests/Core/Command/Apps/AppsEnableTest.php

index ba9b8d769e591c6306544b2d32564e5003623798..88b8539fb2ea9629ccdc375091f2a4d8d0984a29 100644 (file)
@@ -78,7 +78,8 @@ class Disable extends Command implements CompletionAwareInterface {
 
                try {
                        $this->appManager->disableApp($appId);
-                       $output->writeln($appId . ' disabled');
+                       $appVersion = \OC_App::getAppVersion($appId);
+                       $output->writeln($appId . ' ' . $appVersion . ' disabled');
                } catch (\Exception $e) {
                        $output->writeln($e->getMessage());
                        $this->exitCode = 2;
index 2e26184b199350ddf7679b2aa6cefcdfe576793d..e1605942d8214c080af1f2664107e5904233c155 100644 (file)
@@ -120,13 +120,14 @@ class Enable extends Command implements CompletionAwareInterface {
                        }
 
                        $installer->installApp($appId, $forceEnable);
+                       $appVersion = \OC_App::getAppVersion($appId);
 
                        if ($groupIds === []) {
                                $this->appManager->enableApp($appId, $forceEnable);
-                               $output->writeln($appId . ' enabled');
+                               $output->writeln($appId . ' ' . $appVersion . ' enabled');
                        } else {
                                $this->appManager->enableAppForGroups($appId, $groupIds, $forceEnable);
-                               $output->writeln($appId . ' enabled for groups: ' . implode(', ', $groupNames));
+                               $output->writeln($appId . ' ' . $appVersion . ' enabled for groups: ' . implode(', ', $groupNames));
                        }
                } catch (AppPathNotFoundException $e) {
                        $output->writeln($appId . ' not found');
index 41e3e20c9dc201c8f7757b576c9826d459418d25..898e39416f357a7ebc32a68bf44c34cb0df44208 100644 (file)
@@ -74,7 +74,8 @@ class Install extends Command {
                        return 1;
                }
 
-               $output->writeln($appId . ' installed');
+               $appVersion = \OC_App::getAppVersion($appId);
+               $output->writeln($appId . ' ' . $appVersion . ' installed');
 
                if (!$input->getOption('keep-disabled')) {
                        $appClass = new \OC_App();
index 96d1efe8c6207a5f538861fa179bcf8d10426d90..1135b7b446e328c4edf20879cbc8573ab23c6951 100644 (file)
@@ -124,7 +124,8 @@ class Remove extends Command implements CompletionAwareInterface {
                        return 1;
                }
 
-               $output->writeln($appId . ' removed');
+               $appVersion = \OC_App::getAppVersion($appId);
+               $output->writeln($appId . ' ' . $appVersion . ' removed');
 
                return 0;
        }
index 34178c1ee7cecdaeb2e039d13215236d3a149ea7..1efafc47e93def692352c4e0e5ecb517b2aaba45 100644 (file)
@@ -76,7 +76,12 @@ class Update extends Command {
                                InputOption::VALUE_NONE,
                                'show update(s) without updating'
                        )
-
+                       ->addOption(
+                               'allow-unstable',
+                               null,
+                               InputOption::VALUE_NONE,
+                               'allow updating to unstable releases'
+                       )
                ;
        }
 
@@ -100,13 +105,13 @@ class Update extends Command {
 
                $return = 0;
                foreach ($apps as $appId) {
-                       $newVersion = $this->installer->isUpdateAvailable($appId);
+                       $newVersion = $this->installer->isUpdateAvailable($appId, $input->getOption('allow-unstable'));
                        if ($newVersion) {
                                $output->writeln($appId . ' new version available: ' . $newVersion);
 
                                if (!$input->getOption('showonly')) {
                                        try {
-                                               $result = $this->installer->updateAppstoreApp($appId);
+                                               $result = $this->installer->updateAppstoreApp($appId, $input->getOption('allow-unstable'));
                                        } catch (\Exception $e) {
                                                $this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']);
                                                $output->writeln('Error: ' . $e->getMessage());
index e4c2ba4e85eca72cf6b3be1492c66774c7f43e0b..f108d23dd9b2c0a18d5a95faceb31f3a1a712e9c 100644 (file)
@@ -78,15 +78,16 @@ class AppFetcher extends Fetcher {
         *
         * @param string $ETag
         * @param string $content
+        * @param bool [$allowUnstable] Allow unstable releases
         *
         * @return array
         */
-       protected function fetch($ETag, $content) {
+       protected function fetch($ETag, $content, $allowUnstable = false) {
                /** @var mixed[] $response */
                $response = parent::fetch($ETag, $content);
 
-               $allowPreReleases = $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
-               $allowNightly = $this->getChannel() === 'daily';
+               $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily';
+               $allowNightly = $allowUnstable || $this->getChannel() === 'daily';
 
                foreach ($response['data'] as $dataKey => $app) {
                        $releases = [];
index 500a0568c9990c7da0e10504cb45bf76452bd1d8..fcb837ee1623fb6aa40a7bea371f8f0392b78977 100644 (file)
@@ -129,9 +129,10 @@ abstract class Fetcher {
        /**
         * Returns the array with the categories on the appstore server
         *
+        * @param bool [$allowUnstable] Allow unstable releases
         * @return array
         */
-       public function get() {
+       public function get($allowUnstable = false) {
                $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
                $internetavailable = $this->config->getSystemValue('has_internet_connection', true);
 
@@ -148,7 +149,9 @@ abstract class Fetcher {
                        // File does already exists
                        $file = $rootFolder->getFile($this->fileName);
                        $jsonBlob = json_decode($file->getContent(), true);
-                       if (is_array($jsonBlob)) {
+
+                       // Always get latests apps info if $allowUnstable
+                       if (!$allowUnstable && is_array($jsonBlob)) {
 
                                // No caching when the version has been updated
                                if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
@@ -171,7 +174,12 @@ abstract class Fetcher {
 
                // Refresh the file content
                try {
-                       $responseJson = $this->fetch($ETag, $content);
+                       $responseJson = $this->fetch($ETag, $content, $allowUnstable);
+                       // Don't store the apps request file
+                       if ($allowUnstable) {
+                               return $responseJson['data'];
+                       }
+
                        $file->putContent(json_encode($responseJson));
                        return json_decode($file->getContent(), true)['data'];
                } catch (ConnectException $e) {
index d5c9d076edadd722f0a7fc6d3c8f28f94a2ba706..9be79ac72bba2249e7e9315272333c7eb3748e73 100644 (file)
@@ -189,12 +189,13 @@ class Installer {
         * Updates the specified app from the appstore
         *
         * @param string $appId
+        * @param bool [$allowUnstable] Allow unstable releases
         * @return bool
         */
-       public function updateAppstoreApp($appId) {
-               if ($this->isUpdateAvailable($appId)) {
+       public function updateAppstoreApp($appId, $allowUnstable = false) {
+               if ($this->isUpdateAvailable($appId, $allowUnstable)) {
                        try {
-                               $this->downloadApp($appId);
+                               $this->downloadApp($appId, $allowUnstable);
                        } catch (\Exception $e) {
                                $this->logger->logException($e, [
                                        'level' => ILogger::ERROR,
@@ -212,13 +213,14 @@ class Installer {
         * Downloads an app and puts it into the app directory
         *
         * @param string $appId
+        * @param bool [$allowUnstable]
         *
         * @throws \Exception If the installation was not successful
         */
-       public function downloadApp($appId) {
+       public function downloadApp($appId, $allowUnstable = false) {
                $appId = strtolower($appId);
 
-               $apps = $this->appFetcher->get();
+               $apps = $this->appFetcher->get($allowUnstable);
                foreach ($apps as $app) {
                        if ($app['id'] === $appId) {
                                // Load the certificate
@@ -384,9 +386,10 @@ class Installer {
         * Check if an update for the app is available
         *
         * @param string $appId
+        * @param bool $allowUnstable
         * @return string|false false or the version number of the update
         */
-       public function isUpdateAvailable($appId) {
+       public function isUpdateAvailable($appId, $allowUnstable = false) {
                if ($this->isInstanceReadyForUpdates === null) {
                        $installPath = OC_App::getInstallPath();
                        if ($installPath === false || $installPath === null) {
@@ -405,7 +408,7 @@ class Installer {
                }
 
                if ($this->apps === null) {
-                       $this->apps = $this->appFetcher->get();
+                       $this->apps = $this->appFetcher->get($allowUnstable);
                }
 
                foreach ($this->apps as $app) {
index b5fd18ece225c56263e266b103e7fe4ff33cff4e..e19668dea9d2b3353903b7ecdf90e01fb7c6434a 100644 (file)
@@ -68,18 +68,18 @@ class AppsDisableTest extends TestCase {
 
        public function dataCommandInput(): array {
                return [
-                       [['admin_audit'], 0, 'admin_audit disabled'],
-                       [['comments'], 0, 'comments disabled'],
+                       [['admin_audit'], 0, 'admin_audit 1.10.0 disabled'],
+                       [['comments'], 0, 'comments 1.10.0 disabled'],
                        [['invalid_app'], 0, 'No such app enabled: invalid_app'],
 
-                       [['admin_audit', 'comments'], 0, "admin_audit disabled\ncomments disabled"],
-                       [['admin_audit', 'comments', 'invalid_app'], 0, "admin_audit disabled\ncomments disabled\nNo such app enabled: invalid_app"],
+                       [['admin_audit', 'comments'], 0, "admin_audit 1.10.0 disabled\ncomments 1.10.0 disabled"],
+                       [['admin_audit', 'comments', 'invalid_app'], 0, "admin_audit 1.10.0 disabled\ncomments 1.10.0 disabled\nNo such app enabled: invalid_app"],
 
                        [['files'], 2, "files can't be disabled"],
                        [['provisioning_api'], 2, "provisioning_api can't be disabled"],
 
-                       [['files', 'admin_audit'], 2, "files can't be disabled.\nadmin_audit disabled"],
-                       [['provisioning_api', 'comments'], 2, "provisioning_api can't be disabled.\ncomments disabled"],
+                       [['files', 'admin_audit'], 2, "files can't be disabled.\nadmin_audit 1.10.0 disabled"],
+                       [['provisioning_api', 'comments'], 2, "provisioning_api can't be disabled.\ncomments 1.10.0 disabled"],
 
                ];
        }
index b5d781aa125c9a2b1a0f34d50884f0d5463c7db0..bcf3d9dd82c2af9a4d54a1a6b13f81e071ad514b 100644 (file)
@@ -73,29 +73,29 @@ class AppsEnableTest extends TestCase {
 
        public function dataCommandInput(): array {
                $data = [
-                       [['admin_audit'], null, 0, 'admin_audit enabled'],
-                       [['comments'], null, 0, 'comments enabled'],
-                       [['comments', 'comments'], null, 0, "comments enabled\ncomments already enabled"],
+                       [['admin_audit'], null, 0, 'admin_audit 1.10.0 enabled'],
+                       [['comments'], null, 0, 'comments 1.10.0 enabled'],
+                       [['comments', 'comments'], null, 0, "comments 1.10.0 enabled\ncomments already enabled"],
                        [['invalid_app'], null, 1, 'Could not download app invalid_app'],
 
-                       [['admin_audit', 'comments'], null, 0, "admin_audit enabled\ncomments enabled"],
-                       [['admin_audit', 'comments', 'invalid_app'], null, 1, "admin_audit enabled\ncomments enabled\nCould not download app invalid_app"],
+                       [['admin_audit', 'comments'], null, 0, "admin_audit 1.10.0 enabled\ncomments 1.10.0 enabled"],
+                       [['admin_audit', 'comments', 'invalid_app'], null, 1, "admin_audit 1.10.0 enabled\ncomments 1.10.0 enabled\nCould not download app invalid_app"],
 
                        [['admin_audit'], ['admin'], 1, "admin_audit can't be enabled for groups"],
                        [['comments'], ['admin'], 1, "comments can't be enabled for groups"],
 
-                       [['updatenotification'], ['admin'], 0, 'updatenotification enabled for groups: admin'],
-                       [['updatenotification', 'accessibility'], ['admin'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"],
+                       [['updatenotification'], ['admin'], 0, 'updatenotification 1.10.0 enabled for groups: admin'],
+                       [['updatenotification', 'accessibility'], ['admin'], 0, "updatenotification 1.10.0 enabled for groups: admin\naccessibility 1.6.0 enabled for groups: admin"],
 
-                       [['updatenotification'], ['admin', 'invalid_group'], 0, 'updatenotification enabled for groups: admin'],
-                       [['updatenotification', 'accessibility'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin"],
-                       [['updatenotification', 'accessibility', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\naccessibility enabled for groups: admin\nCould not download app invalid_app"],
+                       [['updatenotification'], ['admin', 'invalid_group'], 0, 'updatenotification 1.10.0 enabled for groups: admin'],
+                       [['updatenotification', 'accessibility'], ['admin', 'invalid_group'], 0, "updatenotification 1.10.0 enabled for groups: admin\naccessibility 1.6.0 enabled for groups: admin"],
+                       [['updatenotification', 'accessibility', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification 1.10.0 enabled for groups: admin\naccessibility 1.6.0 enabled for groups: admin\nCould not download app invalid_app"],
                ];
 
                if (getenv('CI') === false) {
                        /** Tests disabled on drone/ci due to appstore dependency */
-                       $data[] = [['updatenotification', 'contacts'], ['admin'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"];
-                       $data[] = [['updatenotification', 'contacts'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin"];
+                       $data[] = [['updatenotification', 'contacts'], ['admin'], 0, "updatenotification 1.10.0 enabled for groups: admin\ncontacts 3.3.0 enabled for groups: admin"];
+                       $data[] = [['updatenotification', 'contacts'], ['admin', 'invalid_group'], 0, "updatenotification enabled for groups: admin\ncontacts 3.3.0 enabled for groups: admin"];
                        $data[] = [['updatenotification', 'contacts', 'invalid_app'], ['admin', 'invalid_group'], 1, "updatenotification enabled for groups: admin\ncontacts enabled for groups: admin\nCould not download app invalid_app"];
                }