diff --git a/public/main/inc/global.inc.php b/public/main/inc/global.inc.php index 5bd8c5d599..956dba0249 100644 --- a/public/main/inc/global.inc.php +++ b/public/main/inc/global.inc.php @@ -58,24 +58,37 @@ if (!empty($flashBag->keys())) { $response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false); $context = Container::getRouter()->getContext(); -$pos = strpos($currentBaseUrl, 'main'); -$posPlugin = strpos($currentBaseUrl, 'plugin'); -$posCertificate = strpos($currentBaseUrl, 'certificate'); - -if (false === $pos && false === $posPlugin && false === $posCertificate) { - echo 'Cannot load current URL'; - exit; +$isCli = 'cli' === php_sapi_name(); +$baseUrl = null; +if ($isCli) { + $cliOptions = getopt('', ['url:']); + if (!empty($cliOptions['url'])) { + $baseUrl = $cliOptions['url']; + } } -if (false !== $pos) { - $newBaseUrl = substr($currentBaseUrl, 0, $pos - 1); -}elseif (false !== $posPlugin) { - $newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); -} elseif (false !== $posCertificate) { - $newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); -} +if ($isCli && $baseUrl) { + $context->setBaseUrl($baseUrl); +} else { + $pos = strpos($currentBaseUrl, 'main'); + $posPlugin = strpos($currentBaseUrl, 'plugin'); + $posCertificate = strpos($currentBaseUrl, 'certificate'); -$context->setBaseUrl($newBaseUrl); + if (false === $pos && false === $posPlugin && false === $posCertificate) { + echo 'Cannot load current URL'; + exit; + } + + if (false !== $pos) { + $newBaseUrl = substr($currentBaseUrl, 0, $pos - 1); + }elseif (false !== $posPlugin) { + $newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); + } elseif (false !== $posCertificate) { + $newBaseUrl = substr($currentBaseUrl, 0, $posPlugin - 1); + } + + $context->setBaseUrl($newBaseUrl); +} try { // Load legacy configuration.php diff --git a/tests/scripts/disable_user_conditions.php b/tests/scripts/disable_user_conditions.php index dfdbb627e2..91642f807b 100644 --- a/tests/scripts/disable_user_conditions.php +++ b/tests/scripts/disable_user_conditions.php @@ -1,6 +1,6 @@