Merge pull request #31876 from nextcloud/bugfix/noid/fix-getCurrentApp-from-cli

Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
This commit is contained in:
Vincent Petry 2022-04-07 17:09:51 +02:00 committed by GitHub
commit 018ca43c09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -629,11 +629,21 @@ class OC_App {
* @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);
}