diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-05-12 17:08:54 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-08-01 09:46:40 +0200 |
commit | 458c2fa2971e6595a18a289b0afeb4a79ea0e0d3 (patch) | |
tree | c0bebce50e7d6956045df53f1e51dc44b0ab6c9e /lib/private/URLGenerator.php | |
parent | 952acd4d276b3190d23e0597c5e01b1dfc4d72bc (diff) | |
download | nextcloud-server-458c2fa2971e6595a18a289b0afeb4a79ea0e0d3.tar.gz nextcloud-server-458c2fa2971e6595a18a289b0afeb4a79ea0e0d3.zip |
Remove OCP\App and OCP\BackgroundJob
Both deprecated since NC 23
IAppManager is the replacement for OCP\App unfortunately it can't be
dependency injected in classes used by the installed otherwise the
database connection is initialised too early
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib/private/URLGenerator.php')
-rw-r--r-- | lib/private/URLGenerator.php | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 47979a038ba..6115d4a221e 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -42,6 +42,8 @@ namespace OC; use OC\Route\Router; use OCA\Theming\ThemingDefaults; +use OCP\App\AppPathNotFoundException; +use OCP\App\IAppManager; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; @@ -65,12 +67,14 @@ class URLGenerator implements IURLGenerator { private $router; /** @var null|string */ private $baseUrl = null; + private ?IAppManager $appManager = null; public function __construct(IConfig $config, IUserSession $userSession, ICacheFactory $cacheFactory, IRequest $request, - Router $router) { + Router $router + ) { $this->config = $config; $this->userSession = $userSession; $this->cacheFactory = $cacheFactory; @@ -78,6 +82,14 @@ class URLGenerator implements IURLGenerator { $this->router = $router; } + private function getAppManager(): IAppManager { + if ($this->appManager !== null) { + return $this->appManager; + } + $this->appManager = \OCP\Server::get(IAppManager::class); + return $this->appManager; + } + /** * Creates an url using a defined route * @@ -132,7 +144,7 @@ class URLGenerator implements IURLGenerator { $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); if ($appName !== '') { - $app_path = \OC_App::getAppPath($appName); + $app_path = $this->getAppManager()->getAppPath($appName); // Check if the app is in the app folder if ($app_path && file_exists($app_path . '/' . $file)) { if (substr($file, -3) === 'php') { @@ -142,7 +154,7 @@ class URLGenerator implements IURLGenerator { } $urlLinkTo .= ($file !== 'index.php') ? '/' . $file : ''; } else { - $urlLinkTo = \OC_App::getAppWebPath($appName) . '/' . $file; + $urlLinkTo = $this->getAppManager()->getAppWebPath($appName) . '/' . $file; } } else { $urlLinkTo = \OC::$WEBROOT . '/' . $appName . '/' . $file; @@ -189,11 +201,20 @@ class URLGenerator implements IURLGenerator { //if a theme has a png but not an svg always use the png $basename = substr(basename($file), 0, -4); - $appPath = \OC_App::getAppPath($appName); + try { + $appPath = $this->getAppManager()->getAppPath($appName); + } catch (AppPathNotFoundException $e) { + if ($appName === 'core' || $appName === '') { + $appName = 'core'; + $appPath = false; + } else { + throw new RuntimeException('image not found: image: ' . $file . ' webroot: ' . \OC::$WEBROOT . ' serverroot: ' . \OC::$SERVERROOT); + } + } // Check if the app is in the app folder $path = ''; - $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); + $themingEnabled = $this->config->getSystemValue('installed', false) && $this->getAppManager()->isEnabledForUser('theming'); $themingImagePath = false; if ($themingEnabled) { $themingDefaults = \OC::$server->getThemingDefaults(); @@ -220,10 +241,10 @@ class URLGenerator implements IURLGenerator { } elseif ($themingEnabled && $themingImagePath) { $path = $themingImagePath; } elseif ($appPath && file_exists($appPath . "/img/$file")) { - $path = \OC_App::getAppWebPath($appName) . "/img/$file"; + $path = $this->getAppManager()->getAppWebPath($appName) . "/img/$file"; } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") && file_exists($appPath . "/img/$basename.png")) { - $path = \OC_App::getAppWebPath($appName) . "/img/$basename.png"; + $path = $this->getAppManager()->getAppWebPath($appName) . "/img/$basename.png"; } elseif (!empty($appName) and file_exists(\OC::$SERVERROOT . "/$appName/img/$file")) { $path = \OC::$WEBROOT . "/$appName/img/$file"; } elseif (!empty($appName) and (!file_exists(\OC::$SERVERROOT . "/$appName/img/$basename.svg") |