Skip to content

Commit eef3b98

Browse files
authored
Internal: Include session when running cli with legacy code (#5790)
1 parent 153fdb1 commit eef3b98

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ services:
110110
- setKernel: [ '@kernel' ]
111111
- setMessengerBus: [ '@messenger.bus.default' ]
112112
- setValidator: [ '@validator' ]
113+
- setSessionFactory: [ '@session.factory' ]
113114

114115
cocur_slugify:
115116
lowercase: true

public/main/inc/global.inc.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,21 @@
4646
}
4747

4848
$container = $kernel->getContainer();
49+
Container::setContainer($container);
50+
$session = Container::getLegacyHelper()->getSession();
51+
$request = Request::create('/');
52+
$request->setSession($session);
53+
$container->get('request_stack')->push($request);
54+
Container::setLegacyServices($container);
4955
$router = $container->get('router');
5056
$context = $router->getContext();
5157
$router->setContext($context);
52-
Database::setManager($container->get('doctrine.orm.entity_manager'));
5358

5459
$cliOptions = getopt('', ['url:']);
5560
if (!empty($cliOptions['url'])) {
5661
$baseUrl = $cliOptions['url'];
5762
$context->setBaseUrl($baseUrl);
5863
}
59-
60-
echo "CLI mode: EntityManager initialized.\n";
61-
6264
} else {
6365
$kernel = new Chamilo\Kernel($env, $debug);
6466
// Loading Request from Sonata. In order to use Sonata Pages Bundle.

src/CoreBundle/ServiceHelper/ContainerHelper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Chamilo\CoreBundle\ServiceHelper;
88

9+
use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface;
10+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
911
use Symfony\Component\HttpKernel\KernelInterface;
1012
use Symfony\Component\Messenger\MessageBusInterface;
1113
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -19,6 +21,7 @@ class ContainerHelper
1921
private KernelInterface $kernel;
2022
private MessageBusInterface $messengerBus;
2123
private ValidatorInterface $validator;
24+
private SessionFactoryInterface $sessionFactory;
2225

2326
public function getAuthorizationChecker(): AuthorizationCheckerInterface
2427
{
@@ -69,4 +72,16 @@ public function setValidator(ValidatorInterface $validator): void
6972
{
7073
$this->validator = $validator;
7174
}
75+
76+
public function getSession(): SessionInterface
77+
{
78+
return $this->sessionFactory->createSession();
79+
}
80+
81+
public function setSessionFactory(SessionFactoryInterface $sessionFactory): ContainerHelper
82+
{
83+
$this->sessionFactory = $sessionFactory;
84+
85+
return $this;
86+
}
7287
}

0 commit comments

Comments
 (0)