Skip to content

Commit 018ca43

Browse files
authored
Merge pull request #31876 from nextcloud/bugfix/noid/fix-getCurrentApp-from-cli
Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
2 parents 7ff60b8 + d966339 commit 018ca43

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/private/legacy/OC_App.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,21 @@ public static function getSettingsNavigation(): array {
629629
* @return string
630630
*/
631631
public static function getCurrentApp(): string {
632+
if (\OC::$CLI) {
633+
return '';
634+
}
635+
632636
$request = \OC::$server->getRequest();
633637
$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
634638
$topFolder = substr($script, 0, strpos($script, '/') ?: 0);
635639
if (empty($topFolder)) {
636-
$path_info = $request->getPathInfo();
640+
try {
641+
$path_info = $request->getPathInfo();
642+
} catch (Exception $e) {
643+
// Can happen from unit tests because the script name is `./vendor/bin/phpunit` or something a like then.
644+
\OC::$server->get(LoggerInterface::class)->error('Failed to detect current app from script path', ['exception' => $e]);
645+
return '';
646+
}
637647
if ($path_info) {
638648
$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
639649
}

0 commit comments

Comments
 (0)