Skip to content

Commit

Permalink
Include session when running cli
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Sep 11, 2024
1 parent 3d6dd1f commit 9748198
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ services:
- setKernel: [ '@kernel' ]
- setMessengerBus: [ '@messenger.bus.default' ]
- setValidator: [ '@validator' ]
- setSessionFactory: [ '@session.factory' ]

cocur_slugify:
lowercase: true
Expand Down
9 changes: 5 additions & 4 deletions public/main/inc/global.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@

$container = $kernel->getContainer();
Container::setContainer($container);
$session = Container::getLegacyHelper()->getSession();
$request = Request::create('/');
$request->setSession($session);
$container->get('request_stack')->push($request);
Container::setLegacyServices($container);
$router = $container->get('router');
$context = $router->getContext();
$router->setContext($context);
Database::setManager($container->get('doctrine.orm.entity_manager'));

$cliOptions = getopt('', ['url:']);
if (!empty($cliOptions['url'])) {
$baseUrl = $cliOptions['url'];
$context->setBaseUrl($baseUrl);
}

echo "CLI mode: EntityManager initialized.\n";

} else {
$kernel = new Chamilo\Kernel($env, $debug);
// Loading Request from Sonata. In order to use Sonata Pages Bundle.
Expand Down
15 changes: 15 additions & 0 deletions src/CoreBundle/ServiceHelper/ContainerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Chamilo\CoreBundle\ServiceHelper;

use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
Expand All @@ -19,6 +21,7 @@ class ContainerHelper
private KernelInterface $kernel;
private MessageBusInterface $messengerBus;
private ValidatorInterface $validator;
private SessionFactoryInterface $sessionFactory;

public function getAuthorizationChecker(): AuthorizationCheckerInterface
{
Expand Down Expand Up @@ -69,4 +72,16 @@ public function setValidator(ValidatorInterface $validator): void
{
$this->validator = $validator;
}

public function getSession(): SessionInterface
{
return $this->sessionFactory->createSession();
}

public function setSessionFactory(SessionFactoryInterface $sessionFactory): ContainerHelper
{
$this->sessionFactory = $sessionFactory;

return $this;
}
}

0 comments on commit 9748198

Please sign in to comment.