Skip to content

Commit

Permalink
Merge pull request #31882 from nextcloud/backport/31876/stable23
Browse files Browse the repository at this point in the history
[stable23] Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
  • Loading branch information
nickvergessen authored Apr 11, 2022
2 parents 4a3f07b + 8f77199 commit 1f5f2fc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,21 @@ 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.
\OC::$server->get(LoggerInterface::class)->error('Failed to detect current app from script path', ['exception' => $e]);
return '';
}
if ($path_info) {
$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
}
Expand Down

0 comments on commit 1f5f2fc

Please sign in to comment.