diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-03-20 19:22:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 19:22:38 +0100 |
commit | 03dc79f66561b1dbaba9c036c47f14697c065e0a (patch) | |
tree | f30bc648f217344d6565b1c4462c2d14b6a98906 /lib | |
parent | b72d270a9b1d441b4ac3a93a91486ebda68a654f (diff) | |
parent | 942281a48e2791cf6c46de758985e62806bed363 (diff) | |
download | nextcloud-server-03dc79f66561b1dbaba9c036c47f14697c065e0a.tar.gz nextcloud-server-03dc79f66561b1dbaba9c036c47f14697c065e0a.zip |
Merge pull request #14578 from nextcloud/enh/force_enable_apps
Force enable apps
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 28 | ||||
-rw-r--r-- | lib/private/App/DependencyAnalyzer.php | 46 | ||||
-rw-r--r-- | lib/private/Installer.php | 7 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 8 |
4 files changed, 57 insertions, 32 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index cf5839e4994..9ad8f582460 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -40,6 +40,9 @@ class AppFetcher extends Fetcher { /** @var CompareVersion */ private $compareVersion; + /** @var bool */ + private $ignoreMaxVersion; + /** * @param Factory $appDataFactory * @param IClientService $clientService @@ -65,6 +68,7 @@ class AppFetcher extends Fetcher { $this->fileName = 'apps.json'; $this->setEndpoint(); $this->compareVersion = $compareVersion; + $this->ignoreMaxVersion = true; } /** @@ -97,7 +101,7 @@ class AppFetcher extends Fetcher { $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $min, '>='); $maxFulfilled = $max !== '' && $this->compareVersion->isCompatible($ncVersion, $max, '<='); - if ($minFulfilled && $maxFulfilled) { + if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled)) { $releases[] = $release; } } catch (\InvalidArgumentException $e) { @@ -106,6 +110,11 @@ class AppFetcher extends Fetcher { } } + if (empty($releases)) { + // Remove apps that don't have a matching release + continue; + } + // Get the highest version $versions = []; foreach($releases as $release) { @@ -113,20 +122,15 @@ class AppFetcher extends Fetcher { } usort($versions, 'version_compare'); $versions = array_reverse($versions); - $compatible = false; if(isset($versions[0])) { $highestVersion = $versions[0]; foreach ($releases as $release) { if ((string)$release['version'] === (string)$highestVersion) { - $compatible = true; $response['data'][$dataKey]['releases'] = [$release]; break; } } } - if(!$compatible) { - unset($response['data'][$dataKey]); - } } $response['data'] = array_values($response['data']); @@ -134,22 +138,18 @@ class AppFetcher extends Fetcher { } 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] - ); + $this->endpointUrl = 'https://apps.nextcloud.com/api/v1/apps.json'; } /** * @param string $version * @param string $fileName + * @param bool $ignoreMaxVersion */ - public function setVersion(string $version, string $fileName = 'apps.json') { + public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { parent::setVersion($version); $this->fileName = $fileName; + $this->ignoreMaxVersion = $ignoreMaxVersion; $this->setEndpoint(); } } diff --git a/lib/private/App/DependencyAnalyzer.php b/lib/private/App/DependencyAnalyzer.php index 1e4d597dbc4..15a6a229476 100644 --- a/lib/private/App/DependencyAnalyzer.php +++ b/lib/private/App/DependencyAnalyzer.php @@ -29,6 +29,7 @@ namespace OC\App; +use OCP\IConfig; use OCP\IL10N; class DependencyAnalyzer { @@ -53,7 +54,7 @@ class DependencyAnalyzer { * @param array $app * @returns array of missing dependencies */ - public function analyze(array $app) { + public function analyze(array $app, bool $ignoreMax = false) { $this->appInfo = $app; if (isset($app['dependencies'])) { $dependencies = $app['dependencies']; @@ -67,10 +68,24 @@ class DependencyAnalyzer { $this->analyzeCommands($dependencies), $this->analyzeLibraries($dependencies), $this->analyzeOS($dependencies), - $this->analyzeOC($dependencies, $app) + $this->analyzeOC($dependencies, $app, $ignoreMax) ); } + public function isMarkedCompatible(array $app): bool { + if (isset($app['dependencies'])) { + $dependencies = $app['dependencies']; + } else { + $dependencies = []; + } + + $maxVersion = $this->getMaxVersion($dependencies, $app); + if ($maxVersion === null) { + return true; + } + return !$this->compareBigger($this->platform->getOcVersion(), $maxVersion); + } + /** * Truncates both versions to the lowest common version, e.g. * 5.1.2.3 and 5.1 will be turned into 5.1 and 5.1, @@ -293,7 +308,7 @@ class DependencyAnalyzer { * @param array $appInfo * @return array */ - private function analyzeOC(array $dependencies, array $appInfo) { + private function analyzeOC(array $dependencies, array $appInfo, bool $ignoreMax) { $missing = []; $minVersion = null; if (isset($dependencies['nextcloud']['@attributes']['min-version'])) { @@ -305,21 +320,14 @@ class DependencyAnalyzer { } elseif (isset($appInfo['require'])) { $minVersion = $appInfo['require']; } - $maxVersion = null; - if (isset($dependencies['nextcloud']['@attributes']['max-version'])) { - $maxVersion = $dependencies['nextcloud']['@attributes']['max-version']; - } elseif (isset($dependencies['owncloud']['@attributes']['max-version'])) { - $maxVersion = $dependencies['owncloud']['@attributes']['max-version']; - } elseif (isset($appInfo['requiremax'])) { - $maxVersion = $appInfo['requiremax']; - } + $maxVersion = $this->getMaxVersion($dependencies, $appInfo); if (!is_null($minVersion)) { if ($this->compareSmaller($this->platform->getOcVersion(), $minVersion)) { $missing[] = (string)$this->l->t('Server version %s or higher is required.', [$this->toVisibleVersion($minVersion)]); } } - if (!is_null($maxVersion)) { + if (!$ignoreMax && !is_null($maxVersion)) { if ($this->compareBigger($this->platform->getOcVersion(), $maxVersion)) { $missing[] = (string)$this->l->t('Server version %s or lower is required.', [$this->toVisibleVersion($maxVersion)]); } @@ -327,6 +335,20 @@ class DependencyAnalyzer { return $missing; } + private function getMaxVersion(array $dependencies, array $appInfo): ?string { + if (isset($dependencies['nextcloud']['@attributes']['max-version'])) { + return $dependencies['nextcloud']['@attributes']['max-version']; + } + if (isset($dependencies['owncloud']['@attributes']['max-version'])) { + return $dependencies['owncloud']['@attributes']['max-version']; + } + if (isset($appInfo['requiremax'])) { + return $appInfo['requiremax']; + } + + return null; + } + /** * Map the internal version number to the Nextcloud version * diff --git a/lib/private/Installer.php b/lib/private/Installer.php index d58ccb36943..dc1110c0496 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -112,8 +112,11 @@ class Installer { ); } + $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []); + $ignoreMax = in_array($appId, $ignoreMaxApps); + $version = implode('.', \OCP\Util::getVersion()); - if (!\OC_App::isAppCompatible($version, $info)) { + if (!\OC_App::isAppCompatible($version, $info, $ignoreMax)) { throw new \Exception( // TODO $l $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', @@ -123,7 +126,7 @@ class Installer { } // check for required dependencies - \OC_App::checkAppDependencies($this->config, $l, $info); + \OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax); \OC_App::registerAutoloading($appId, $basedir); //install the database diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 9b4a83de349..9f51c022d6c 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -826,7 +826,7 @@ class OC_App { * * @return boolean true if compatible, otherwise false */ - public static function isAppCompatible(string $ocVersion, array $appInfo): bool { + public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool { $requireMin = ''; $requireMax = ''; if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { @@ -854,7 +854,7 @@ class OC_App { return false; } - if (!empty($requireMax) + if (!$ignoreMax && !empty($requireMax) && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') ) { return false; @@ -1090,9 +1090,9 @@ class OC_App { * @param array $info * @throws \Exception */ - public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info) { + public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info, bool $ignoreMax) { $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); - $missing = $dependencyAnalyzer->analyze($info); + $missing = $dependencyAnalyzer->analyze($info, $ignoreMax); if (!empty($missing)) { $missingMsg = implode(PHP_EOL, $missing); throw new \Exception( |