From b79420aeb0dcc8300b2e1d7bbd4f04839bfd9cbe Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 1 Jun 2022 17:04:07 -0500 Subject: [PATCH] Fix get request session from legacy container --- public/main/install/index.php | 3 +++ src/CoreBundle/Framework/Container.php | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/public/main/install/index.php b/public/main/install/index.php index c36b5dc987..c61c85ef0e 100644 --- a/public/main/install/index.php +++ b/public/main/install/index.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\ErrorHandler\Debug; +use Symfony\Component\HttpFoundation\Session\Session as HttpSession; use Symfony\Component\Translation\Loader\PoFileLoader; use Symfony\Component\Translation\Translator; @@ -78,6 +79,8 @@ $translator->addResource( ); Container::$translator = $translator; +Container::$session = new HttpSession(); + // The function api_get_setting() might be called within the installation scripts. // We need to provide some limited support for it through initialization of the // global array-type variable $_setting. diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php index 4ff329fdf1..d21ed54fb6 100644 --- a/src/CoreBundle/Framework/Container.php +++ b/src/CoreBundle/Framework/Container.php @@ -82,7 +82,8 @@ use Doctrine\ORM\EntityManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Form\FormFactory; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\SessionInterface as HttpSessionInterface; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; @@ -100,6 +101,7 @@ class Container public static ?Request $request = null; public static ?TranslatorInterface $translator = null; public static Environment $twig; + public static ?Session $session = null; public static string $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig'; public static function setContainer(ContainerInterface $container): void @@ -196,15 +198,24 @@ class Container self::$request = $request; } - public static function getSession(): SessionInterface|bool + public static function getSession(): Session|HttpSessionInterface|bool|null { - if (!empty(self::$request)) { - return self::$request->getSession(); + if (null !== self::$session) { + return self::$session; + } + + if (null !== self::$container) { + return self::$container->get('request_stack')->getSession(); } return false; } + public static function setSession(Session $session): void + { + self::$session = $session; + } + /** * @return AuthorizationChecker */