Completed
Pull Request — master (#3195)
by Jan-Christoph
12:46
created
settings/Controller/AppSettingsController.php 2 patches
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -47,336 +47,336 @@
 block discarded – undo
47 47
  * @package OC\Settings\Controller
48 48
  */
49 49
 class AppSettingsController extends Controller {
50
-	const CAT_ENABLED = 0;
51
-	const CAT_DISABLED = 1;
52
-	const CAT_ALL_INSTALLED = 2;
53
-
54
-	/** @var \OCP\IL10N */
55
-	private $l10n;
56
-	/** @var IConfig */
57
-	private $config;
58
-	/** @var INavigationManager */
59
-	private $navigationManager;
60
-	/** @var IAppManager */
61
-	private $appManager;
62
-	/** @var CategoryFetcher */
63
-	private $categoryFetcher;
64
-	/** @var AppFetcher */
65
-	private $appFetcher;
66
-	/** @var IFactory */
67
-	private $l10nFactory;
68
-
69
-	/**
70
-	 * @param string $appName
71
-	 * @param IRequest $request
72
-	 * @param IL10N $l10n
73
-	 * @param IConfig $config
74
-	 * @param INavigationManager $navigationManager
75
-	 * @param IAppManager $appManager
76
-	 * @param CategoryFetcher $categoryFetcher
77
-	 * @param AppFetcher $appFetcher
78
-	 * @param IFactory $l10nFactory
79
-	 */
80
-	public function __construct($appName,
81
-								IRequest $request,
82
-								IL10N $l10n,
83
-								IConfig $config,
84
-								INavigationManager $navigationManager,
85
-								IAppManager $appManager,
86
-								CategoryFetcher $categoryFetcher,
87
-								AppFetcher $appFetcher,
88
-								IFactory $l10nFactory) {
89
-		parent::__construct($appName, $request);
90
-		$this->l10n = $l10n;
91
-		$this->config = $config;
92
-		$this->navigationManager = $navigationManager;
93
-		$this->appManager = $appManager;
94
-		$this->categoryFetcher = $categoryFetcher;
95
-		$this->appFetcher = $appFetcher;
96
-		$this->l10nFactory = $l10nFactory;
97
-	}
98
-
99
-	/**
100
-	 * @NoCSRFRequired
101
-	 *
102
-	 * @param string $category
103
-	 * @return TemplateResponse
104
-	 */
105
-	public function viewApps($category = '') {
106
-		if ($category === '') {
107
-			$category = 'installed';
108
-		}
109
-
110
-		$params = [];
111
-		$params['category'] = $category;
112
-		$params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
113
-		$this->navigationManager->setActiveEntry('core_apps');
114
-
115
-		$templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user');
116
-		$policy = new ContentSecurityPolicy();
117
-		$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
118
-		$templateResponse->setContentSecurityPolicy($policy);
119
-
120
-		return $templateResponse;
121
-	}
122
-
123
-	/**
124
-	 * Get all available categories
125
-	 *
126
-	 * @return JSONResponse
127
-	 */
128
-	public function listCategories() {
129
-		$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
130
-
131
-		$formattedCategories = [
132
-			['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')],
133
-			['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')],
134
-			['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')],
135
-		];
136
-		$categories = $this->categoryFetcher->get();
137
-		foreach($categories as $category) {
138
-			$formattedCategories[] = [
139
-				'id' => $category['id'],
140
-				'ident' => $category['id'],
141
-				'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'],
142
-			];
143
-		}
144
-
145
-		return new JSONResponse($formattedCategories);
146
-	}
147
-
148
-	/**
149
-	 * Get all apps for a category
150
-	 *
151
-	 * @param string $requestedCategory
152
-	 * @return array
153
-	 */
154
-	private function getAppsForCategory($requestedCategory) {
155
-		$versionParser = new VersionParser();
156
-		$formattedApps = [];
157
-		$apps = $this->appFetcher->get();
158
-		foreach($apps as $app) {
159
-			if (isset($app['isFeatured'])) {
160
-				$app['featured'] = $app['isFeatured'];
161
-			}
162
-
163
-			// Skip all apps not in the requested category
164
-			$isInCategory = false;
165
-			foreach($app['categories'] as $category) {
166
-				if($category === $requestedCategory) {
167
-					$isInCategory = true;
168
-				}
169
-			}
170
-			if(!$isInCategory) {
171
-				continue;
172
-			}
173
-
174
-			$nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
175
-			$nextCloudVersionDependencies = [];
176
-			if($nextCloudVersion->getMinimumVersion() !== '') {
177
-				$nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
178
-			}
179
-			if($nextCloudVersion->getMaximumVersion() !== '') {
180
-				$nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
181
-			}
182
-			$phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
183
-			$existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false;
184
-			$phpDependencies = [];
185
-			if($phpVersion->getMinimumVersion() !== '') {
186
-				$phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
187
-			}
188
-			if($phpVersion->getMaximumVersion() !== '') {
189
-				$phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
190
-			}
191
-			if(isset($app['releases'][0]['minIntSize'])) {
192
-				$phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
193
-			}
194
-			$authors = '';
195
-			foreach($app['authors'] as $key => $author) {
196
-				$authors .= $author['name'];
197
-				if($key !== count($app['authors']) - 1) {
198
-					$authors .= ', ';
199
-				}
200
-			}
201
-
202
-			$currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
203
-			$enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
204
-			$groups = null;
205
-			if($enabledValue !== 'no' && $enabledValue !== 'yes') {
206
-				$groups = $enabledValue;
207
-			}
208
-
209
-			$currentVersion = '';
210
-			if($this->appManager->isInstalled($app['id'])) {
211
-				$currentVersion = \OC_App::getAppVersion($app['id']);
212
-			} else {
213
-				$currentLanguage = $app['releases'][0]['version'];
214
-			}
215
-
216
-			$formattedApps[] = [
217
-				'id' => $app['id'],
218
-				'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'],
219
-				'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'],
220
-				'license' => $app['releases'][0]['licenses'],
221
-				'author' => $authors,
222
-				'shipped' => false,
223
-				'version' => $currentVersion,
224
-				'default_enable' => '',
225
-				'types' => [],
226
-				'documentation' => [
227
-					'admin' => $app['adminDocs'],
228
-					'user' => $app['userDocs'],
229
-					'developer' => $app['developerDocs']
230
-				],
231
-				'website' => $app['website'],
232
-				'bugs' => $app['issueTracker'],
233
-				'detailpage' => $app['website'],
234
-				'dependencies' => array_merge(
235
-					$nextCloudVersionDependencies,
236
-					$phpDependencies
237
-				),
238
-				'level' => ($app['featured'] === true) ? 200 : 100,
239
-				'missingMaxOwnCloudVersion' => false,
240
-				'missingMinOwnCloudVersion' => false,
241
-				'canInstall' => true,
242
-				'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
243
-				'score' => $app['ratingOverall'],
244
-				'ratingNumOverall' => $app['ratingNumOverall'],
245
-				'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false,
246
-				'removable' => $existsLocally,
247
-				'active' => $this->appManager->isEnabledForUser($app['id']),
248
-				'needsDownload' => !$existsLocally,
249
-				'groups' => $groups,
250
-				'fromAppStore' => true,
251
-			];
252
-
253
-
254
-			$appFetcher = \OC::$server->getAppFetcher();
255
-			$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
256
-			if($newVersion && $this->appManager->isInstalled($app['id'])) {
257
-				$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
258
-			}
259
-		}
260
-
261
-		return $formattedApps;
262
-	}
263
-
264
-	/**
265
-	 * Get all available apps in a category
266
-	 *
267
-	 * @param string $category
268
-	 * @return JSONResponse
269
-	 */
270
-	public function listApps($category = '') {
271
-		$appClass = new \OC_App();
272
-
273
-		switch ($category) {
274
-			// installed apps
275
-			case 'installed':
276
-				$apps = $appClass->listAllApps();
277
-
278
-				foreach($apps as $key => $app) {
279
-					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
280
-					$apps[$key]['update'] = $newVersion;
281
-				}
282
-
283
-				usort($apps, function ($a, $b) {
284
-					$a = (string)$a['name'];
285
-					$b = (string)$b['name'];
286
-					if ($a === $b) {
287
-						return 0;
288
-					}
289
-					return ($a < $b) ? -1 : 1;
290
-				});
291
-				break;
292
-			// enabled apps
293
-			case 'enabled':
294
-				$apps = $appClass->listAllApps();
295
-				$apps = array_filter($apps, function ($app) {
296
-					return $app['active'];
297
-				});
298
-
299
-				foreach($apps as $key => $app) {
300
-					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
301
-					$apps[$key]['update'] = $newVersion;
302
-				}
303
-
304
-				usort($apps, function ($a, $b) {
305
-					$a = (string)$a['name'];
306
-					$b = (string)$b['name'];
307
-					if ($a === $b) {
308
-						return 0;
309
-					}
310
-					return ($a < $b) ? -1 : 1;
311
-				});
312
-				break;
313
-			// disabled  apps
314
-			case 'disabled':
315
-				$apps = $appClass->listAllApps();
316
-				$apps = array_filter($apps, function ($app) {
317
-					return !$app['active'];
318
-				});
319
-
320
-				$apps = array_map(function ($app) {
321
-					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
322
-					if ($newVersion !== false) {
323
-						$app['update'] = $newVersion;
324
-					}
325
-					return $app;
326
-				}, $apps);
327
-
328
-				usort($apps, function ($a, $b) {
329
-					$a = (string)$a['name'];
330
-					$b = (string)$b['name'];
331
-					if ($a === $b) {
332
-						return 0;
333
-					}
334
-					return ($a < $b) ? -1 : 1;
335
-				});
336
-				break;
337
-			default:
338
-				$apps = $this->getAppsForCategory($category);
339
-
340
-				// sort by score
341
-				usort($apps, function ($a, $b) {
342
-					$a = (int)$a['score'];
343
-					$b = (int)$b['score'];
344
-					if ($a === $b) {
345
-						return 0;
346
-					}
347
-					return ($a > $b) ? -1 : 1;
348
-				});
349
-				break;
350
-		}
351
-
352
-		// fix groups to be an array
353
-		$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
354
-		$apps = array_map(function($app) use ($dependencyAnalyzer) {
355
-
356
-			// fix groups
357
-			$groups = array();
358
-			if (is_string($app['groups'])) {
359
-				$groups = json_decode($app['groups']);
360
-			}
361
-			$app['groups'] = $groups;
362
-			$app['canUnInstall'] = !$app['active'] && $app['removable'];
363
-
364
-			// fix licence vs license
365
-			if (isset($app['license']) && !isset($app['licence'])) {
366
-				$app['licence'] = $app['license'];
367
-			}
368
-
369
-			// analyse dependencies
370
-			$missing = $dependencyAnalyzer->analyze($app);
371
-			$app['canInstall'] = empty($missing);
372
-			$app['missingDependencies'] = $missing;
373
-
374
-			$app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']);
375
-			$app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']);
376
-
377
-			return $app;
378
-		}, $apps);
379
-
380
-		return new JSONResponse(['apps' => $apps, 'status' => 'success']);
381
-	}
50
+    const CAT_ENABLED = 0;
51
+    const CAT_DISABLED = 1;
52
+    const CAT_ALL_INSTALLED = 2;
53
+
54
+    /** @var \OCP\IL10N */
55
+    private $l10n;
56
+    /** @var IConfig */
57
+    private $config;
58
+    /** @var INavigationManager */
59
+    private $navigationManager;
60
+    /** @var IAppManager */
61
+    private $appManager;
62
+    /** @var CategoryFetcher */
63
+    private $categoryFetcher;
64
+    /** @var AppFetcher */
65
+    private $appFetcher;
66
+    /** @var IFactory */
67
+    private $l10nFactory;
68
+
69
+    /**
70
+     * @param string $appName
71
+     * @param IRequest $request
72
+     * @param IL10N $l10n
73
+     * @param IConfig $config
74
+     * @param INavigationManager $navigationManager
75
+     * @param IAppManager $appManager
76
+     * @param CategoryFetcher $categoryFetcher
77
+     * @param AppFetcher $appFetcher
78
+     * @param IFactory $l10nFactory
79
+     */
80
+    public function __construct($appName,
81
+                                IRequest $request,
82
+                                IL10N $l10n,
83
+                                IConfig $config,
84
+                                INavigationManager $navigationManager,
85
+                                IAppManager $appManager,
86
+                                CategoryFetcher $categoryFetcher,
87
+                                AppFetcher $appFetcher,
88
+                                IFactory $l10nFactory) {
89
+        parent::__construct($appName, $request);
90
+        $this->l10n = $l10n;
91
+        $this->config = $config;
92
+        $this->navigationManager = $navigationManager;
93
+        $this->appManager = $appManager;
94
+        $this->categoryFetcher = $categoryFetcher;
95
+        $this->appFetcher = $appFetcher;
96
+        $this->l10nFactory = $l10nFactory;
97
+    }
98
+
99
+    /**
100
+     * @NoCSRFRequired
101
+     *
102
+     * @param string $category
103
+     * @return TemplateResponse
104
+     */
105
+    public function viewApps($category = '') {
106
+        if ($category === '') {
107
+            $category = 'installed';
108
+        }
109
+
110
+        $params = [];
111
+        $params['category'] = $category;
112
+        $params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
113
+        $this->navigationManager->setActiveEntry('core_apps');
114
+
115
+        $templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user');
116
+        $policy = new ContentSecurityPolicy();
117
+        $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
118
+        $templateResponse->setContentSecurityPolicy($policy);
119
+
120
+        return $templateResponse;
121
+    }
122
+
123
+    /**
124
+     * Get all available categories
125
+     *
126
+     * @return JSONResponse
127
+     */
128
+    public function listCategories() {
129
+        $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
130
+
131
+        $formattedCategories = [
132
+            ['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')],
133
+            ['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')],
134
+            ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')],
135
+        ];
136
+        $categories = $this->categoryFetcher->get();
137
+        foreach($categories as $category) {
138
+            $formattedCategories[] = [
139
+                'id' => $category['id'],
140
+                'ident' => $category['id'],
141
+                'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'],
142
+            ];
143
+        }
144
+
145
+        return new JSONResponse($formattedCategories);
146
+    }
147
+
148
+    /**
149
+     * Get all apps for a category
150
+     *
151
+     * @param string $requestedCategory
152
+     * @return array
153
+     */
154
+    private function getAppsForCategory($requestedCategory) {
155
+        $versionParser = new VersionParser();
156
+        $formattedApps = [];
157
+        $apps = $this->appFetcher->get();
158
+        foreach($apps as $app) {
159
+            if (isset($app['isFeatured'])) {
160
+                $app['featured'] = $app['isFeatured'];
161
+            }
162
+
163
+            // Skip all apps not in the requested category
164
+            $isInCategory = false;
165
+            foreach($app['categories'] as $category) {
166
+                if($category === $requestedCategory) {
167
+                    $isInCategory = true;
168
+                }
169
+            }
170
+            if(!$isInCategory) {
171
+                continue;
172
+            }
173
+
174
+            $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
175
+            $nextCloudVersionDependencies = [];
176
+            if($nextCloudVersion->getMinimumVersion() !== '') {
177
+                $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
178
+            }
179
+            if($nextCloudVersion->getMaximumVersion() !== '') {
180
+                $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
181
+            }
182
+            $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
183
+            $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false;
184
+            $phpDependencies = [];
185
+            if($phpVersion->getMinimumVersion() !== '') {
186
+                $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
187
+            }
188
+            if($phpVersion->getMaximumVersion() !== '') {
189
+                $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
190
+            }
191
+            if(isset($app['releases'][0]['minIntSize'])) {
192
+                $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
193
+            }
194
+            $authors = '';
195
+            foreach($app['authors'] as $key => $author) {
196
+                $authors .= $author['name'];
197
+                if($key !== count($app['authors']) - 1) {
198
+                    $authors .= ', ';
199
+                }
200
+            }
201
+
202
+            $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
203
+            $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
204
+            $groups = null;
205
+            if($enabledValue !== 'no' && $enabledValue !== 'yes') {
206
+                $groups = $enabledValue;
207
+            }
208
+
209
+            $currentVersion = '';
210
+            if($this->appManager->isInstalled($app['id'])) {
211
+                $currentVersion = \OC_App::getAppVersion($app['id']);
212
+            } else {
213
+                $currentLanguage = $app['releases'][0]['version'];
214
+            }
215
+
216
+            $formattedApps[] = [
217
+                'id' => $app['id'],
218
+                'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'],
219
+                'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'],
220
+                'license' => $app['releases'][0]['licenses'],
221
+                'author' => $authors,
222
+                'shipped' => false,
223
+                'version' => $currentVersion,
224
+                'default_enable' => '',
225
+                'types' => [],
226
+                'documentation' => [
227
+                    'admin' => $app['adminDocs'],
228
+                    'user' => $app['userDocs'],
229
+                    'developer' => $app['developerDocs']
230
+                ],
231
+                'website' => $app['website'],
232
+                'bugs' => $app['issueTracker'],
233
+                'detailpage' => $app['website'],
234
+                'dependencies' => array_merge(
235
+                    $nextCloudVersionDependencies,
236
+                    $phpDependencies
237
+                ),
238
+                'level' => ($app['featured'] === true) ? 200 : 100,
239
+                'missingMaxOwnCloudVersion' => false,
240
+                'missingMinOwnCloudVersion' => false,
241
+                'canInstall' => true,
242
+                'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
243
+                'score' => $app['ratingOverall'],
244
+                'ratingNumOverall' => $app['ratingNumOverall'],
245
+                'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5 ? true : false,
246
+                'removable' => $existsLocally,
247
+                'active' => $this->appManager->isEnabledForUser($app['id']),
248
+                'needsDownload' => !$existsLocally,
249
+                'groups' => $groups,
250
+                'fromAppStore' => true,
251
+            ];
252
+
253
+
254
+            $appFetcher = \OC::$server->getAppFetcher();
255
+            $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
256
+            if($newVersion && $this->appManager->isInstalled($app['id'])) {
257
+                $formattedApps[count($formattedApps)-1]['update'] = $newVersion;
258
+            }
259
+        }
260
+
261
+        return $formattedApps;
262
+    }
263
+
264
+    /**
265
+     * Get all available apps in a category
266
+     *
267
+     * @param string $category
268
+     * @return JSONResponse
269
+     */
270
+    public function listApps($category = '') {
271
+        $appClass = new \OC_App();
272
+
273
+        switch ($category) {
274
+            // installed apps
275
+            case 'installed':
276
+                $apps = $appClass->listAllApps();
277
+
278
+                foreach($apps as $key => $app) {
279
+                    $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
280
+                    $apps[$key]['update'] = $newVersion;
281
+                }
282
+
283
+                usort($apps, function ($a, $b) {
284
+                    $a = (string)$a['name'];
285
+                    $b = (string)$b['name'];
286
+                    if ($a === $b) {
287
+                        return 0;
288
+                    }
289
+                    return ($a < $b) ? -1 : 1;
290
+                });
291
+                break;
292
+            // enabled apps
293
+            case 'enabled':
294
+                $apps = $appClass->listAllApps();
295
+                $apps = array_filter($apps, function ($app) {
296
+                    return $app['active'];
297
+                });
298
+
299
+                foreach($apps as $key => $app) {
300
+                    $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
301
+                    $apps[$key]['update'] = $newVersion;
302
+                }
303
+
304
+                usort($apps, function ($a, $b) {
305
+                    $a = (string)$a['name'];
306
+                    $b = (string)$b['name'];
307
+                    if ($a === $b) {
308
+                        return 0;
309
+                    }
310
+                    return ($a < $b) ? -1 : 1;
311
+                });
312
+                break;
313
+            // disabled  apps
314
+            case 'disabled':
315
+                $apps = $appClass->listAllApps();
316
+                $apps = array_filter($apps, function ($app) {
317
+                    return !$app['active'];
318
+                });
319
+
320
+                $apps = array_map(function ($app) {
321
+                    $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
322
+                    if ($newVersion !== false) {
323
+                        $app['update'] = $newVersion;
324
+                    }
325
+                    return $app;
326
+                }, $apps);
327
+
328
+                usort($apps, function ($a, $b) {
329
+                    $a = (string)$a['name'];
330
+                    $b = (string)$b['name'];
331
+                    if ($a === $b) {
332
+                        return 0;
333
+                    }
334
+                    return ($a < $b) ? -1 : 1;
335
+                });
336
+                break;
337
+            default:
338
+                $apps = $this->getAppsForCategory($category);
339
+
340
+                // sort by score
341
+                usort($apps, function ($a, $b) {
342
+                    $a = (int)$a['score'];
343
+                    $b = (int)$b['score'];
344
+                    if ($a === $b) {
345
+                        return 0;
346
+                    }
347
+                    return ($a > $b) ? -1 : 1;
348
+                });
349
+                break;
350
+        }
351
+
352
+        // fix groups to be an array
353
+        $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
354
+        $apps = array_map(function($app) use ($dependencyAnalyzer) {
355
+
356
+            // fix groups
357
+            $groups = array();
358
+            if (is_string($app['groups'])) {
359
+                $groups = json_decode($app['groups']);
360
+            }
361
+            $app['groups'] = $groups;
362
+            $app['canUnInstall'] = !$app['active'] && $app['removable'];
363
+
364
+            // fix licence vs license
365
+            if (isset($app['license']) && !isset($app['licence'])) {
366
+                $app['licence'] = $app['license'];
367
+            }
368
+
369
+            // analyse dependencies
370
+            $missing = $dependencyAnalyzer->analyze($app);
371
+            $app['canInstall'] = empty($missing);
372
+            $app['missingDependencies'] = $missing;
373
+
374
+            $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['min-version']);
375
+            $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['nextcloud']['@attributes']['max-version']);
376
+
377
+            return $app;
378
+        }, $apps);
379
+
380
+        return new JSONResponse(['apps' => $apps, 'status' => 'success']);
381
+    }
382 382
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
130 130
 
