2014-10-15 19:59:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-10-27 15:41:15 +00:00
|
|
|
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 15:07:57 +00:00
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Felix A. Epp <work@felixepp.de>
|
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-10-15 19:59:16 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-10-15 19:59:16 +00:00
|
|
|
namespace OC\Settings\Controller;
|
|
|
|
|
2017-04-23 20:10:17 +00:00
|
|
|
use OC\App\AppStore\Bundles\BundleFetcher;
|
2016-10-27 15:41:15 +00:00
|
|
|
use OC\App\AppStore\Fetcher\AppFetcher;
|
|
|
|
use OC\App\AppStore\Fetcher\CategoryFetcher;
|
|
|
|
use OC\App\AppStore\Version\VersionParser;
|
2014-12-01 20:47:22 +00:00
|
|
|
use OC\App\DependencyAnalyzer;
|
|
|
|
use OC\App\Platform;
|
2017-11-24 09:41:51 +00:00
|
|
|
use OC\Installer;
|
2018-01-18 09:02:08 +00:00
|
|
|
use OC_App;
|
2015-03-30 13:58:20 +00:00
|
|
|
use OCP\App\IAppManager;
|
2014-10-15 19:59:16 +00:00
|
|
|
use \OCP\AppFramework\Controller;
|
2018-01-18 09:02:08 +00:00
|
|
|
use OCP\AppFramework\Http;
|
2015-03-30 13:58:20 +00:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2016-10-27 15:41:15 +00:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2015-03-30 13:58:20 +00:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2018-01-18 09:02:08 +00:00
|
|
|
use OCP\ILogger;
|
2015-03-30 13:58:20 +00:00
|
|
|
use OCP\INavigationManager;
|
2014-10-15 19:59:16 +00:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IConfig;
|
2018-02-08 14:13:06 +00:00
|
|
|
use OCP\IURLGenerator;
|
2016-10-27 15:41:15 +00:00
|
|
|
use OCP\L10N\IFactory;
|
2014-10-15 19:59:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OC\Settings\Controller
|
|
|
|
*/
|
|
|
|
class AppSettingsController extends Controller {
|
|
|
|
|
|
|
|
/** @var \OCP\IL10N */
|
|
|
|
private $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2015-03-30 13:58:20 +00:00
|
|
|
/** @var INavigationManager */
|
|
|
|
private $navigationManager;
|
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2016-10-27 15:41:15 +00:00
|
|
|
/** @var CategoryFetcher */
|
|
|
|
private $categoryFetcher;
|
|
|
|
/** @var AppFetcher */
|
|
|
|
private $appFetcher;
|
|
|
|
/** @var IFactory */
|
|
|
|
private $l10nFactory;
|
2017-04-23 20:10:17 +00:00
|
|
|
/** @var BundleFetcher */
|
|
|
|
private $bundleFetcher;
|
2017-11-24 09:41:51 +00:00
|
|
|
/** @var Installer */
|
|
|
|
private $installer;
|
2018-02-08 14:13:06 +00:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2018-01-18 09:02:08 +00:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
2014-10-15 19:59:16 +00:00
|
|
|
|
2018-06-02 07:51:14 +00:00
|
|
|
/** @var array */
|
|
|
|
private $allApps = [];
|
|
|
|
|
2014-10-15 19:59:16 +00:00
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param IConfig $config
|
2015-03-30 13:58:20 +00:00
|
|
|
* @param INavigationManager $navigationManager
|
|
|
|
* @param IAppManager $appManager
|
2016-10-27 15:41:15 +00:00
|
|
|
* @param CategoryFetcher $categoryFetcher
|
|
|
|
* @param AppFetcher $appFetcher
|
|
|
|
* @param IFactory $l10nFactory
|
2017-04-23 20:10:17 +00:00
|
|
|
* @param BundleFetcher $bundleFetcher
|
2017-11-24 09:41:51 +00:00
|
|
|
* @param Installer $installer
|
2018-02-08 14:13:06 +00:00
|
|
|
* @param IURLGenerator $urlGenerator
|
2018-01-18 09:02:08 +00:00
|
|
|
* @param ILogger $logger
|
2014-10-15 19:59:16 +00:00
|
|
|
*/
|
2018-02-08 14:13:06 +00:00
|
|
|
public function __construct(string $appName,
|
2014-10-15 19:59:16 +00:00
|
|
|
IRequest $request,
|
|
|
|
IL10N $l10n,
|
2015-01-09 17:31:39 +00:00
|
|
|
IConfig $config,
|
2015-03-30 13:58:20 +00:00
|
|
|
INavigationManager $navigationManager,
|
|
|
|
IAppManager $appManager,
|
2016-10-27 15:41:15 +00:00
|
|
|
CategoryFetcher $categoryFetcher,
|
|
|
|
AppFetcher $appFetcher,
|
2017-04-23 20:10:17 +00:00
|
|
|
IFactory $l10nFactory,
|
2017-11-24 09:41:51 +00:00
|
|
|
BundleFetcher $bundleFetcher,
|
2018-02-08 14:13:06 +00:00
|
|
|
Installer $installer,
|
2018-01-18 09:02:08 +00:00
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
ILogger $logger) {
|
2014-10-15 19:59:16 +00:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->config = $config;
|
2015-03-30 13:58:20 +00:00
|
|
|
$this->navigationManager = $navigationManager;
|
|
|
|
$this->appManager = $appManager;
|
2016-10-27 15:41:15 +00:00
|
|
|
$this->categoryFetcher = $categoryFetcher;
|
|
|
|
$this->appFetcher = $appFetcher;
|
|
|
|
$this->l10nFactory = $l10nFactory;
|
2017-04-23 20:10:17 +00:00
|
|
|
$this->bundleFetcher = $bundleFetcher;
|
2017-11-24 09:41:51 +00:00
|
|
|
$this->installer = $installer;
|
2018-02-08 14:13:06 +00:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2018-01-18 09:02:08 +00:00
|
|
|
$this->logger = $logger;
|
2015-10-20 10:02:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 13:58:20 +00:00
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
2016-10-27 15:41:15 +00:00
|
|
|
*
|
2015-03-30 13:58:20 +00:00
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
2018-05-29 15:52:50 +00:00
|
|
|
public function viewApps(): TemplateResponse {
|
2018-05-29 20:53:20 +00:00
|
|
|
\OC_Util::addScript('settings', 'apps');
|
2018-05-23 17:50:42 +00:00
|
|
|
\OC_Util::addVendorScript('core', 'marked/marked.min');
|
2015-03-30 13:58:20 +00:00
|
|
|
$params = [];
|
2015-12-02 13:35:38 +00:00
|
|
|
$params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
|
2018-05-17 20:42:16 +00:00
|
|
|
$params['updateCount'] = count($this->getAppsWithUpdates());
|
2018-05-25 11:24:51 +00:00
|
|
|
$params['developerDocumentation'] = $this->urlGenerator->linkToDocs('developer-manual');
|
2018-05-29 16:23:42 +00:00
|
|
|
$params['bundles'] = $this->getBundles();
|
2015-03-30 13:58:20 +00:00
|
|
|
$this->navigationManager->setActiveEntry('core_apps');
|
|
|
|
|
2018-06-12 08:23:00 +00:00
|
|
|
$templateResponse = new TemplateResponse('settings', 'settings-vue', ['serverData' => $params]);
|
2015-03-30 13:58:20 +00:00
|
|
|
$policy = new ContentSecurityPolicy();
|
2016-10-31 16:08:11 +00:00
|
|
|
$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
|
2015-03-30 13:58:20 +00:00
|
|
|
$templateResponse->setContentSecurityPolicy($policy);
|
|
|
|
|
|
|
|
return $templateResponse;
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 07:38:27 +00:00
|
|
|
private function getAppsWithUpdates() {
|
|
|
|
$appClass = new \OC_App();
|
|
|
|
$apps = $appClass->listAllApps();
|
|
|
|
foreach($apps as $key => $app) {
|
|
|
|
$newVersion = $this->installer->isUpdateAvailable($app['id']);
|
|
|
|
if($newVersion === false) {
|
|
|
|
unset($apps[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $apps;
|
|
|
|
}
|
|
|
|
|
2018-05-29 16:23:42 +00:00
|
|
|
private function getBundles() {
|
|
|
|
$result = [];
|
|
|
|
$bundles = $this->bundleFetcher->getBundles();
|
|
|
|
foreach ($bundles as $bundle) {
|
|
|
|
$result[] = [
|
|
|
|
'name' => $bundle->getName(),
|
|
|
|
'id' => $bundle->getIdentifier(),
|
|
|
|
'appIdentifiers' => $bundle->getAppIdentifiers()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:38:27 +00:00
|
|
|
/**
|
|
|
|
* Get all available categories
|
|
|
|
*
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function listCategories(): JSONResponse {
|
|
|
|
return new JSONResponse($this->getAllCategories());
|
|
|
|
}
|
|
|
|
|
2017-04-25 18:17:52 +00:00
|
|
|
private function getAllCategories() {
|
2016-10-27 15:41:15 +00:00
|
|
|
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
|
2014-10-15 19:59:16 +00:00
|
|
|
|
2018-05-17 20:42:16 +00:00
|
|
|
$formattedCategories = [];
|
2016-10-27 15:41:15 +00:00
|
|
|
$categories = $this->categoryFetcher->get();
|
|
|
|
foreach($categories as $category) {
|
|
|
|
$formattedCategories[] = [
|
|
|
|
'id' => $category['id'],
|
|
|
|
'ident' => $category['id'],
|
|
|
|
'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'],
|
|
|
|
];
|
|
|
|
}
|
2014-10-15 19:59:16 +00:00
|
|
|
|
2017-04-25 18:17:52 +00:00
|
|
|
return $formattedCategories;
|
|
|
|
}
|
|
|
|
|
2018-06-02 07:51:14 +00:00
|
|
|
private function fetchApps() {
|
|
|
|
$appClass = new \OC_App();
|
|
|
|
$apps = $appClass->listAllApps();
|
|
|
|
foreach ($apps as $app) {
|
|
|
|
$app['installed'] = true;
|
|
|
|
$this->allApps[$app['id']] = $app;
|
|
|
|
}
|
|
|
|
|
|
|
|
$apps = $this->getAppsForCategory('');
|
|
|
|
foreach ($apps as $app) {
|
|
|
|
$app['appstore'] = true;
|
|
|
|
if (!array_key_exists($app['id'], $this->allApps)) {
|
|
|
|
$this->allApps[$app['id']] = $app;
|
|
|
|
} else {
|
2018-08-02 11:47:42 +00:00
|
|
|
$this->allApps[$app['id']] = array_merge($app, $this->allApps[$app['id']]);
|
2018-06-02 07:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add bundle information
|
|
|
|
$bundles = $this->bundleFetcher->getBundles();
|
|
|
|
foreach($bundles as $bundle) {
|
|
|
|
foreach($bundle->getAppIdentifiers() as $identifier) {
|
|
|
|
foreach($this->allApps as &$app) {
|
|
|
|
if($app['id'] === $identifier) {
|
|
|
|
$app['bundleId'] = $bundle->getIdentifier();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAllApps() {
|
|
|
|
return $this->allApps;
|
|
|
|
}
|
2017-04-25 18:17:52 +00:00
|
|
|
/**
|
2018-05-30 07:38:27 +00:00
|
|
|
* Get all available apps in a category
|
2017-04-25 18:17:52 +00:00
|
|
|
*
|
2018-05-30 07:38:27 +00:00
|
|
|
* @param string $category
|
2017-04-25 18:17:52 +00:00
|
|
|
* @return JSONResponse
|
2018-05-30 07:38:27 +00:00
|
|
|
* @throws \Exception
|
2017-04-25 18:17:52 +00:00
|
|
|
*/
|
2018-06-02 07:51:14 +00:00
|
|
|
public function listApps(): JSONResponse {
|
2018-05-30 07:38:27 +00:00
|
|
|
|
2018-06-02 07:51:14 +00:00
|
|
|
$this->fetchApps();
|
|
|
|
$apps = $this->getAllApps();
|
2018-05-30 07:38:27 +00:00
|
|
|
|
|
|
|
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
|
|
|
|
|
|
|
|
// Extend existing app details
|
2018-06-02 07:51:14 +00:00
|
|
|
$apps = array_map(function($appData) use ($dependencyAnalyzer) {
|
|
|
|
$appstoreData = $appData['appstoreData'];
|
2018-05-30 07:38:27 +00:00
|
|
|
$appData['screenshot'] = isset($appstoreData['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($appstoreData['screenshots'][0]['url']) : '';
|
2018-06-09 09:38:44 +00:00
|
|
|
$appData['category'] = $appstoreData['categories'];
|
2018-06-02 06:48:33 +00:00
|
|
|
|
2018-05-30 07:38:27 +00:00
|
|
|
$newVersion = $this->installer->isUpdateAvailable($appData['id']);
|
|
|
|
if($newVersion && $this->appManager->isInstalled($appData['id'])) {
|
|
|
|
$appData['update'] = $newVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix groups to be an array
|
|
|
|
$groups = array();
|
|
|
|
if (is_string($appData['groups'])) {
|
|
|
|
$groups = json_decode($appData['groups']);
|
|
|
|
}
|
|
|
|
$appData['groups'] = $groups;
|
|
|
|
$appData['canUnInstall'] = !$appData['active'] && $appData['removable'];
|
|
|
|
|
|
|
|
// fix licence vs license
|
|
|
|
if (isset($appData['license']) && !isset($appData['licence'])) {
|
|
|
|
$appData['licence'] = $appData['license'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// analyse dependencies
|
|
|
|
$missing = $dependencyAnalyzer->analyze($appData);
|
|
|
|
$appData['canInstall'] = empty($missing);
|
|
|
|
$appData['missingDependencies'] = $missing;
|
|
|
|
|
|
|
|
$appData['missingMinOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['min-version']);
|
|
|
|
$appData['missingMaxOwnCloudVersion'] = !isset($appData['dependencies']['nextcloud']['@attributes']['max-version']);
|
|
|
|
|
|
|
|
return $appData;
|
|
|
|
}, $apps);
|
|
|
|
|
|
|
|
usort($apps, [$this, 'sortApps']);
|
|
|
|
|
|
|
|
return new JSONResponse(['apps' => $apps, 'status' => 'success']);
|
2016-10-27 15:41:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-02 07:51:14 +00:00
|
|
|
* Get all apps for a category from the app store
|
2016-10-27 15:41:15 +00:00
|
|
|
*
|
|
|
|
* @param string $requestedCategory
|
|
|
|
* @return array
|
2018-05-29 15:52:50 +00:00
|
|
|
* @throws \Exception
|
2016-10-27 15:41:15 +00:00
|
|
|
*/
|
2018-05-29 15:52:50 +00:00
|
|
|
private function getAppsForCategory($requestedCategory = ''): array {
|
2016-10-27 15:41:15 +00:00
|
|
|
$versionParser = new VersionParser();
|
|
|
|
$formattedApps = [];
|
|
|
|
$apps = $this->appFetcher->get();
|
|
|
|
foreach($apps as $app) {
|
|
|
|
// Skip all apps not in the requested category
|
2018-05-22 06:58:07 +00:00
|
|
|
if ($requestedCategory !== '') {
|
|
|
|
$isInCategory = false;
|
|
|
|
foreach($app['categories'] as $category) {
|
|
|
|
if($category === $requestedCategory) {
|
|
|
|
$isInCategory = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$isInCategory) {
|
|
|
|
continue;
|
2016-10-27 15:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
|
|
|
|
$nextCloudVersionDependencies = [];
|
|
|
|
if($nextCloudVersion->getMinimumVersion() !== '') {
|
2016-11-15 14:07:58 +00:00
|
|
|
$nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
|
2016-10-27 15:41:15 +00:00
|
|
|
}
|
|
|
|
if($nextCloudVersion->getMaximumVersion() !== '') {
|
2016-11-15 14:07:58 +00:00
|
|
|
$nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
|
2016-10-27 15:41:15 +00:00
|
|
|
}
|
|
|
|
$phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
|
2018-01-26 11:36:25 +00:00
|
|
|
$existsLocally = \OC_App::getAppPath($app['id']) !== false;
|
2016-10-27 15:41:15 +00:00
|
|
|
$phpDependencies = [];
|
|
|
|
if($phpVersion->getMinimumVersion() !== '') {
|
|
|
|
$phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
|
|
|
|
}
|
|
|
|
if($phpVersion->getMaximumVersion() !== '') {
|
|
|
|
$phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
|
|
|
|
}
|
|
|
|
if(isset($app['releases'][0]['minIntSize'])) {
|
|
|
|
$phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
|
|
|
|
}
|
|
|
|
$authors = '';
|
|
|
|
foreach($app['authors'] as $key => $author) {
|
|
|
|
$authors .= $author['name'];
|
|
|
|
if($key !== count($app['authors']) - 1) {
|
|
|
|
$authors .= ', ';
|
2015-01-30 15:39:57 +00:00
|
|
|
}
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 15:41:15 +00:00
|
|
|
$currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
|
2016-10-31 10:07:54 +00:00
|
|
|
$enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
|
|
|
|
$groups = null;
|
|
|
|
if($enabledValue !== 'no' && $enabledValue !== 'yes') {
|
|
|
|
$groups = $enabledValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$currentVersion = '';
|
|
|
|
if($this->appManager->isInstalled($app['id'])) {
|
2018-05-29 15:52:50 +00:00
|
|
|
$currentVersion = $this->appManager->getAppVersion($app['id']);
|
2016-10-31 10:07:54 +00:00
|
|
|
} else {
|
|
|
|
$currentLanguage = $app['releases'][0]['version'];
|
|
|
|
}
|
2016-10-27 15:41:15 +00:00
|
|
|
|
|
|
|
$formattedApps[] = [
|
|
|
|
'id' => $app['id'],
|
|
|
|
'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'],
|
|
|
|
'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'],
|
2018-05-25 11:24:51 +00:00
|
|
|
'summary' => isset($app['translations'][$currentLanguage]['summary']) ? $app['translations'][$currentLanguage]['summary'] : $app['translations']['en']['summary'],
|
2016-10-27 15:41:15 +00:00
|
|
|
'license' => $app['releases'][0]['licenses'],
|
|
|
|
'author' => $authors,
|
|
|
|
'shipped' => false,
|
2016-10-31 10:07:54 +00:00
|
|
|
'version' => $currentVersion,
|
2016-10-27 15:41:15 +00:00
|
|
|
'default_enable' => '',
|
|
|
|
'types' => [],
|
|
|
|
'documentation' => [
|
|
|
|
'admin' => $app['adminDocs'],
|
|
|
|
'user' => $app['userDocs'],
|
|
|
|
'developer' => $app['developerDocs']
|
|
|
|
],
|
|
|
|
'website' => $app['website'],
|
|
|
|
'bugs' => $app['issueTracker'],
|
|
|
|
'detailpage' => $app['website'],
|
|
|
|
'dependencies' => array_merge(
|
|
|
|
$nextCloudVersionDependencies,
|
|
|
|
$phpDependencies
|
|
|
|
),
|
2018-05-30 07:38:27 +00:00
|
|
|
'level' => ($app['isFeatured'] === true) ? 200 : 100,
|
2016-10-27 15:41:15 +00:00
|
|
|
'missingMaxOwnCloudVersion' => false,
|
|
|
|
'missingMinOwnCloudVersion' => false,
|
|
|
|
'canInstall' => true,
|
2018-06-05 15:07:04 +00:00
|
|
|
'screenshot' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
|
2016-10-27 15:41:15 +00:00
|
|
|
'score' => $app['ratingOverall'],
|
2016-11-30 14:59:02 +00:00
|
|
|
'ratingNumOverall' => $app['ratingNumOverall'],
|
2018-05-30 07:38:27 +00:00
|
|
|
'ratingNumThresholdReached' => $app['ratingNumOverall'] > 5,
|
2016-10-27 15:41:15 +00:00
|
|
|
'removable' => $existsLocally,
|
|
|
|
'active' => $this->appManager->isEnabledForUser($app['id']),
|
|
|
|
'needsDownload' => !$existsLocally,
|
2016-10-31 10:07:54 +00:00
|
|
|
'groups' => $groups,
|
2016-10-31 16:08:11 +00:00
|
|
|
'fromAppStore' => true,
|
2018-05-30 07:38:27 +00:00
|
|
|
'appstoreData' => $app,
|
2016-10-27 15:41:15 +00:00
|
|
|
];
|
|
|
|
}
|
2014-10-15 19:59:16 +00:00
|
|
|
|
2016-10-27 15:41:15 +00:00
|
|
|
return $formattedApps;
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 09:02:08 +00:00
|
|
|
/**
|
|
|
|
* @PasswordConfirmationRequired
|
|
|
|
*
|
|
|
|
* @param string $appId
|
2018-05-22 06:58:07 +00:00
|
|
|
* @param array $groups
|
2018-01-18 09:02:08 +00:00
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
2018-05-22 06:58:07 +00:00
|
|
|
public function enableApp(string $appId, array $groups = []): JSONResponse {
|
2018-01-18 09:02:08 +00:00
|
|
|
return $this->enableApps([$appId], $groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable one or more apps
|
|
|
|
*
|
|
|
|
* apps will be enabled for specific groups only if $groups is defined
|
|
|
|
*
|
|
|
|
* @PasswordConfirmationRequired
|
|
|
|
* @param array $appIds
|
|
|
|
* @param array $groups
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function enableApps(array $appIds, array $groups = []): JSONResponse {
|
|
|
|
try {
|
|
|
|
$updateRequired = false;
|
|
|
|
|
|
|
|
foreach ($appIds as $appId) {
|
|
|
|
$appId = OC_App::cleanAppId($appId);
|
2018-05-23 17:51:22 +00:00
|
|
|
|
|
|
|
// Check if app is already downloaded
|
|
|
|
/** @var Installer $installer */
|
|
|
|
$installer = \OC::$server->query(Installer::class);
|
|
|
|
$isDownloaded = $installer->isDownloaded($appId);
|
|
|
|
|
|
|
|
if(!$isDownloaded) {
|
|
|
|
$installer->downloadApp($appId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$installer->installApp($appId);
|
|
|
|
|
2018-01-18 09:02:08 +00:00
|
|
|
if (count($groups) > 0) {
|
|
|
|
$this->appManager->enableAppForGroups($appId, $this->getGroupList($groups));
|
|
|
|
} else {
|
|
|
|
$this->appManager->enableApp($appId);
|
|
|
|
}
|
|
|
|
if (\OC_App::shouldUpgrade($appId)) {
|
|
|
|
$updateRequired = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->logger->logException($e);
|
|
|
|
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:38:27 +00:00
|
|
|
private function getGroupList(array $groups) {
|
|
|
|
$groupManager = \OC::$server->getGroupManager();
|
|
|
|
$groupsList = [];
|
|
|
|
foreach ($groups as $group) {
|
|
|
|
$groupItem = $groupManager->get($group);
|
|
|
|
if ($groupItem instanceof \OCP\IGroup) {
|
|
|
|
$groupsList[] = $groupManager->get($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $groupsList;
|
|
|
|
}
|
|
|
|
|
2018-01-18 09:02:08 +00:00
|
|
|
/**
|
|
|
|
* @PasswordConfirmationRequired
|
|
|
|
*
|
|
|
|
* @param string $appId
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function disableApp(string $appId): JSONResponse {
|
|
|
|
return $this->disableApps([$appId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PasswordConfirmationRequired
|
|
|
|
*
|
|
|
|
* @param array $appIds
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function disableApps(array $appIds): JSONResponse {
|
|
|
|
try {
|
|
|
|
foreach ($appIds as $appId) {
|
|
|
|
$appId = OC_App::cleanAppId($appId);
|
|
|
|
$this->appManager->disableApp($appId);
|
|
|
|
}
|
|
|
|
return new JSONResponse([]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->logger->logException($e);
|
|
|
|
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PasswordConfirmationRequired
|
|
|
|
*
|
|
|
|
* @param string $appId
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function uninstallApp(string $appId): JSONResponse {
|
|
|
|
$appId = OC_App::cleanAppId($appId);
|
2018-05-29 15:52:50 +00:00
|
|
|
$result = $this->installer->removeApp($appId);
|
2018-01-18 09:02:08 +00:00
|
|
|
if($result !== false) {
|
2018-06-02 06:48:33 +00:00
|
|
|
$this->appManager->clearAppsCache();
|
2018-01-18 09:02:08 +00:00
|
|
|
return new JSONResponse(['data' => ['appid' => $appId]]);
|
|
|
|
}
|
|
|
|
return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t remove app.')]], Http::STATUS_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:52:50 +00:00
|
|
|
/**
|
|
|
|
* @param string $appId
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function updateApp(string $appId): JSONResponse {
|
2018-01-18 09:02:08 +00:00
|
|
|
$appId = OC_App::cleanAppId($appId);
|
|
|
|
|
|
|
|
$this->config->setSystemValue('maintenance', true);
|
|
|
|
try {
|
2018-05-29 15:52:50 +00:00
|
|
|
$result = $this->installer->updateAppstoreApp($appId);
|
2018-01-18 09:02:08 +00:00
|
|
|
$this->config->setSystemValue('maintenance', false);
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
$this->config->setSystemValue('maintenance', false);
|
|
|
|
return new JSONResponse(['data' => ['message' => $ex->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result !== false) {
|
|
|
|
return new JSONResponse(['data' => ['appid' => $appId]]);
|
|
|
|
}
|
|
|
|
return new JSONResponse(['data' => ['message' => $this->l10n->t('Couldn\'t update app.')]], Http::STATUS_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
2018-05-29 15:52:50 +00:00
|
|
|
|
2018-05-30 07:38:27 +00:00
|
|
|
private function sortApps($a, $b) {
|
|
|
|
$a = (string)$a['name'];
|
|
|
|
$b = (string)$b['name'];
|
|
|
|
if ($a === $b) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ($a < $b) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|