summaryrefslogtreecommitdiffstats
path: root/lib/private/App/AppStore/Fetcher/AppFetcher.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/App/AppStore/Fetcher/AppFetcher.php')
-rw-r--r--lib/private/App/AppStore/Fetcher/AppFetcher.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php
index 19e61d416a0..32c207e3ac0 100644
--- a/lib/private/App/AppStore/Fetcher/AppFetcher.php
+++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php
@@ -21,12 +21,16 @@
namespace OC\App\AppStore\Fetcher;
+use OC\App\AppStore\Version\VersionParser;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
class AppFetcher extends Fetcher {
+ /** @var IConfig */
+ private $config;
+
/**
* @param IAppData $appData
* @param IClientService $clientService
@@ -44,6 +48,7 @@ class AppFetcher extends Fetcher {
);
$this->fileName = 'apps.json';
+ $this->config = $config;
$versionArray = \OC_Util::getVersion();
$this->endpointUrl = sprintf(
@@ -53,4 +58,66 @@ class AppFetcher extends Fetcher {
$versionArray[2]
);
}
+
+ /**
+ * Only returns the latest compatible app release in the releases array
+ *
+ * @return array
+ */
+ protected function fetch() {
+ $client = $this->clientService->newClient();
+ $response = $client->get($this->endpointUrl);
+ $responseJson = [];
+ $responseJson['data'] = json_decode($response->getBody(), true);
+ $responseJson['timestamp'] = $this->timeFactory->getTime();
+ $response = $responseJson;
+
+ $ncVersion = $this->config->getSystemValue('version');
+ $ncMajorVersion = explode('.', $ncVersion)[0];
+ foreach($response['data'] as $dataKey => $app) {
+ $releases = [];
+
+ // Filter all compatible releases
+ foreach($app['releases'] as $release) {
+ // Exclude all nightly releases
+ if($release['isNightly'] === false) {
+ // Exclude all versions not compatible with the current version
+ $versionParser = new VersionParser();
+ $version = $versionParser->getVersion($release['rawPlatformVersionSpec']);
+
+ if(
+ // Major version is bigger or equals to the minimum version of the app
+ version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=')
+ // Major version is smaller or equals to the maximum version of the app
+ && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=')) {
+ $releases[] = $release;
+ }
+ }
+ }
+
+ // Get the highest version
+ $versions = [];
+ foreach($releases as $release) {
+ $versions[] = $release['version'];
+ }
+ 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]);
+ }
+ }
+
+ return $response;
+ }
}