summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2022-04-07 17:09:51 +0200
committerGitHub <noreply@github.com>2022-04-07 17:09:51 +0200
commit018ca43c096c9ab5de0c0388e60ea494ac0480a4 (patch)
tree5ba4b050adb2d73fcba4520a222ee11f9a410d14 /lib
parent7ff60b824900412a017bf2c775cc0f8f7cb7edc7 (diff)
parentd96633916cb9fba6dc2ed522f7e449e725deeacd (diff)
downloadnextcloud-server-018ca43c096c9ab5de0c0388e60ea494ac0480a4.tar.gz
nextcloud-server-018ca43c096c9ab5de0c0388e60ea494ac0480a4.zip
Merge pull request #31876 from nextcloud/bugfix/noid/fix-getCurrentApp-from-cli
Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/OC_App.php12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index ca01e91216b..f290b7a610c 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -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);
}