diff options
Diffstat (limited to 'lib/private/App/AppStore/Fetcher/AppFetcher.php')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 122 |
1 files changed, 59 insertions, 63 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 4dc517879e8..bbf4b00245b 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -1,33 +1,9 @@ <?php + /** - * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OC\App\AppStore\Fetcher; use OC\App\AppStore\Version\VersionParser; @@ -36,41 +12,33 @@ use OC\Files\AppData\Factory; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; +use OCP\Support\Subscription\IRegistry; +use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { - - /** @var CompareVersion */ - private $compareVersion; - /** @var bool */ private $ignoreMaxVersion; - /** - * @param Factory $appDataFactory - * @param IClientService $clientService - * @param ITimeFactory $timeFactory - * @param IConfig $config - * @param CompareVersion $compareVersion - * @param ILogger $logger - */ - public function __construct(Factory $appDataFactory, - IClientService $clientService, - ITimeFactory $timeFactory, - IConfig $config, - CompareVersion $compareVersion, - ILogger $logger) { + public function __construct( + Factory $appDataFactory, + IClientService $clientService, + ITimeFactory $timeFactory, + IConfig $config, + private CompareVersion $compareVersion, + LoggerInterface $logger, + protected IRegistry $registry, + ) { parent::__construct( $appDataFactory, $clientService, $timeFactory, $config, - $logger + $logger, + $registry ); $this->fileName = 'apps.json'; $this->endpointName = 'apps.json'; - $this->compareVersion = $compareVersion; $this->ignoreMaxVersion = true; } @@ -87,8 +55,13 @@ class AppFetcher extends Fetcher { /** @var mixed[] $response */ $response = parent::fetch($ETag, $content); - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily'; - $allowNightly = $allowUnstable || $this->getChannel() === 'daily'; + if (!isset($response['data']) || $response['data'] === null) { + $this->logger->warning('Response from appstore is invalid, apps could not be retrieved. Try again later.', ['app' => 'appstoreFetcher']); + return []; + } + + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; + $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; foreach ($response['data'] as $dataKey => $app) { $releases = []; @@ -97,7 +70,7 @@ class AppFetcher extends Fetcher { foreach ($app['releases'] as $release) { // Exclude all nightly and pre-releases if required if (($allowNightly || $release['isNightly'] === false) - && ($allowPreReleases || strpos($release['version'], '-') === false)) { + && ($allowPreReleases || !str_contains($release['version'], '-'))) { // Exclude all versions not compatible with the current version try { $versionParser = new VersionParser(); @@ -106,23 +79,23 @@ class AppFetcher extends Fetcher { $minServerVersion = $serverVersion->getMinimumVersion(); $maxServerVersion = $serverVersion->getMaximumVersion(); $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); - $maxFulfilled = $maxServerVersion !== '' && - $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); + $maxFulfilled = $maxServerVersion !== '' + && $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); $isPhpCompatible = true; if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); $minPhpVersion = $phpVersion->getMinimumVersion(); $maxPhpVersion = $phpVersion->getMaximumVersion(); $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( - PHP_VERSION, - $minPhpVersion, - '>=' - ); + PHP_VERSION, + $minPhpVersion, + '>=' + ); $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( - PHP_VERSION, - $maxPhpVersion, - '<=' - ); + PHP_VERSION, + $maxPhpVersion, + '<=' + ); $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; } @@ -130,7 +103,9 @@ class AppFetcher extends Fetcher { $releases[] = $release; } } catch (\InvalidArgumentException $e) { - $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]); + $this->logger->warning($e->getMessage(), [ + 'exception' => $e, + ]); } } } @@ -146,7 +121,9 @@ class AppFetcher extends Fetcher { foreach ($releases as $release) { $versions[] = $release['version']; } - usort($versions, 'version_compare'); + usort($versions, function ($version1, $version2) { + return version_compare($version1, $version2); + }); $versions = array_reverse($versions); if (isset($versions[0])) { $highestVersion = $versions[0]; @@ -173,4 +150,23 @@ class AppFetcher extends Fetcher { $this->fileName = $fileName; $this->ignoreMaxVersion = $ignoreMaxVersion; } + + public function get($allowUnstable = false): array { + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; + + $apps = parent::get($allowPreReleases); + if (empty($apps)) { + return []; + } + $allowList = $this->config->getSystemValue('appsallowlist'); + + // If the admin specified a allow list, filter apps from the appstore + if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { + return array_filter($apps, function ($app) use ($allowList) { + return in_array($app['id'], $allowList); + }); + } + + return $apps; + } } |