2014-10-15 19:59:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Lukas Reschke
|
|
|
|
* @author Thomas Müller
|
|
|
|
* @copyright 2014 Lukas Reschke lukas@owncloud.com, 2014 Thomas Müller deepdiver@owncloud.com
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Settings\Controller;
|
|
|
|
|
2014-12-01 20:47:22 +00:00
|
|
|
use OC\App\DependencyAnalyzer;
|
|
|
|
use OC\App\Platform;
|
2014-10-15 19:59:16 +00:00
|
|
|
use \OCP\AppFramework\Controller;
|
2015-01-09 17:31:39 +00:00
|
|
|
use OCP\ICacheFactory;
|
2014-10-15 19:59:16 +00:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OC\Settings\Controller
|
|
|
|
*/
|
|
|
|
class AppSettingsController extends Controller {
|
|
|
|
|
|
|
|
/** @var \OCP\IL10N */
|
|
|
|
private $l10n;
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2015-01-09 17:31:39 +00:00
|
|
|
/** @var \OCP\ICache */
|
|
|
|
private $cache;
|
2014-10-15 19:59:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IL10N $l10n
|
|
|
|
* @param IConfig $config
|
2015-01-09 17:31:39 +00:00
|
|
|
* @param ICacheFactory $cache
|
2014-10-15 19:59:16 +00:00
|
|
|
*/
|
|
|
|
public function __construct($appName,
|
|
|
|
IRequest $request,
|
|
|
|
IL10N $l10n,
|
2015-01-09 17:31:39 +00:00
|
|
|
IConfig $config,
|
|
|
|
ICacheFactory $cache) {
|
2014-10-15 19:59:16 +00:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->l10n = $l10n;
|
|
|
|
$this->config = $config;
|
2015-01-09 17:31:39 +00:00
|
|
|
$this->cache = $cache->create($appName);
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all available categories
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function listCategories() {
|
|
|
|
|
2015-01-09 17:31:39 +00:00
|
|
|
if(!is_null($this->cache->get('listCategories'))) {
|
|
|
|
return $this->cache->get('listCategories');
|
|
|
|
}
|
|
|
|
$categories = [
|
|
|
|
['id' => 0, 'displayName' => (string)$this->l10n->t('Enabled')],
|
|
|
|
['id' => 1, 'displayName' => (string)$this->l10n->t('Not enabled')],
|
|
|
|
];
|
2014-10-15 19:59:16 +00:00
|
|
|
|
|
|
|
if($this->config->getSystemValue('appstoreenabled', true)) {
|
2015-01-09 17:31:39 +00:00
|
|
|
$categories[] = ['id' => 2, 'displayName' => (string)$this->l10n->t('Recommended')];
|
2014-10-15 19:59:16 +00:00
|
|
|
// apps from external repo via OCS
|
|
|
|
$ocs = \OC_OCSClient::getCategories();
|
|
|
|
foreach($ocs as $k => $v) {
|
|
|
|
$categories[] = array(
|
|
|
|
'id' => $k,
|
|
|
|
'displayName' => str_replace('ownCloud ', '', $v)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$categories['status'] = 'success';
|
2015-01-09 17:31:39 +00:00
|
|
|
$this->cache->set('listCategories', $categories, 3600);
|
2014-10-15 19:59:16 +00:00
|
|
|
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all available categories
|
|
|
|
* @param int $category
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function listApps($category = 0) {
|
2015-01-09 17:31:39 +00:00
|
|
|
if(!is_null($this->cache->get('listApps-'.$category))) {
|
|
|
|
$apps = $this->cache->get('listApps-'.$category);
|
|
|
|
} else {
|
|
|
|
switch ($category) {
|
|
|
|
// installed apps
|
|
|
|
case 0:
|
|
|
|
$apps = \OC_App::listAllApps(true);
|
|
|
|
$apps = array_filter($apps, function ($app) {
|
|
|
|
return $app['active'];
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
// not-installed apps
|
|
|
|
case 1:
|
|
|
|
$apps = \OC_App::listAllApps(true);
|
|
|
|
$apps = array_filter($apps, function ($app) {
|
|
|
|
return !$app['active'];
|
2014-10-15 19:59:16 +00:00
|
|
|
});
|
2015-01-09 17:31:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ($category === 2) {
|
|
|
|
$apps = \OC_App::getAppstoreApps('approved');
|
|
|
|
$apps = array_filter($apps, function ($app) {
|
|
|
|
return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$apps = \OC_App::getAppstoreApps('approved', $category);
|
|
|
|
}
|
|
|
|
if (!$apps) {
|
|
|
|
$apps = array();
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
2015-01-09 17:31:39 +00:00
|
|
|
usort($apps, function ($a, $b) {
|
|
|
|
$a = (int)$a['score'];
|
|
|
|
$b = (int)$b['score'];
|
|
|
|
if ($a === $b) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ($a > $b) ? -1 : 1;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fix groups to be an array
|
2014-12-12 11:34:53 +00:00
|
|
|
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
|
|
|
|
$apps = array_map(function($app) use ($dependencyAnalyzer) {
|
2015-01-06 12:07:17 +00:00
|
|
|
|
|
|
|
// fix groups
|
2014-10-15 19:59:16 +00:00
|
|
|
$groups = array();
|
|
|
|
if (is_string($app['groups'])) {
|
|
|
|
$groups = json_decode($app['groups']);
|
|
|
|
}
|
|
|
|
$app['groups'] = $groups;
|
|
|
|
$app['canUnInstall'] = !$app['active'] && $app['removable'];
|
2014-12-01 20:47:22 +00:00
|
|
|
|
2015-01-06 12:07:17 +00:00
|
|
|
// fix licence vs license
|
|
|
|
if (isset($app['license']) && !isset($app['licence'])) {
|
|
|
|
$app['licence'] = $app['license'];
|
|
|
|
}
|
|
|
|
|
2014-12-01 20:47:22 +00:00
|
|
|
// analyse dependencies
|
2014-12-12 11:34:53 +00:00
|
|
|
$missing = $dependencyAnalyzer->analyze($app);
|
2014-12-01 20:47:22 +00:00
|
|
|
$app['canInstall'] = empty($missing);
|
|
|
|
$app['missingDependencies'] = $missing;
|
2015-01-06 12:07:17 +00:00
|
|
|
|
2014-10-15 19:59:16 +00:00
|
|
|
return $app;
|
|
|
|
}, $apps);
|
|
|
|
|
2015-01-09 17:31:39 +00:00
|
|
|
$this->cache->set('listApps-'.$category, $apps, 300);
|
|
|
|
|
|
|
|
return ['apps' => $apps, 'status' => 'success'];
|
2014-10-15 19:59:16 +00:00
|
|
|
}
|
|
|
|
}
|