@@ -40,161 +40,161 @@ |
||
40 | 40 | |
41 | 41 | class AppFetcher extends Fetcher { |
42 | 42 | |
43 | - /** @var CompareVersion */ |
|
44 | - private $compareVersion; |
|
45 | - |
|
46 | - /** @var IRegistry */ |
|
47 | - protected $registry; |
|
48 | - |
|
49 | - /** @var bool */ |
|
50 | - private $ignoreMaxVersion; |
|
51 | - |
|
52 | - public function __construct(Factory $appDataFactory, |
|
53 | - IClientService $clientService, |
|
54 | - ITimeFactory $timeFactory, |
|
55 | - IConfig $config, |
|
56 | - CompareVersion $compareVersion, |
|
57 | - LoggerInterface $logger, |
|
58 | - IRegistry $registry) { |
|
59 | - parent::__construct( |
|
60 | - $appDataFactory, |
|
61 | - $clientService, |
|
62 | - $timeFactory, |
|
63 | - $config, |
|
64 | - $logger, |
|
65 | - $registry |
|
66 | - ); |
|
67 | - |
|
68 | - $this->compareVersion = $compareVersion; |
|
69 | - $this->registry = $registry; |
|
70 | - |
|
71 | - $this->fileName = 'apps.json'; |
|
72 | - $this->endpointName = 'apps.json'; |
|
73 | - $this->ignoreMaxVersion = true; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Only returns the latest compatible app release in the releases array |
|
78 | - * |
|
79 | - * @param string $ETag |
|
80 | - * @param string $content |
|
81 | - * @param bool [$allowUnstable] Allow unstable releases |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function fetch($ETag, $content, $allowUnstable = false) { |
|
86 | - /** @var mixed[] $response */ |
|
87 | - $response = parent::fetch($ETag, $content); |
|
88 | - |
|
89 | - if (empty($response)) { |
|
90 | - return []; |
|
91 | - } |
|
92 | - |
|
93 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
94 | - $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
95 | - |
|
96 | - foreach ($response['data'] as $dataKey => $app) { |
|
97 | - $releases = []; |
|
98 | - |
|
99 | - // Filter all compatible releases |
|
100 | - foreach ($app['releases'] as $release) { |
|
101 | - // Exclude all nightly and pre-releases if required |
|
102 | - if (($allowNightly || $release['isNightly'] === false) |
|
103 | - && ($allowPreReleases || strpos($release['version'], '-') === false)) { |
|
104 | - // Exclude all versions not compatible with the current version |
|
105 | - try { |
|
106 | - $versionParser = new VersionParser(); |
|
107 | - $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
108 | - $ncVersion = $this->getVersion(); |
|
109 | - $minServerVersion = $serverVersion->getMinimumVersion(); |
|
110 | - $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
111 | - $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
112 | - $maxFulfilled = $maxServerVersion !== '' && |
|
113 | - $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
114 | - $isPhpCompatible = true; |
|
115 | - if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
116 | - $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
117 | - $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
118 | - $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
119 | - $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
120 | - PHP_VERSION, |
|
121 | - $minPhpVersion, |
|
122 | - '>=' |
|
123 | - ); |
|
124 | - $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
125 | - PHP_VERSION, |
|
126 | - $maxPhpVersion, |
|
127 | - '<=' |
|
128 | - ); |
|
129 | - |
|
130 | - $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
131 | - } |
|
132 | - if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
133 | - $releases[] = $release; |
|
134 | - } |
|
135 | - } catch (\InvalidArgumentException $e) { |
|
136 | - $this->logger->warning($e->getMessage(), [ |
|
137 | - 'exception' => $e, |
|
138 | - ]); |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - if (empty($releases)) { |
|
144 | - // Remove apps that don't have a matching release |
|
145 | - $response['data'][$dataKey] = []; |
|
146 | - continue; |
|
147 | - } |
|
148 | - |
|
149 | - // Get the highest version |
|
150 | - $versions = []; |
|
151 | - foreach ($releases as $release) { |
|
152 | - $versions[] = $release['version']; |
|
153 | - } |
|
154 | - usort($versions, function ($version1, $version2) { |
|
155 | - return version_compare($version1, $version2); |
|
156 | - }); |
|
157 | - $versions = array_reverse($versions); |
|
158 | - if (isset($versions[0])) { |
|
159 | - $highestVersion = $versions[0]; |
|
160 | - foreach ($releases as $release) { |
|
161 | - if ((string)$release['version'] === (string)$highestVersion) { |
|
162 | - $response['data'][$dataKey]['releases'] = [$release]; |
|
163 | - break; |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - $response['data'] = array_values(array_filter($response['data'])); |
|
170 | - return $response; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $version |
|
175 | - * @param string $fileName |
|
176 | - * @param bool $ignoreMaxVersion |
|
177 | - */ |
|
178 | - public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
179 | - parent::setVersion($version); |
|
180 | - $this->fileName = $fileName; |
|
181 | - $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - public function get($allowUnstable = false) { |
|
186 | - $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
187 | - |
|
188 | - $apps = parent::get($allowPreReleases); |
|
189 | - $allowList = $this->config->getSystemValue('appsallowlist'); |
|
190 | - |
|
191 | - // If the admin specified a allow list, filter apps from the appstore |
|
192 | - if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
193 | - return array_filter($apps, function ($app) use ($allowList) { |
|
194 | - return in_array($app['id'], $allowList); |
|
195 | - }); |
|
196 | - } |
|
197 | - |
|
198 | - return $apps; |
|
199 | - } |
|
43 | + /** @var CompareVersion */ |
|
44 | + private $compareVersion; |
|
45 | + |
|
46 | + /** @var IRegistry */ |
|
47 | + protected $registry; |
|
48 | + |
|
49 | + /** @var bool */ |
|
50 | + private $ignoreMaxVersion; |
|
51 | + |
|
52 | + public function __construct(Factory $appDataFactory, |
|
53 | + IClientService $clientService, |
|
54 | + ITimeFactory $timeFactory, |
|
55 | + IConfig $config, |
|
56 | + CompareVersion $compareVersion, |
|
57 | + LoggerInterface $logger, |
|
58 | + IRegistry $registry) { |
|
59 | + parent::__construct( |
|
60 | + $appDataFactory, |
|
61 | + $clientService, |
|
62 | + $timeFactory, |
|
63 | + $config, |
|
64 | + $logger, |
|
65 | + $registry |
|
66 | + ); |
|
67 | + |
|
68 | + $this->compareVersion = $compareVersion; |
|
69 | + $this->registry = $registry; |
|
70 | + |
|
71 | + $this->fileName = 'apps.json'; |
|
72 | + $this->endpointName = 'apps.json'; |
|
73 | + $this->ignoreMaxVersion = true; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Only returns the latest compatible app release in the releases array |
|
78 | + * |
|
79 | + * @param string $ETag |
|
80 | + * @param string $content |
|
81 | + * @param bool [$allowUnstable] Allow unstable releases |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function fetch($ETag, $content, $allowUnstable = false) { |
|
86 | + /** @var mixed[] $response */ |
|
87 | + $response = parent::fetch($ETag, $content); |
|
88 | + |
|
89 | + if (empty($response)) { |
|
90 | + return []; |
|
91 | + } |
|
92 | + |
|
93 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
94 | + $allowNightly = $allowUnstable || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
95 | + |
|
96 | + foreach ($response['data'] as $dataKey => $app) { |
|
97 | + $releases = []; |
|
98 | + |
|
99 | + // Filter all compatible releases |
|
100 | + foreach ($app['releases'] as $release) { |
|
101 | + // Exclude all nightly and pre-releases if required |
|
102 | + if (($allowNightly || $release['isNightly'] === false) |
|
103 | + && ($allowPreReleases || strpos($release['version'], '-') === false)) { |
|
104 | + // Exclude all versions not compatible with the current version |
|
105 | + try { |
|
106 | + $versionParser = new VersionParser(); |
|
107 | + $serverVersion = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
|
108 | + $ncVersion = $this->getVersion(); |
|
109 | + $minServerVersion = $serverVersion->getMinimumVersion(); |
|
110 | + $maxServerVersion = $serverVersion->getMaximumVersion(); |
|
111 | + $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $minServerVersion, '>='); |
|
112 | + $maxFulfilled = $maxServerVersion !== '' && |
|
113 | + $this->compareVersion->isCompatible($ncVersion, $maxServerVersion, '<='); |
|
114 | + $isPhpCompatible = true; |
|
115 | + if (($release['rawPhpVersionSpec'] ?? '*') !== '*') { |
|
116 | + $phpVersion = $versionParser->getVersion($release['rawPhpVersionSpec']); |
|
117 | + $minPhpVersion = $phpVersion->getMinimumVersion(); |
|
118 | + $maxPhpVersion = $phpVersion->getMaximumVersion(); |
|
119 | + $minPhpFulfilled = $minPhpVersion === '' || $this->compareVersion->isCompatible( |
|
120 | + PHP_VERSION, |
|
121 | + $minPhpVersion, |
|
122 | + '>=' |
|
123 | + ); |
|
124 | + $maxPhpFulfilled = $maxPhpVersion === '' || $this->compareVersion->isCompatible( |
|
125 | + PHP_VERSION, |
|
126 | + $maxPhpVersion, |
|
127 | + '<=' |
|
128 | + ); |
|
129 | + |
|
130 | + $isPhpCompatible = $minPhpFulfilled && $maxPhpFulfilled; |
|
131 | + } |
|
132 | + if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { |
|
133 | + $releases[] = $release; |
|
134 | + } |
|
135 | + } catch (\InvalidArgumentException $e) { |
|
136 | + $this->logger->warning($e->getMessage(), [ |
|
137 | + 'exception' => $e, |
|
138 | + ]); |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + if (empty($releases)) { |
|
144 | + // Remove apps that don't have a matching release |
|
145 | + $response['data'][$dataKey] = []; |
|
146 | + continue; |
|
147 | + } |
|
148 | + |
|
149 | + // Get the highest version |
|
150 | + $versions = []; |
|
151 | + foreach ($releases as $release) { |
|
152 | + $versions[] = $release['version']; |
|
153 | + } |
|
154 | + usort($versions, function ($version1, $version2) { |
|
155 | + return version_compare($version1, $version2); |
|
156 | + }); |
|
157 | + $versions = array_reverse($versions); |
|
158 | + if (isset($versions[0])) { |
|
159 | + $highestVersion = $versions[0]; |
|
160 | + foreach ($releases as $release) { |
|
161 | + if ((string)$release['version'] === (string)$highestVersion) { |
|
162 | + $response['data'][$dataKey]['releases'] = [$release]; |
|
163 | + break; |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + $response['data'] = array_values(array_filter($response['data'])); |
|
170 | + return $response; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $version |
|
175 | + * @param string $fileName |
|
176 | + * @param bool $ignoreMaxVersion |
|
177 | + */ |
|
178 | + public function setVersion(string $version, string $fileName = 'apps.json', bool $ignoreMaxVersion = true) { |
|
179 | + parent::setVersion($version); |
|
180 | + $this->fileName = $fileName; |
|
181 | + $this->ignoreMaxVersion = $ignoreMaxVersion; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + public function get($allowUnstable = false) { |
|
186 | + $allowPreReleases = $allowUnstable || $this->getChannel() === 'beta' || $this->getChannel() === 'daily' || $this->getChannel() === 'git'; |
|
187 | + |
|
188 | + $apps = parent::get($allowPreReleases); |
|
189 | + $allowList = $this->config->getSystemValue('appsallowlist'); |
|
190 | + |
|
191 | + // If the admin specified a allow list, filter apps from the appstore |
|
192 | + if (is_array($allowList) && $this->registry->delegateHasValidSubscription()) { |
|
193 | + return array_filter($apps, function ($app) use ($allowList) { |
|
194 | + return in_array($app['id'], $allowList); |
|
195 | + }); |
|
196 | + } |
|
197 | + |
|
198 | + return $apps; |
|
199 | + } |
|
200 | 200 | } |
@@ -35,69 +35,69 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class Install extends Command { |
38 | - protected function configure() { |
|
39 | - $this |
|
40 | - ->setName('app:install') |
|
41 | - ->setDescription('install an app') |
|
42 | - ->addArgument( |
|
43 | - 'app-id', |
|
44 | - InputArgument::REQUIRED, |
|
45 | - 'install the specified app' |
|
46 | - ) |
|
47 | - ->addOption( |
|
48 | - 'keep-disabled', |
|
49 | - null, |
|
50 | - InputOption::VALUE_NONE, |
|
51 | - 'don\'t enable the app afterwards' |
|
52 | - ) |
|
53 | - ->addOption( |
|
54 | - 'force', |
|
55 | - 'f', |
|
56 | - InputOption::VALUE_NONE, |
|
57 | - 'install the app regardless of the Nextcloud version requirement' |
|
58 | - ) |
|
59 | - ->addOption( |
|
60 | - 'allow-unstable', |
|
61 | - null, |
|
62 | - InputOption::VALUE_NONE, |
|
63 | - 'allow installing an unstable releases' |
|
64 | - ) |
|
65 | - ; |
|
66 | - } |
|
38 | + protected function configure() { |
|
39 | + $this |
|
40 | + ->setName('app:install') |
|
41 | + ->setDescription('install an app') |
|
42 | + ->addArgument( |
|
43 | + 'app-id', |
|
44 | + InputArgument::REQUIRED, |
|
45 | + 'install the specified app' |
|
46 | + ) |
|
47 | + ->addOption( |
|
48 | + 'keep-disabled', |
|
49 | + null, |
|
50 | + InputOption::VALUE_NONE, |
|
51 | + 'don\'t enable the app afterwards' |
|
52 | + ) |
|
53 | + ->addOption( |
|
54 | + 'force', |
|
55 | + 'f', |
|
56 | + InputOption::VALUE_NONE, |
|
57 | + 'install the app regardless of the Nextcloud version requirement' |
|
58 | + ) |
|
59 | + ->addOption( |
|
60 | + 'allow-unstable', |
|
61 | + null, |
|
62 | + InputOption::VALUE_NONE, |
|
63 | + 'allow installing an unstable releases' |
|
64 | + ) |
|
65 | + ; |
|
66 | + } |
|
67 | 67 | |
68 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
69 | - $appId = $input->getArgument('app-id'); |
|
70 | - $forceEnable = (bool) $input->getOption('force'); |
|
68 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
69 | + $appId = $input->getArgument('app-id'); |
|
70 | + $forceEnable = (bool) $input->getOption('force'); |
|
71 | 71 | |
72 | - if (\OC_App::getAppPath($appId)) { |
|
73 | - $output->writeln($appId . ' already installed'); |
|
74 | - return 1; |
|
75 | - } |
|
72 | + if (\OC_App::getAppPath($appId)) { |
|
73 | + $output->writeln($appId . ' already installed'); |
|
74 | + return 1; |
|
75 | + } |
|
76 | 76 | |
77 | - try { |
|
78 | - /** @var Installer $installer */ |
|
79 | - $installer = \OC::$server->query(Installer::class); |
|
80 | - $installer->downloadApp($appId, $input->getOption('allow-unstable')); |
|
81 | - $result = $installer->installApp($appId, $forceEnable); |
|
82 | - } catch (\Exception $e) { |
|
83 | - $output->writeln('Error: ' . $e->getMessage()); |
|
84 | - return 1; |
|
85 | - } |
|
77 | + try { |
|
78 | + /** @var Installer $installer */ |
|
79 | + $installer = \OC::$server->query(Installer::class); |
|
80 | + $installer->downloadApp($appId, $input->getOption('allow-unstable')); |
|
81 | + $result = $installer->installApp($appId, $forceEnable); |
|
82 | + } catch (\Exception $e) { |
|
83 | + $output->writeln('Error: ' . $e->getMessage()); |
|
84 | + return 1; |
|
85 | + } |
|
86 | 86 | |
87 | - if ($result === false) { |
|
88 | - $output->writeln($appId . ' couldn\'t be installed'); |
|
89 | - return 1; |
|
90 | - } |
|
87 | + if ($result === false) { |
|
88 | + $output->writeln($appId . ' couldn\'t be installed'); |
|
89 | + return 1; |
|
90 | + } |
|
91 | 91 | |
92 | - $appVersion = \OC_App::getAppVersion($appId); |
|
93 | - $output->writeln($appId . ' ' . $appVersion . ' installed'); |
|
92 | + $appVersion = \OC_App::getAppVersion($appId); |
|
93 | + $output->writeln($appId . ' ' . $appVersion . ' installed'); |
|
94 | 94 | |
95 | - if (!$input->getOption('keep-disabled')) { |
|
96 | - $appClass = new \OC_App(); |
|
97 | - $appClass->enable($appId); |
|
98 | - $output->writeln($appId . ' enabled'); |
|
99 | - } |
|
95 | + if (!$input->getOption('keep-disabled')) { |
|
96 | + $appClass = new \OC_App(); |
|
97 | + $appClass->enable($appId); |
|
98 | + $output->writeln($appId . ' enabled'); |
|
99 | + } |
|
100 | 100 | |
101 | - return 0; |
|
102 | - } |
|
101 | + return 0; |
|
102 | + } |
|
103 | 103 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $forceEnable = (bool) $input->getOption('force'); |
71 | 71 | |
72 | 72 | if (\OC_App::getAppPath($appId)) { |
73 | - $output->writeln($appId . ' already installed'); |
|
73 | + $output->writeln($appId.' already installed'); |
|
74 | 74 | return 1; |
75 | 75 | } |
76 | 76 | |
@@ -80,22 +80,22 @@ discard block |
||
80 | 80 | $installer->downloadApp($appId, $input->getOption('allow-unstable')); |
81 | 81 | $result = $installer->installApp($appId, $forceEnable); |
82 | 82 | } catch (\Exception $e) { |
83 | - $output->writeln('Error: ' . $e->getMessage()); |
|
83 | + $output->writeln('Error: '.$e->getMessage()); |
|
84 | 84 | return 1; |
85 | 85 | } |
86 | 86 | |
87 | 87 | if ($result === false) { |
88 | - $output->writeln($appId . ' couldn\'t be installed'); |
|
88 | + $output->writeln($appId.' couldn\'t be installed'); |
|
89 | 89 | return 1; |
90 | 90 | } |
91 | 91 | |
92 | 92 | $appVersion = \OC_App::getAppVersion($appId); |
93 | - $output->writeln($appId . ' ' . $appVersion . ' installed'); |
|
93 | + $output->writeln($appId.' '.$appVersion.' installed'); |
|
94 | 94 | |
95 | 95 | if (!$input->getOption('keep-disabled')) { |
96 | 96 | $appClass = new \OC_App(); |
97 | 97 | $appClass->enable($appId); |
98 | - $output->writeln($appId . ' enabled'); |
|
98 | + $output->writeln($appId.' enabled'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return 0; |