From dbb1fa12738e4d30ed22deffa0b2dd921f96af04 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 10 Jan 2023 01:06:26 +0100 Subject: [PATCH] fix(OC/Template): Remove usage of deprecated functions in `JSResourceLocator` Move from `\OC_App::getAppPath` to `IAppManager::getAppPath`. Signed-off-by: Ferdinand Thiessen --- lib/private/Template/JSResourceLocator.php | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php index 7648c7953f3..0745451bbd5 100644 --- a/lib/private/Template/JSResourceLocator.php +++ b/lib/private/Template/JSResourceLocator.php @@ -27,16 +27,22 @@ */ namespace OC\Template; +use OCP\App\AppPathNotFoundException; use Psr\Log\LoggerInterface; +use \OCP\App\IAppManager; class JSResourceLocator extends ResourceLocator { /** @var JSCombiner */ protected $jsCombiner; - public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner) { + /** @var IAppManager */ + protected $appManager; + + public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner, IAppManager $appManager) { parent::__construct($logger); $this->jsCombiner = $JSCombiner; + $this->appManager = $appManager; } /** @@ -80,14 +86,23 @@ class JSResourceLocator extends ResourceLocator { } $script = substr($script, strpos($script, '/') + 1); - $app_path = \OC_App::getAppPath($app); - $app_url = \OC_App::getAppWebPath($app); + $app_path = false; + $app_url = false; - if ($app_path !== false) { + try { + $app_path = $this->appManager->getAppPath($app); // Account for the possibility of having symlinks in app path. Only // do this if $app_path is set, because an empty argument to realpath // gets turned into cwd. $app_path = realpath($app_path); + } catch (AppPathNotFoundException) { + // pass + } + + try { + $app_url = $this->appManager->getAppWebPath($app); + } catch (AppPathNotFoundException) { + // pass } // missing translations files fill be ignored @@ -122,7 +137,12 @@ class JSResourceLocator extends ResourceLocator { } else { // Add all the files from the json $files = $this->jsCombiner->getContent($root, $file); - $app_url = \OC_App::getAppWebPath($app); + $app_url = null; + try { + $app_url = $this->appManager->getAppWebPath($app); + } catch (AppPathNotFoundException) { + // pass + } foreach ($files as $jsFile) { $this->append($root, $jsFile, $app_url); -- 2.39.5