aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/App
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-04-22 15:50:06 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-04-22 15:50:06 +0200
commitac1d868d18074752029a9f4fdeda6614daa62010 (patch)
tree0776d206f015910c14cf4302fa369077474a1445 /lib/private/App
parent61621ee1d048802249602cb91fad7df437ad16de (diff)
downloadnextcloud-server-ac1d868d18074752029a9f4fdeda6614daa62010.tar.gz
nextcloud-server-ac1d868d18074752029a9f4fdeda6614daa62010.zip
fix: Lazy load IURLGenerator from AppManager to avoid installation crash
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/App')
-rw-r--r--lib/private/App/AppManager.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php
index 65a1e9e1e7e..3867dcc509e 100644
--- a/lib/private/App/AppManager.php
+++ b/lib/private/App/AppManager.php
@@ -98,7 +98,12 @@ class AppManager implements IAppManager {
private array $loadedApps = [];
private ?AppConfig $appConfig = null;
+ private ?IURLGenerator $urlGenerator = null;
+ /**
+ * Be extremely careful when injecting classes here. The AppManager is used by the installer,
+ * so it needs to work before installation. See how AppConfig and IURLGenerator are injected for reference
+ */
public function __construct(
private IUserSession $userSession,
private IConfig $config,
@@ -106,7 +111,6 @@ class AppManager implements IAppManager {
private ICacheFactory $memCacheFactory,
private IEventDispatcher $dispatcher,
private LoggerInterface $logger,
- private IURLGenerator $urlGenerator,
) {
}
@@ -115,7 +119,7 @@ class AppManager implements IAppManager {
$icon = null;
foreach ($possibleIcons as $iconName) {
try {
- $icon = $this->urlGenerator->imagePath($appId, $iconName);
+ $icon = $this->getUrlGenerator()->imagePath($appId, $iconName);
break;
} catch (\RuntimeException $e) {
// ignore
@@ -135,6 +139,17 @@ class AppManager implements IAppManager {
return $this->appConfig;
}
+ private function getUrlGenerator(): IURLGenerator {
+ if ($this->urlGenerator !== null) {
+ return $this->urlGenerator;
+ }
+ if (!$this->config->getSystemValueBool('installed', false)) {
+ throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
+ }
+ $this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
+ return $this->urlGenerator;
+ }
+
/**
* @return string[] $appId => $enabled
*/