summaryrefslogtreecommitdiffstats
path: root/lib/private/app
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-02-23 16:03:32 +0100
committerVincent Petry <pvince81@owncloud.com>2015-02-23 16:03:32 +0100
commit4290e1990ec7d04a06298df9aad4c4fd8519f9aa (patch)
treedbb8c02e3f7a3d008b554931d8888f81dcb79b5c /lib/private/app
parent81760321765272f638bf50487518860374ffb7f0 (diff)
parent5542fafd3696033ea8bfdcc441c05522cf6a5736 (diff)
downloadnextcloud-server-4290e1990ec7d04a06298df9aad4c4fd8519f9aa.tar.gz
nextcloud-server-4290e1990ec7d04a06298df9aad4c4fd8519f9aa.zip
Merge pull request #13829 from owncloud/appmanager-list
Better caching for enabled apps
Diffstat (limited to 'lib/private/app')
-rw-r--r--lib/private/app/appmanager.php71
1 files changed, 53 insertions, 18 deletions
diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php
index ec7e6c80c56..66a52935a2f 100644
--- a/lib/private/app/appmanager.php
+++ b/lib/private/app/appmanager.php
@@ -24,6 +24,7 @@ namespace OC\App;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IGroupManager;
+use OCP\IUser;
use OCP\IUserSession;
class AppManager implements IAppManager {
@@ -61,7 +62,7 @@ class AppManager implements IAppManager {
/**
* @return string[] $appId => $enabled
*/
- private function getInstalledApps() {
+ private function getInstalledAppsValues() {
if (!$this->installedAppsCache) {
$values = $this->appConfig->getValues(false, 'enabled');
$this->installedAppsCache = array_filter($values, function ($value) {
@@ -73,6 +74,29 @@ class AppManager implements IAppManager {
}
/**
+ * List all installed apps
+ *
+ * @return string[]
+ */
+ public function getInstalledApps() {
+ return array_keys($this->getInstalledAppsValues());
+ }
+
+ /**
+ * List all apps enabled for a user
+ *
+ * @param \OCP\IUser $user
+ * @return string[]
+ */
+ public function getEnabledAppsForUser(IUser $user) {
+ $apps = $this->getInstalledAppsValues();
+ $appsForUser = array_filter($apps, function ($enabled) use ($user) {
+ return $this->checkAppForUser($enabled, $user);
+ });
+ return array_keys($appsForUser);
+ }
+
+ /**
* Check if an app is enabled for user
*
* @param string $appId
@@ -83,24 +107,32 @@ class AppManager implements IAppManager {
if (is_null($user)) {
$user = $this->userSession->getUser();
}
- $installedApps = $this->getInstalledApps();
+ $installedApps = $this->getInstalledAppsValues();
if (isset($installedApps[$appId])) {
- $enabled = $installedApps[$appId];
- if ($enabled === 'yes') {
- return true;
- } elseif (is_null($user)) {
- return false;
- } else {
- $groupIds = json_decode($enabled);
- $userGroups = $this->groupManager->getUserGroupIds($user);
- foreach ($userGroups as $groupId) {
- if (array_search($groupId, $groupIds) !== false) {
- return true;
- }
+ return $this->checkAppForUser($installedApps[$appId], $user);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @param string $enabled
+ * @param IUser $user
+ * @return bool
+ */
+ private function checkAppForUser($enabled, $user) {
+ if ($enabled === 'yes') {
+ return true;
+ } elseif (is_null($user)) {
+ return false;
+ } else {
+ $groupIds = json_decode($enabled);
+ $userGroups = $this->groupManager->getUserGroupIds($user);
+ foreach ($userGroups as $groupId) {
+ if (array_search($groupId, $groupIds) !== false) {
+ return true;
}
- return false;
}
- } else {
return false;
}
}
@@ -112,7 +144,7 @@ class AppManager implements IAppManager {
* @return bool
*/
public function isInstalled($appId) {
- $installedApps = $this->getInstalledApps();
+ $installedApps = $this->getInstalledAppsValues();
return isset($installedApps[$appId]);
}
@@ -122,6 +154,7 @@ class AppManager implements IAppManager {
* @param string $appId
*/
public function enableApp($appId) {
+ $this->installedAppsCache[$appId] = 'yes';
$this->appConfig->setValue($appId, 'enabled', 'yes');
}
@@ -136,6 +169,7 @@ class AppManager implements IAppManager {
/** @var \OCP\IGroup $group */
return $group->getGID();
}, $groups);
+ $this->installedAppsCache[$appId] = json_encode($groupIds);
$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
}
@@ -146,9 +180,10 @@ class AppManager implements IAppManager {
* @throws \Exception if app can't be disabled
*/
public function disableApp($appId) {
- if($appId === 'files') {
+ if ($appId === 'files') {
throw new \Exception("files can't be disabled.");
}
+ unset($this->installedAppsCache[$appId]);
$this->appConfig->setValue($appId, 'enabled', 'no');
}
}