Merge pull request #5923 from christianbeeznest/ofaj-22174

Internal: Fix 500 error on legacy pages for unauthenticated access; redirect to login - refs BT#22174
pull/5930/head
Nicolas Ducoulombier 10 months ago committed by GitHub
commit c1f78cfaac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      public/main/inc/global.inc.php

@ -3,12 +3,15 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Controller\ExceptionController;
use Chamilo\CoreBundle\EventListener\ExceptionListener;
use Chamilo\CoreBundle\Framework\Container;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
// Use when running PHPUnit tests.
if (isset($fileToLoad)) {
@ -81,6 +84,26 @@ if ($isCli) {
$context = $router->getContext();
$router->setContext($context);
set_exception_handler(function ($exception) use ($kernel, $container) {
$request = Request::createFromGlobals();
$event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception);
$listener = $container->get(ExceptionListener::class);
if (is_callable([$listener, '__invoke'])) {
$listener->__invoke($event);
} else {
$response = new Response('Error occurred', Response::HTTP_INTERNAL_SERVER_ERROR);
$response->send();
return;
}
$response = $event->getResponse();
if ($response) {
$response->send();
} else {
$response = new Response('An error occurred', Response::HTTP_INTERNAL_SERVER_ERROR);
$response->send();
}
});
$context = Container::getRouter()->getContext();
$currentUri = $request->getRequestUri();

Loading…
Cancel
Save