131 131
 		$formattedCategories = [
132
-			['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string)$this->l10n->t('Your apps')],
133
-			['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled apps')],
134
-			['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Disabled apps')],
132
+			['id' => self::CAT_ALL_INSTALLED, 'ident' => 'installed', 'displayName' => (string) $this->l10n->t('Your apps')],
133
+			['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string) $this->l10n->t('Enabled apps')],
134
+			['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string) $this->l10n->t('Disabled apps')],
135 135
 		];
136 136
 		$categories = $this->categoryFetcher->get();
137
-		foreach($categories as $category) {
137
+		foreach ($categories as $category) {
138 138
 			$formattedCategories[] = [
139 139
 				'id' => $category['id'],
140 140
 				'ident' => $category['id'],
@@ -155,46 +155,46 @@  discard block
 block discarded – undo
155 155
 		$versionParser = new VersionParser();
156 156
 		$formattedApps = [];
157 157
 		$apps = $this->appFetcher->get();
158
-		foreach($apps as $app) {
158
+		foreach ($apps as $app) {
159 159
 			if (isset($app['isFeatured'])) {
160 160
 				$app['featured'] = $app['isFeatured'];
161 161
 			}
162 162
 
163 163
 			// Skip all apps not in the requested category
164 164
 			$isInCategory = false;
165
-			foreach($app['categories'] as $category) {
166
-				if($category === $requestedCategory) {
165
+			foreach ($app['categories'] as $category) {
166
+				if ($category === $requestedCategory) {
167 167
 					$isInCategory = true;
168 168
 				}
169 169
 			}
170
-			if(!$isInCategory) {
170
+			if (!$isInCategory) {
171 171
 				continue;
172 172
 			}
173 173
 
174 174
 			$nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
175 175
 			$nextCloudVersionDependencies = [];
176
-			if($nextCloudVersion->getMinimumVersion() !== '') {
176
+			if ($nextCloudVersion->getMinimumVersion() !== '') {
177 177
 				$nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
178 178
 			}
179
-			if($nextCloudVersion->getMaximumVersion() !== '') {
179
+			if ($nextCloudVersion->getMaximumVersion() !== '') {
180 180
 				$nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
181 181
 			}
182 182
 			$phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
183 183
 			$existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false;
184 184
 			$phpDependencies = [];
185
-			if($phpVersion->getMinimumVersion() !== '') {
185
+			if ($phpVersion->getMinimumVersion() !== '') {
186 186
 				$phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
187 187
 			}
188
-			if($phpVersion->getMaximumVersion() !== '') {
188
+			if ($phpVersion->getMaximumVersion() !== '') {
189 189
 				$phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
190 190
 			}
191
-			if(isset($app['releases'][0]['minIntSize'])) {
191
+			if (isset($app['releases'][0]['minIntSize'])) {
192 192
 				$phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
193 193
 			}
194 194
 			$authors = '';
195
-			foreach($app['authors'] as $key => $author) {
195
+			foreach ($app['authors'] as $key => $author) {
196 196
 				$authors .= $author['name'];
197
-				if($key !== count($app['authors']) - 1) {
197
+				if ($key !== count($app['authors']) - 1) {
198 198
 					$authors .= ', ';
199 199
 				}
200 200
 			}
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
 			$currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
203 203
 			$enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
204 204
 			$groups = null;
205
-			if($enabledValue !== 'no' && $enabledValue !== 'yes') {
205
+			if ($enabledValue !== 'no' && $enabledValue !== 'yes') {
206 206
 				$groups = $enabledValue;
207 207
 			}
208 208
 
209 209
 			$currentVersion = '';
210
-			if($this->appManager->isInstalled($app['id'])) {
210
+			if ($this->appManager->isInstalled($app['id'])) {
211 211
 				$currentVersion = \OC_App::getAppVersion($app['id']);
212 212
 			} else {
213 213
 				$currentLanguage = $app['releases'][0]['version'];
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 
254 254
 			$appFetcher = \OC::$server->getAppFetcher();
255 255
 			$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
256
-			if($newVersion && $this->appManager->isInstalled($app['id'])) {
257
-				$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
256
+			if ($newVersion && $this->appManager->isInstalled($app['id'])) {
257
+				$formattedApps[count($formattedApps) - 1]['update'] = $newVersion;
258 258
 			}
259 259
 		}
260 260
 
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
 			case 'installed':
276 276
 				$apps = $appClass->listAllApps();
277 277
 
278
-				foreach($apps as $key => $app) {
278
+				foreach ($apps as $key => $app) {
279 279
 					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
280 280
 					$apps[$key]['update'] = $newVersion;
281 281
 				}
282 282
 
283
-				usort($apps, function ($a, $b) {
284
-					$a = (string)$a['name'];
285
-					$b = (string)$b['name'];
283
+				usort($apps, function($a, $b) {
284
+					$a = (string) $a['name'];
285
+					$b = (string) $b['name'];
286 286
 					if ($a === $b) {
287 287
 						return 0;
288 288
 					}
@@ -292,18 +292,18 @@  discard block
 block discarded – undo
292 292
 			// enabled apps
293 293
 			case 'enabled':
294 294
 				$apps = $appClass->listAllApps();
295
-				$apps = array_filter($apps, function ($app) {
295
+				$apps = array_filter($apps, function($app) {
296 296
 					return $app['active'];
297 297
 				});
298 298
 
299
-				foreach($apps as $key => $app) {
299
+				foreach ($apps as $key => $app) {
300 300
 					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
301 301
 					$apps[$key]['update'] = $newVersion;
302 302
 				}
303 303
 
304
-				usort($apps, function ($a, $b) {
305
-					$a = (string)$a['name'];
306
-					$b = (string)$b['name'];
304
+				usort($apps, function($a, $b) {
305
+					$a = (string) $a['name'];
306
+					$b = (string) $b['name'];
307 307
 					if ($a === $b) {
308 308
 						return 0;
309 309
 					}
@@ -313,11 +313,11 @@  discard block
 block discarded – undo
313 313
 			// disabled  apps
314 314
 			case 'disabled':
315 315
 				$apps = $appClass->listAllApps();
316
-				$apps = array_filter($apps, function ($app) {
316
+				$apps = array_filter($apps, function($app) {
317 317
 					return !$app['active'];
318 318
 				});
319 319
 
320
-				$apps = array_map(function ($app) {
320
+				$apps = array_map(function($app) {
321 321
 					$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
322 322
 					if ($newVersion !== false) {
323 323
 						$app['update'] = $newVersion;
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 					return $app;
326 326
 				}, $apps);
327 327
 
328
-				usort($apps, function ($a, $b) {
329
-					$a = (string)$a['name'];
330
-					$b = (string)$b['name'];
328
+				usort($apps, function($a, $b) {
329
+					$a = (string) $a['name'];
330
+					$b = (string) $b['name'];
331 331
 					if ($a === $b) {
332 332
 						return 0;
333 333
 					}
@@ -338,9 +338,9 @@  discard block
 block discarded – undo
338 338
 				$apps = $this->getAppsForCategory($category);
339 339
 
340 340
 				// sort by score
341
-				usort($apps, function ($a, $b) {
342
-					$a = (int)$a['score'];
343
-					$b = (int)$b['score'];
341
+				usort($apps, function($a, $b) {
342
+					$a = (int) $a['score'];
343
+					$b = (int) $b['score'];
344 344
 					if ($a === $b) {
345 345
 						return 0;
346 346
 					}
Please login to merge, or discard this patch.
settings/templates/apps.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,9 +23,9 @@  discard block
 block discarded – undo
23 23
 	</li>
24 24
 {{/each}}
25 25
 
26
-<?php if($_['appstoreEnabled']): ?>
26
+<?php if ($_['appstoreEnabled']): ?>
27 27
 	<li>
28
-		<a class="app-external" target="_blank" rel="noreferrer" href="https://docs.nextcloud.org/server/12/developer_manual/"><?php p($l->t('Developer documentation'));?> ↗</a>
28
+		<a class="app-external" target="_blank" rel="noreferrer" href="https://docs.nextcloud.org/server/12/developer_manual/"><?php p($l->t('Developer documentation')); ?> ↗</a>
29 29
 	</li>
30 30
 <?php endif; ?>
31 31
 </script>
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	</div>
44 44
 	<div class="app-version">{{version}}</div>
45 45
 	<div class="app-level">
46
-		{{{level}}}{{#unless internal}}<a href="https://apps.nextcloud.com/apps/{{id}}"><?php p($l->t('View in store'));?> ↗</a>{{/unless}}
46
+		{{{level}}}{{#unless internal}}<a href="https://apps.nextcloud.com/apps/{{id}}"><?php p($l->t('View in store')); ?> ↗</a>{{/unless}}
47 47
 	</div>
48 48
 
49 49
 	<div class="app-groups">
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 		<input class="uninstall" type="submit" value="<?php p($l->t('Uninstall')); ?>" data-appid="{{id}}" />
67 67
 		{{/if}}
68 68
 		{{#if active}}
69
-		<input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/>
69
+		<input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable")); ?>"/>
70 70
 		{{else}}
71
-		<input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable"));?>"/>
71
+		<input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable")); ?>"/>
72 72
 		{{/if}}
73 73
 	</div>
74 74
 </div>
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	</h2>
90 90
 	<div class="app-version"> {{version}}</div>
91 91
 	{{#if profilepage}}<a href="{{profilepage}}" target="_blank" rel="noreferrer">{{/if}}
92
-	<div class="app-author"><?php p($l->t('by %s', ['{{author}}']));?>
92
+	<div class="app-author"><?php p($l->t('by %s', ['{{author}}'])); ?>
93 93
 		{{#if licence}}
94 94
 		(<?php p($l->t('%s-licensed', ['{{licence}}'])); ?>)
95 95
 		{{/if}}
@@ -108,37 +108,37 @@  discard block
 block discarded – undo
108 108
 		<!--<div class="app-changed">{{changed}}</div>-->
109 109
 		{{#if documentation}}
110 110
 		<p class="documentation">
111
-			<?php p($l->t("Documentation:"));?>
111
+			<?php p($l->t("Documentation:")); ?>
112 112
 			{{#if documentation.user}}
113 113
 			<span class="userDocumentation">
114
-			<a id="userDocumentation" class="appslink" href="{{documentation.user}}" target="_blank" rel="noreferrer"><?php p($l->t('User documentation'));?> ↗</a>
114
+			<a id="userDocumentation" class="appslink" href="{{documentation.user}}" target="_blank" rel="noreferrer"><?php p($l->t('User documentation')); ?> ↗</a>
115 115
 			</span>
116 116
 			{{/if}}
117 117
 
118 118
 			{{#if documentation.admin}}
119 119
 			<span class="adminDocumentation">
120
-			<a id="adminDocumentation" class="appslink" href="{{documentation.admin}}" target="_blank" rel="noreferrer"><?php p($l->t('Admin documentation'));?> ↗</a>
120
+			<a id="adminDocumentation" class="appslink" href="{{documentation.admin}}" target="_blank" rel="noreferrer"><?php p($l->t('Admin documentation')); ?> ↗</a>
121 121
 			</span>
122 122
 			{{/if}}
123 123
 
124 124
 			{{#if documentation.developer}}
125 125
 			<span class="developerDocumentation">
126
-			<a id="developerDocumentation" class="appslink" href="{{documentation.developer}}" target="_blank" rel="noreferrer"><?php p($l->t('Developer documentation'));?> ↗</a>
126
+			<a id="developerDocumentation" class="appslink" href="{{documentation.developer}}" target="_blank" rel="noreferrer"><?php p($l->t('Developer documentation')); ?> ↗</a>
127 127
 			</span>
128 128
 			{{/if}}
129 129
 		</p>
130 130
 		{{/if}}
131 131
 
132 132
 		{{#if website}}
133
-		<a id="userDocumentation" class="appslink" href="{{website}}" target="_blank" rel="noreferrer"><?php p($l->t('Visit website'));?> ↗</a>
133
+		<a id="userDocumentation" class="appslink" href="{{website}}" target="_blank" rel="noreferrer"><?php p($l->t('Visit website')); ?> ↗</a>
134 134
 		{{/if}}
135 135
 
136 136
 		{{#if bugs}}
137
-		<a id="adminDocumentation" class="appslink" href="{{bugs}}" target="_blank" rel="noreferrer"><?php p($l->t('Report a bug'));?> ↗</a>
137
+		<a id="adminDocumentation" class="appslink" href="{{bugs}}" target="_blank" rel="noreferrer"><?php p($l->t('Report a bug')); ?> ↗</a>
138 138
 		{{/if}}
139 139
 	</div><!-- end app-description-container -->
140
-	<div class="app-description-toggle-show" role="link"><?php p($l->t("Show description …"));?></div>
141
-	<div class="app-description-toggle-hide hidden" role="link"><?php p($l->t("Hide description …"));?></div>
140
+	<div class="app-description-toggle-show" role="link"><?php p($l->t("Show description …")); ?></div>
141
+	<div class="app-description-toggle-hide hidden" role="link"><?php p($l->t("Hide description …")); ?></div>
142 142
 
143 143
 	<div class="app-dependencies update hidden">
144 144
 		<p><?php p($l->t('This app has an update available.')); ?></p>
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 
170 170
 	<input class="update hidden" type="submit" value="<?php p($l->t('Update to %s', array('{{update}}'))); ?>" data-appid="{{id}}" />
171 171
 	{{#if active}}
172
-	<input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable"));?>"/>
172
+	<input class="enable" type="submit" data-appid="{{id}}" data-active="true" value="<?php p($l->t("Disable")); ?>"/>
173 173
 	<div class="groups-enable">
174 174
 		<input type="checkbox" class="groups-enable__checkbox checkbox" id="groups_enable-{{id}}"/>
175 175
 		<label for="groups_enable-{{id}}"><?php p($l->t('Enable only for specific groups')); ?></label>
176 176
 	</div>
177 177
 	<input type="hidden" id="group_select" title="<?php p($l->t('All')); ?>" style="width: 200px">
178 178
 	{{else}}
179
-	<input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable"));?>"/>
179
+	<input class="enable{{#if needsDownload}} needs-download{{/if}}" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable")); ?>"/>
180 180
 	{{/if}}
181 181
 	{{#if canUnInstall}}
182 182
 	<input class="uninstall" type="submit" value="<?php p($l->t('Uninstall app')); ?>" data-appid="{{id}}" />
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	</div>
188 188
 </script>
189 189
 
190
-<div id="app-navigation" class="icon-loading" data-category="<?php p($_['category']);?>">
190
+<div id="app-navigation" class="icon-loading" data-category="<?php p($_['category']); ?>">
191 191
 	<ul id="apps-categories">
192 192
 
193 193
 	</ul>
Please login to merge, or discard this patch.