Replace deprecated get('session') and instead access session through RequestStack in ExportController.php

This commit is contained in:
2025-10-02 15:22:28 +02:00
parent aa0db40224
commit 86422a5946

View File

@@ -38,6 +38,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -57,7 +58,7 @@ class ExportController extends AbstractController
private readonly ExportManager $exportManager, private readonly ExportManager $exportManager,
private readonly FormFactoryInterface $formFactory, private readonly FormFactoryInterface $formFactory,
private readonly LoggerInterface $logger, private readonly LoggerInterface $logger,
private readonly SessionInterface $session, private readonly RequestStack $requestStack,
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly ExportFormHelper $exportFormHelper, private readonly ExportFormHelper $exportFormHelper,
private readonly Security $security, private readonly Security $security,
@@ -186,7 +187,7 @@ class ExportController extends AbstractController
$exportManager = $this->exportManager; $exportManager = $this->exportManager;
// check we have data from the previous step (export step) // check we have data from the previous step (export step)
$data = $this->session->get('centers_step', []); $data = $this->requestStack->getSession()->get('centers_step', []);
if (null === $data && true === $this->filterStatsByCenters) { if (null === $data && true === $this->filterStatsByCenters) {
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
@@ -208,11 +209,11 @@ class ExportController extends AbstractController
// store data for reusing in next steps // store data for reusing in next steps
$data = $form->getData(); $data = $form->getData();
$this->session->set( $this->requestStack->getSession()->set(
'export_step_raw', 'export_step_raw',
$request->request->all() $request->request->all()
); );
$this->session->set('export_step', $data); $this->requestStack->getSession()->set('export_step', $data);
// redirect to next step // redirect to next step
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
@@ -242,7 +243,7 @@ class ExportController extends AbstractController
private function formatterFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response private function formatterFormStep(Request $request, DirectExportInterface|ExportInterface $export, string $alias, ?SavedExport $savedExport = null): Response
{ {
// check we have data from the previous step (export step) // check we have data from the previous step (export step)
$data = $this->session->get('export_step', null); $data = $this->requestStack->getSession()->get('export_step', null);
if (null === $data) { if (null === $data) {
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
@@ -258,8 +259,8 @@ class ExportController extends AbstractController
if ($form->isValid()) { if ($form->isValid()) {
$dataFormatter = $form->getData(); $dataFormatter = $form->getData();
$this->session->set('formatter_step', $dataFormatter); $this->requestStack->getSession()->set('formatter_step', $dataFormatter);
$this->session->set( $this->requestStack->getSession()->set(
'formatter_step_raw', 'formatter_step_raw',
$request->request->all() $request->request->all()
); );
@@ -296,9 +297,9 @@ class ExportController extends AbstractController
if (!$user instanceof User) { if (!$user instanceof User) {
throw new AccessDeniedHttpException('only regular users can generate export'); throw new AccessDeniedHttpException('only regular users can generate export');
} }
$dataCenters = $this->session->get('centers_step_raw', null); $dataCenters = $this->requestStack->getSession()->get('centers_step_raw', null);
$dataFormatter = $this->session->get('formatter_step_raw', null); $dataFormatter = $this->requestStack->getSession()->get('formatter_step_raw', null);
$dataExport = $this->session->get('export_step_raw', null); $dataExport = $this->requestStack->getSession()->get('export_step_raw', null);
if (null === $dataFormatter && $export instanceof ExportInterface) { if (null === $dataFormatter && $export instanceof ExportInterface) {
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
@@ -328,11 +329,11 @@ class ExportController extends AbstractController
$this->messageBus->dispatch(new ExportRequestGenerationMessage($exportGeneration, $user)); $this->messageBus->dispatch(new ExportRequestGenerationMessage($exportGeneration, $user));
// remove data from session // remove data from session
$this->session->remove('centers_step_raw'); $this->requestStack->getSession()->remove('centers_step_raw');
$this->session->remove('export_step_raw'); $this->requestStack->getSession()->remove('export_step_raw');
$this->session->remove('export_step'); $this->requestStack->getSession()->remove('export_step');
$this->session->remove('formatter_step_raw'); $this->requestStack->getSession()->remove('formatter_step_raw');
$this->session->remove('formatter_step'); $this->requestStack->getSession()->remove('formatter_step');
return $this->redirectToRoute('chill_main_export-generation_wait', ['id' => $exportGeneration->getId()]); return $this->redirectToRoute('chill_main_export-generation_wait', ['id' => $exportGeneration->getId()]);
} }
@@ -431,11 +432,11 @@ class ExportController extends AbstractController
throw $this->createAccessDeniedException('you do not have access to this export for those centers'); throw $this->createAccessDeniedException('you do not have access to this export for those centers');
} }
$this->session->set( $this->requestStack->getSession()->set(
'centers_step_raw', 'centers_step_raw',
$request->request->all() $request->request->all()
); );
$this->session->set('centers_step', $data['centers']); $this->requestStack->getSession()->set('centers_step', $data['centers']);
return $this->redirectToRoute('chill_main_export_new', [ return $this->redirectToRoute('chill_main_export_new', [
'step' => $this->getNextStep('centers', $export), 'step' => $this->getNextStep('centers', $export),