You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppSettingsController.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author John Molakvoæ <skjnldsv@protonmail.com>
  11. * @author Julius Härtl <jus@bitgrid.net>
  12. * @author Lukas Reschke <lukas@statuscode.ch>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. * @author Thomas Müller <thomas.mueller@tmit.eu>
  16. * @author Kate Döen <kate.doeen@nextcloud.com>
  17. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  18. *
  19. * @license AGPL-3.0
  20. *
  21. * This code is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU Affero General Public License, version 3,
  23. * as published by the Free Software Foundation.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU Affero General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Affero General Public License, version 3,
  31. * along with this program. If not, see <http://www.gnu.org/licenses/>
  32. *
  33. */
  34. namespace OCA\Settings\Controller;
  35. use OC\App\AppStore\Bundles\BundleFetcher;
  36. use OC\App\AppStore\Fetcher\AppDiscoverFetcher;
  37. use OC\App\AppStore\Fetcher\AppFetcher;
  38. use OC\App\AppStore\Fetcher\CategoryFetcher;
  39. use OC\App\AppStore\Version\VersionParser;
  40. use OC\App\DependencyAnalyzer;
  41. use OC\App\Platform;
  42. use OC\Installer;
  43. use OC_App;
  44. use OCP\App\AppPathNotFoundException;
  45. use OCP\App\IAppManager;
  46. use OCP\AppFramework\Controller;
  47. use OCP\AppFramework\Http;
  48. use OCP\AppFramework\Http\Attribute\OpenAPI;
  49. use OCP\AppFramework\Http\ContentSecurityPolicy;
  50. use OCP\AppFramework\Http\FileDisplayResponse;
  51. use OCP\AppFramework\Http\JSONResponse;
  52. use OCP\AppFramework\Http\NotFoundResponse;
  53. use OCP\AppFramework\Http\Response;
  54. use OCP\AppFramework\Http\TemplateResponse;
  55. use OCP\AppFramework\Services\IInitialState;
  56. use OCP\Files\AppData\IAppDataFactory;
  57. use OCP\Files\IAppData;
  58. use OCP\Files\NotFoundException;
  59. use OCP\Files\NotPermittedException;
  60. use OCP\Files\SimpleFS\ISimpleFile;
  61. use OCP\Files\SimpleFS\ISimpleFolder;
  62. use OCP\Http\Client\IClientService;
  63. use OCP\IConfig;
  64. use OCP\IL10N;
  65. use OCP\INavigationManager;
  66. use OCP\IRequest;
  67. use OCP\IURLGenerator;
  68. use OCP\L10N\IFactory;
  69. use Psr\Log\LoggerInterface;
  70. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  71. class AppSettingsController extends Controller {
  72. /** @var array */
  73. private $allApps = [];
  74. private IAppData $appData;
  75. public function __construct(
  76. string $appName,
  77. IRequest $request,
  78. IAppDataFactory $appDataFactory,
  79. private IL10N $l10n,
  80. private IConfig $config,
  81. private INavigationManager $navigationManager,
  82. private IAppManager $appManager,
  83. private CategoryFetcher $categoryFetcher,
  84. private AppFetcher $appFetcher,
  85. private IFactory $l10nFactory,
  86. private BundleFetcher $bundleFetcher,
  87. private Installer $installer,
  88. private IURLGenerator $urlGenerator,
  89. private LoggerInterface $logger,
  90. private IInitialState $initialState,
  91. private AppDiscoverFetcher $discoverFetcher,
  92. private IClientService $clientService,
  93. ) {
  94. parent::__construct($appName, $request);
  95. $this->appData = $appDataFactory->get('appstore');
  96. }
  97. /**
  98. * @NoCSRFRequired
  99. *
  100. * @return TemplateResponse
  101. */
  102. public function viewApps(): TemplateResponse {
  103. $this->navigationManager->setActiveEntry('core_apps');
  104. $this->initialState->provideInitialState('appstoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
  105. $this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
  106. $this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));
  107. $this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates()));
  108. $policy = new ContentSecurityPolicy();
  109. $policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
  110. $templateResponse = new TemplateResponse('settings', 'settings/empty', ['pageTitle' => $this->l10n->t('Settings')]);
  111. $templateResponse->setContentSecurityPolicy($policy);
  112. \OCP\Util::addStyle('settings', 'settings');
  113. \OCP\Util::addScript('settings', 'vue-settings-apps-users-management');
  114. return $templateResponse;
  115. }
  116. /**
  117. * Get all active entries for the app discover section
  118. *
  119. * @NoCSRFRequired
  120. */
  121. public function getAppDiscoverJSON(): JSONResponse {
  122. $data = $this->discoverFetcher->get(true);
  123. return new JSONResponse($data);
  124. }
  125. /**
  126. * @PublicPage
  127. * @NoCSRFRequired
  128. *
  129. * Get a image for the app discover section - this is proxied for privacy and CSP reasons
  130. *
  131. * @param string $image
  132. * @throws \Exception
  133. */
  134. public function getAppDiscoverMedia(string $fileName): Response {
  135. $etag = $this->discoverFetcher->getETag() ?? date('Y-m');
  136. $folder = null;
  137. try {
  138. $folder = $this->appData->getFolder('app-discover-cache');
  139. $this->cleanUpImageCache($folder, $etag);
  140. } catch (\Throwable $e) {
  141. $folder = $this->appData->newFolder('app-discover-cache');
  142. }
  143. // Get the current cache folder
  144. try {
  145. $folder = $folder->getFolder($etag);
  146. } catch (NotFoundException $e) {
  147. $folder = $folder->newFolder($etag);
  148. }
  149. $info = pathinfo($fileName);
  150. $hashName = md5($fileName);
  151. $allFiles = $folder->getDirectoryListing();
  152. // Try to find the file
  153. $file = array_filter($allFiles, function (ISimpleFile $file) use ($hashName) {
  154. return str_starts_with($file->getName(), $hashName);
  155. });
  156. // Get the first entry
  157. $file = reset($file);
  158. // If not found request from Web
  159. if ($file === false) {
  160. try {
  161. $client = $this->clientService->newClient();
  162. $fileResponse = $client->get($fileName);
  163. $contentType = $fileResponse->getHeader('Content-Type');
  164. $extension = $info['extension'] ?? '';
  165. $file = $folder->newFile($hashName . '.' . base64_encode($contentType) . '.' . $extension, $fileResponse->getBody());
  166. } catch (\Throwable $e) {
  167. $this->logger->warning('Could not load media file for app discover section', ['media_src' => $fileName, 'exception' => $e]);
  168. return new NotFoundResponse();
  169. }
  170. } else {
  171. // File was found so we can get the content type from the file name
  172. $contentType = base64_decode(explode('.', $file->getName())[1] ?? '');
  173. }
  174. $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $contentType]);
  175. // cache for 7 days
  176. $response->cacheFor(604800, false, true);
  177. return $response;
  178. }
  179. /**
  180. * Remove orphaned folders from the image cache that do not match the current etag
  181. * @param ISimpleFolder $folder The folder to clear
  182. * @param string $etag The etag (directory name) to keep
  183. */
  184. private function cleanUpImageCache(ISimpleFolder $folder, string $etag): void {
  185. // Cleanup old cache folders
  186. $allFiles = $folder->getDirectoryListing();
  187. foreach ($allFiles as $dir) {
  188. try {
  189. if ($dir->getName() !== $etag) {
  190. $dir->delete();
  191. }
  192. } catch (NotPermittedException $e) {
  193. // ignore folder for now
  194. }
  195. }
  196. }
  197. private function getAppsWithUpdates() {
  198. $appClass = new \OC_App();
  199. $apps = $appClass->listAllApps();
  200. foreach ($apps as $key => $app) {
  201. $newVersion = $this->installer->isUpdateAvailable($app['id']);
  202. if ($newVersion === false) {
  203. unset($apps[$key]);
  204. }
  205. }
  206. return $apps;
  207. }
  208. private function getBundles() {
  209. $result = [];
  210. $bundles = $this->bundleFetcher->getBundles();
  211. foreach ($bundles as $bundle) {
  212. $result[] = [
  213. 'name' => $bundle->getName(),
  214. 'id' => $bundle->getIdentifier(),
  215. 'appIdentifiers' => $bundle->getAppIdentifiers()
  216. ];
  217. }
  218. return $result;
  219. }
  220. /**
  221. * Get all available categories
  222. *
  223. * @return JSONResponse
  224. */
  225. public function listCategories(): JSONResponse {
  226. return new JSONResponse($this->getAllCategories());
  227. }
  228. private function getAllCategories() {
  229. $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
  230. $categories = $this->categoryFetcher->get();
  231. return array_map(fn ($category) => [
  232. 'id' => $category['id'],
  233. 'displayName' => $category['translations'][$currentLanguage]['name'] ?? $category['translations']['en']['name'],
  234. ], $categories);
  235. }
  236. private function fetchApps() {
  237. $appClass = new \OC_App();
  238. $apps = $appClass->listAllApps();
  239. foreach ($apps as $app) {
  240. $app['installed'] = true;
  241. $this->allApps[$app['id']] = $app;
  242. }
  243. $apps = $this->getAppsForCategory('');
  244. $supportedApps = $appClass->getSupportedApps();
  245. foreach ($apps as $app) {
  246. $app['appstore'] = true;
  247. if (!array_key_exists($app['id'], $this->allApps)) {
  248. $this->allApps[$app['id']] = $app;
  249. } else {
  250. $this->allApps[$app['id']] = array_merge($app, $this->allApps[$app['id']]);
  251. }
  252. if (in_array($app['id'], $supportedApps)) {
  253. $this->allApps[$app['id']]['level'] = \OC_App::supportedApp;
  254. }
  255. }
  256. // add bundle information
  257. $bundles = $this->bundleFetcher->getBundles();
  258. foreach ($bundles as $bundle) {
  259. foreach ($bundle->getAppIdentifiers() as $identifier) {
  260. foreach ($this->allApps as &$app) {
  261. if ($app['id'] === $identifier) {
  262. $app['bundleIds'][] = $bundle->getIdentifier();
  263. continue;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. private function getAllApps() {
  270. return $this->allApps;
  271. }
  272. /**
  273. * Get all available apps in a category
  274. *
  275. * @return JSONResponse
  276. * @throws \Exception
  277. */
  278. public function listApps(): JSONResponse {
  279. $this->fetchApps();
  280. $apps = $this->getAllApps();
  281. $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
  282. $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []);
  283. if (!is_array($ignoreMaxApps)) {
  284. $this->logger->warning('The value given for app_install_overwrite is not an array. Ignoring...');
  285. $ignoreMaxApps = [];
  286. }
  287. // Extend existing app details
  288. $apps = array_map(function (array $appData) use ($dependencyAnalyzer, $ignoreMaxApps) {
  289. if (isset($appData['appstoreData'])) {
  290. $appstoreData = $appData['appstoreData'];
  291. $appData['screenshot'] = isset($appstoreData['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/' . base64_encode($appstoreData['screenshots'][0]['url']) : '';
  292. $appData['category'] = $appstoreData['categories'];
  293. $appData['releases'] = $appstoreData['releases'];
  294. }
  295. $newVersion = $this->installer->isUpdateAvailable($appData['id']);
  296. if ($newVersion) {
  297. $appData['update'] = $newVersion;
  298. }
  299. // fix groups to be an array
  300. $groups = [];
  301. if (is_string($appData['groups'])) {
  302. $groups = json_decode($appData['groups']);
  303. }
  304. $appData['groups'] = $groups;
  305. $appData['canUnInstall'] = !$appData['active'] && $appData['removable'];
  306. // fix licence vs license
  307. if (isset($appData['license']) && !isset($appData['licence'])) {
  308. $appData['licence'] = $appData['license'];
  309. }
  310. $ignoreMax = in_array($appData['id'], $ignoreMaxApps);
  311. // analyse dependencies
  312. $missing = $dependencyAnalyzer->analyze($appData, $ignoreMax);
  313. $appData['canInstall'] = empty($missing);
  314. $appData['missingDependencies'] = $missing;
  315. $appData['missingMinOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['min-version']);
  316. $appData['missingMaxOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['max-version']);
  317. $appData['isCompatible'] = $dependencyAnalyzer->isMarkedCompatible($appData);
  318. return $appData;
  319. }, $apps);
  320. usort($apps, [$this, 'sortApps']);
  321. return new JSONResponse(['apps' => $apps, 'status' => 'success']);
  322. }
  323. /**
  324. * Get all apps for a category from the app store
  325. *
  326. * @param string $requestedCategory
  327. * @return array
  328. * @throws \Exception
  329. */
  330. private function getAppsForCategory($requestedCategory = ''): array {
  331. $versionParser = new VersionParser();
  332. $formattedApps = [];
  333. $apps = $this->appFetcher->get();
  334. foreach ($apps as $app) {
  335. // Skip all apps not in the requested category
  336. if ($requestedCategory !== '') {
  337. $isInCategory = false;
  338. foreach ($app['categories'] as $category) {
  339. if ($category === $requestedCategory) {
  340. $isInCategory = true;
  341. }
  342. }
  343. if (!$isInCategory) {
  344. continue;
  345. }
  346. }
  347. if (!isset($app['releases'][0]['rawPlatformVersionSpec'])) {
  348. continue;
  349. }
  350. $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
  351. $nextCloudVersionDependencies = [];
  352. if ($nextCloudVersion->getMinimumVersion() !== '') {
  353. $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
  354. }
  355. if ($nextCloudVersion->getMaximumVersion() !== '') {
  356. $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
  357. }
  358. $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
  359. try {
  360. $this->appManager->getAppPath($app['id']);
  361. $existsLocally = true;
  362. } catch (AppPathNotFoundException) {
  363. $existsLocally = false;
  364. }
  365. $phpDependencies = [];
  366. if ($phpVersion->getMinimumVersion() !== '') {
  367. $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
  368. }
  369. if ($phpVersion->getMaximumVersion() !== '') {
  370. $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
  371. }
  372. if (isset($app['releases'][0]['minIntSize'])) {
  373. $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
  374. }
  375. $authors = '';
  376. foreach ($app['authors'] as $key => $author) {
  377. $authors .= $author['name'];
  378. if ($key !== count($app['authors']) - 1) {
  379. $authors .= ', ';
  380. }
  381. }
  382. $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
  383. $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
  384. $groups = null;
  385. if ($enabledValue !== 'no' && $enabledValue !== 'yes') {
  386. $groups = $enabledValue;
  387. }
  388. $currentVersion = '';
  389. if ($this->appManager->isInstalled($app['id'])) {
  390. $currentVersion = $this->appManager->getAppVersion($app['id']);
  391. } else {
  392. $currentVersion = $app['releases'][0]['version'];
  393. }
  394. $formattedApps[] = [
  395. 'id' => $app['id'],
  396. 'name' => $app['translations'][$currentLanguage]['name'] ?? $app['translations']['en']['name'],
  397. 'description' => $app['translations'][$currentLanguage]['description'] ?? $app['translations']['en']['description'],
  398. 'summary' => $app['translations'][$currentLanguage]['summary'] ?? $app['translations']['en']['summary'],
  399. 'license' => $app['releases'][0]['licenses'],
  400. 'author' => $authors,
  401. 'shipped' => false,
  402. 'version' => $currentVersion,
  403. 'default_enable' => '',
  404. 'types' => [],
  405. 'documentation' => [
  406. 'admin' => $app['adminDocs'],
  407. 'user' => $app['userDocs'],
  408. 'developer' => $app['developerDocs']
  409. ],
  410. 'website' => $app['website'],
  411. 'bugs' => $app['issueTracker'],
  412. 'detailpage' => $app['website'],
  413. 'dependencies' => array_merge(
  414. $nextCloudVersionDependencies,
  415. $phpDependencies
  416. ),
  417. 'level' => ($app['isFeatured'] === true) ? 200 : 100,
  418. 'missingMaxOwnCloudVersion' => false,
  419. 'missingMinOwnCloudVersion' => false,
  420. 'canInstall' => true,
  421. 'screenshot' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
  422. 'score' => $app['ratingOverall'],
  423. 'ratingNumOverall' => $app['ratingNumOverall'],
  424. 'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5,
  425. 'removable' => $existsLocally,
  426. 'active' => $this->appManager->isEnabledForUser($app['id']),
  427. 'needsDownload' => !$existsLocally,
  428. 'groups' => $groups,
  429. 'fromAppStore' => true,
  430. 'appstoreData' => $app,
  431. ];
  432. }
  433. return $formattedApps;
  434. }
  435. /**
  436. * @PasswordConfirmationRequired
  437. *
  438. * @param string $appId
  439. * @param array $groups
  440. * @return JSONResponse
  441. */
  442. public function enableApp(string $appId, array $groups = []): JSONResponse {
  443. return $this->enableApps([$appId], $groups);
  444. }
  445. /**
  446. * Enable one or more apps
  447. *
  448. * apps will be enabled for specific groups only if $groups is defined
  449. *
  450. * @PasswordConfirmationRequired
  451. * @param array $appIds
  452. * @param array $groups
  453. * @return JSONResponse
  454. */
  455. public function enableApps(array $appIds, array $groups = []): JSONResponse {
  456. try {
  457. $updateRequired = false;
  458. foreach ($appIds as $appId) {
  459. $appId = OC_App::cleanAppId($appId);
  460. // Check if app is already downloaded
  461. /** @var Installer $installer */
  462. $installer = \OC::$server->get(Installer::class);
  463. $isDownloaded = $installer->isDownloaded($appId);
  464. if (!$isDownloaded) {
  465. $installer->downloadApp($appId);
  466. }
  467. $installer->installApp($appId);
  468. if (count($groups) > 0) {
  469. $this->appManager->enableAppForGroups($appId, $this->getGroupList($groups));
  470. } else {
  471. $this->appManager->enableApp($appId);
  472. }
  473. if (\OC_App::shouldUpgrade($appId)) {
  474. $updateRequired = true;
  475. }
  476. }
  477. return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
  478. } catch (\Throwable $e) {
  479. $this->logger->error('could not enable apps', ['exception' => $e]);
  480. return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
  481. }
  482. }
  483. private function getGroupList(array $groups) {
  484. $groupManager = \OC::$server->getGroupManager();
  485. $groupsList = [];
  486. foreach ($groups as $group) {
  487. $groupItem = $groupManager->get($group);
  488. if ($groupItem instanceof \OCP\IGroup) {
  489. $groupsList[] = $groupManager->get($group);
  490. }
  491. }
  492. return $groupsList;
  493. }
  494. /**
  495. * @PasswordConfirmationRequired
  496. *
  497. * @param string $appId
  498. * @return JSONResponse
  499. */
  500. public function disableApp(string $appId): JSONResponse {
  501. return $this->disableApps([$appId]);
  502. }
  503. /**
  504. * @PasswordConfirmationRequired
  505. *
  506. * @param array $appIds
  507. * @return JSONResponse
  508. */
  509. public function disableApps(array $appIds): JSONResponse {
  510. try {
  511. foreach ($appIds as $appId) {
  512. $appId = OC_App::cleanAppId($appId);
  513. $this->appManager->disableApp($appId);
  514. }
  515. return new JSONResponse([]);
  516. } catch (\Exception $e) {
  517. $this->logger->error('could not disable app', ['exception' => $e]);
  518. return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
  519. }
  520. }
  521. /**
  522. * @PasswordConfirmationRequired
  523. *
  524. * @param string $appId
  525. * @return JSONResponse
  526. */
  527. public function uninstallApp(string $appId): JSONResponse {
  528. $appId = OC_App::cleanAppId($appId);
  529. $result = $this->installer->removeApp($appId);
  530. if ($result !== false) {
  531. $this->appManager->clearAppsCache();
  532. return new JSONResponse(['data' => ['appid' => $appId]]);
  533. }
  534. return new JSONResponse(['data' => ['message' => $this->l10n->t('Could not remove app.')]], Http::STATUS_INTERNAL_SERVER_ERROR);
  535. }
  536. /**
  537. * @param string $appId
  538. * @return JSONResponse
  539. */
  540. public function updateApp(string $appId): JSONResponse {
  541. $appId = OC_App::cleanAppId($appId);
  542. $this->config->setSystemValue('maintenance', true);
  543. try {
  544. $result = $this->installer->updateAppstoreApp($appId);
  545. $this->config->setSystemValue('maintenance', false);
  546. } catch (\Exception $ex) {
  547. $this->config->setSystemValue('maintenance', false);
  548. return new JSONResponse(['data' => ['message' => $ex->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
  549. }
  550. if ($result !== false) {
  551. return new JSONResponse(['data' => ['appid' => $appId]]);
  552. }
  553. return new JSONResponse(['data' => ['message' => $this->l10n->t('Could not update app.')]], Http::STATUS_INTERNAL_SERVER_ERROR);
  554. }
  555. private function sortApps($a, $b) {
  556. $a = (string)$a['name'];
  557. $b = (string)$b['name'];
  558. if ($a === $b) {
  559. return 0;
  560. }
  561. return ($a < $b) ? -1 : 1;
  562. }
  563. public function force(string $appId): JSONResponse {
  564. $appId = OC_App::cleanAppId($appId);
  565. $this->appManager->ignoreNextcloudRequirementForApp($appId);
  566. return new JSONResponse();
  567. }
  568. }