From a06ba8850243b93295e9c49ab820c0c46d9b220a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Apr 2022 14:08:37 +0200 Subject: [PATCH 1/2] Fix \OC_App::getCurrentApp() when being called from CLI or phpunit Signed-off-by: Joas Schilling --- lib/private/legacy/OC_App.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ca01e91216b75..245bfe76d985c 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -629,11 +629,20 @@ public static function getSettingsNavigation(): array { * @return string */ public static function getCurrentApp(): string { + if (\OC::$CLI) { + return ''; + } + $request = \OC::$server->getRequest(); $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); $topFolder = substr($script, 0, strpos($script, '/') ?: 0); if (empty($topFolder)) { - $path_info = $request->getPathInfo(); + try { + $path_info = $request->getPathInfo(); + } catch (Exception $e) { + // Can happen from unit tests because the script name is `./vendor/bin/phpunit` or something a like then. + return ''; + } if ($path_info) { $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); } From d96633916cb9fba6dc2ed522f7e449e725deeacd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Apr 2022 14:45:58 +0200 Subject: [PATCH 2/2] Log exception Signed-off-by: Joas Schilling --- lib/private/legacy/OC_App.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 245bfe76d985c..f290b7a610c67 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -641,6 +641,7 @@ public static function getCurrentApp(): string { $path_info = $request->getPathInfo(); } catch (Exception $e) { // Can happen from unit tests because the script name is `./vendor/bin/phpunit` or something a like then. + \OC::$server->get(LoggerInterface::class)->error('Failed to detect current app from script path', ['exception' => $e]); return ''; } if ($path_info) {