From 883b931d87eaaf9863b677a280cadf65b0a03b1d Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 25 Jun 2021 18:02:08 +0200 Subject: [PATCH 1/2] fix getInstalledApps and add getEnabledApps Signed-off-by: szaimen --- lib/private/App/AppManager.php | 31 ++++++++++++++++++++++++++++++- lib/public/App/IAppManager.php | 8 ++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 388a743b93696..e79f970daaaed 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -132,7 +132,7 @@ private function getInstalledAppsValues() { } $this->installedAppsCache = array_filter($values, function ($value) { - return $value !== 'no'; + return $value !== ''; }); ksort($this->installedAppsCache); } @@ -147,6 +147,35 @@ private function getInstalledAppsValues() { public function getInstalledApps() { return array_keys($this->getInstalledAppsValues()); } + + /** + * @return string[] $appId => $enabled + */ + private function getEnabledAppsValues() { + if (!$this->enabledAppsCache) { + $values = $this->appConfig->getValues(false, 'enabled'); + + $alwaysEnabledApps = $this->getAlwaysEnabledApps(); + foreach ($alwaysEnabledApps as $appId) { + $values[$appId] = 'yes'; + } + + $this->enabledAppsCache = array_filter($values, function ($value) { + return $value !== 'no'; + }); + ksort($this->enabledAppsCache); + } + return $this->enabledAppsCache; + } + + /** + * List all enabled apps + * + * @return string[] + */ + public function getEnabledApps() { + return array_keys($this->getEnabledAppsValues()); + } /** * List all apps enabled for a user diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index 645d5ffd97c9a..df525b4345365 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -156,6 +156,14 @@ public function getEnabledAppsForUser(IUser $user); */ public function getInstalledApps(); + /** + * List all enabled apps + * + * @return string[] + * @since 23.0.0 + */ + public function getEnabledApps(); + /** * Clear the cached list of apps when enabling/disabling an app * @since 8.1.0 From c7f0572ee33da166b16f1fee34684f6c1b90f010 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 25 Jun 2021 18:09:56 +0200 Subject: [PATCH 2/2] initialize enabledAppsCache Signed-off-by: szaimen --- lib/private/App/AppManager.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index e79f970daaaed..f2120a925d7d4 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -88,6 +88,9 @@ class AppManager implements IAppManager { /** @var string[] $appId => $enabled */ private $installedAppsCache; + /** @var string[] $appId => $enabled */ + private $enabledAppsCache; + /** @var string[] */ private $shippedApps;