Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Apr 7, 2022
commit a06ba8850243b93295e9c49ab820c0c46d9b220a
11 changes: 10 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,20 @@ public static function getSettingsNavigation(): array {
* @return string
*/
public static function getCurrentApp(): string {
if (\OC::$CLI) {
return '';
}
Comment on lines +632 to +634
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related? What does it fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the case when this is called via cron/cli/occ
We don't need to do anything in that case, but it's not set to true when running tests


$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);
}
Expand Down