aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/App/AppManager.php
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-03-06 14:17:14 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-04-22 12:17:31 +0200
commit0e7bac72ae9e6096fe79c460bc2ef963619aa226 (patch)
tree046cfc07a8c8f03612b99d9c410c1001c849ca45 /lib/private/App/AppManager.php
parent8c5f32320a3ceeb9aac86bb2340d0919adf37993 (diff)
downloadnextcloud-server-0e7bac72ae9e6096fe79c460bc2ef963619aa226.tar.gz
nextcloud-server-0e7bac72ae9e6096fe79c460bc2ef963619aa226.zip
fix: Make sure that AppManager can be built before Nextcloud is installed
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/App/AppManager.php')
-rw-r--r--lib/private/App/AppManager.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php
index c6e6ba2975e..65a1e9e1e7e 100644
--- a/lib/private/App/AppManager.php
+++ b/lib/private/App/AppManager.php
@@ -97,10 +97,11 @@ class AppManager implements IAppManager {
/** @var array<string, true> */
private array $loadedApps = [];
+ private ?AppConfig $appConfig = null;
+
public function __construct(
private IUserSession $userSession,
private IConfig $config,
- private AppConfig $appConfig,
private IGroupManager $groupManager,
private ICacheFactory $memCacheFactory,
private IEventDispatcher $dispatcher,
@@ -123,12 +124,23 @@ class AppManager implements IAppManager {
return $icon;
}
+ private function getAppConfig(): AppConfig {
+ if ($this->appConfig !== null) {
+ return $this->appConfig;
+ }
+ if (!$this->config->getSystemValueBool('installed', false)) {
+ throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
+ }
+ $this->appConfig = \OCP\Server::get(AppConfig::class);
+ return $this->appConfig;
+ }
+
/**
* @return string[] $appId => $enabled
*/
private function getInstalledAppsValues(): array {
if (!$this->installedAppsCache) {
- $values = $this->appConfig->getValues(false, 'enabled');
+ $values = $this->getAppConfig()->getValues(false, 'enabled');
$alwaysEnabledApps = $this->getAlwaysEnabledApps();
foreach ($alwaysEnabledApps as $appId) {
@@ -253,7 +265,7 @@ class AppManager implements IAppManager {
private function getAppTypes(string $app): array {
//load the cache
if (count($this->appTypes) === 0) {
- $this->appTypes = $this->appConfig->getValues(false, 'types') ?: [];
+ $this->appTypes = $this->getAppConfig()->getValues(false, 'types') ?: [];
}
if (isset($this->appTypes[$app])) {
@@ -541,7 +553,7 @@ class AppManager implements IAppManager {
}
$this->installedAppsCache[$appId] = 'yes';
- $this->appConfig->setValue($appId, 'enabled', 'yes');
+ $this->getAppConfig()->setValue($appId, 'enabled', 'yes');
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
ManagerEvent::EVENT_APP_ENABLE, $appId
@@ -595,7 +607,7 @@ class AppManager implements IAppManager {
}, $groups);
$this->installedAppsCache[$appId] = json_encode($groupIds);
- $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
+ $this->getAppConfig()->setValue($appId, 'enabled', json_encode($groupIds));
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
@@ -616,7 +628,7 @@ class AppManager implements IAppManager {
}
if ($automaticDisabled) {
- $previousSetting = $this->appConfig->getValue($appId, 'enabled', 'yes');
+ $previousSetting = $this->getAppConfig()->getValue($appId, 'enabled', 'yes');
if ($previousSetting !== 'yes' && $previousSetting !== 'no') {
$previousSetting = json_decode($previousSetting, true);
}
@@ -624,7 +636,7 @@ class AppManager implements IAppManager {
}
unset($this->installedAppsCache[$appId]);
- $this->appConfig->setValue($appId, 'enabled', 'no');
+ $this->getAppConfig()->setValue($appId, 'enabled', 'no');
// run uninstall steps
$appData = $this->getAppInfo($appId);
@@ -689,7 +701,7 @@ class AppManager implements IAppManager {
$apps = $this->getInstalledApps();
foreach ($apps as $appId) {
$appInfo = $this->getAppInfo($appId);
- $appDbVersion = $this->appConfig->getValue($appId, 'installed_version');
+ $appDbVersion = $this->getAppConfig()->getValue($appId, 'installed_version');
if ($appDbVersion
&& isset($appInfo['version'])
&& version_compare($appInfo['version'], $appDbVersion, '>')