diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-03-06 19:59:15 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-03-20 15:16:11 +0100 |
commit | 769cb629aebd368fbddd6ea04067fdcfaa262e3e (patch) | |
tree | 432bfb3aca1d60128e79da57c2053bf7f19291a2 /lib/private/App | |
parent | 1c8779dc6e34a89ea9181b3cb252101e457c1543 (diff) | |
download | nextcloud-server-769cb629aebd368fbddd6ea04067fdcfaa262e3e.tar.gz nextcloud-server-769cb629aebd368fbddd6ea04067fdcfaa262e3e.zip |
allow enforcing apps to ignore the max version
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/App')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 18 | ||||
-rw-r--r-- | lib/private/App/DependencyAnalyzer.php | 46 |
2 files changed, 36 insertions, 28 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index cf5839e4994..d8c505757c8 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -93,11 +93,8 @@ class AppFetcher extends Fetcher { $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); $ncVersion = $this->getVersion(); $min = $version->getMinimumVersion(); - $max = $version->getMaximumVersion(); $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $min, '>='); - $maxFulfilled = $max !== '' && - $this->compareVersion->isCompatible($ncVersion, $max, '<='); - if ($minFulfilled && $maxFulfilled) { + if ($minFulfilled) { $releases[] = $release; } } catch (\InvalidArgumentException $e) { @@ -113,20 +110,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,13 +126,7 @@ 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'; } /** 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 * |