]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(OC/Template): Remove usage of deprecated functions in `JSResourceLocator`
authorFerdinand Thiessen <rpm@fthiessen.de>
Tue, 10 Jan 2023 00:06:26 +0000 (01:06 +0100)
committerFerdinand Thiessen <rpm@fthiessen.de>
Wed, 22 Feb 2023 20:19:37 +0000 (21:19 +0100)
Move from `\OC_App::getAppPath` to `IAppManager::getAppPath`.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
lib/private/Template/JSResourceLocator.php

index 7648c7953f30a6c7f4de92b0165ad12e653e38b4..0745451bbd5a764f06be7d34ba283b386fc289f6 100644 (file)
  */
 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);