diff --git a/docs/source/development/pagination/example.php b/docs/source/development/pagination/example.php index 964da8764..ef565e941 100644 --- a/docs/source/development/pagination/example.php +++ b/docs/source/development/pagination/example.php @@ -15,9 +15,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; class example extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } public function yourAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); // first, get the number of total item are available $total = $em ->createQuery('SELECT COUNT (item.id) FROM ChillMyBundle:Item item') diff --git a/docs/source/development/useful-snippets/controller-secured-for-person.php b/docs/source/development/useful-snippets/controller-secured-for-person.php index da2078a7a..35028f524 100644 --- a/docs/source/development/useful-snippets/controller-secured-for-person.php +++ b/docs/source/development/useful-snippets/controller-secured-for-person.php @@ -18,6 +18,9 @@ use Symfony\Component\Security\Core\Role\Role; class ConsultationController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * @param int $id personId * @@ -48,7 +51,7 @@ class ConsultationController extends \Symfony\Bundle\FrameworkBundle\Controller\ ); // create a query which take circles into account - $consultations = $this->getDoctrine()->getManager() + $consultations = $this->managerRegistry->getManager() ->createQuery('SELECT c FROM ChillHealthBundle:Consultation c ' . 'WHERE c.patient = :person AND c.circle IN(:circles) ' . 'ORDER BY c.date DESC') diff --git a/rector.php b/rector.php index cf0745174..80459534a 100644 --- a/rector.php +++ b/rector.php @@ -30,6 +30,7 @@ return static function (RectorConfig $rectorConfig): void { // part of the symfony 54 rules $rectorConfig->rule(\Rector\Symfony\Symfony53\Rector\StaticPropertyFetch\KernelTestCaseContainerPropertyDeprecationRector::class); + $rectorConfig->rule(\Rector\Symfony\Symfony60\Rector\MethodCall\GetHelperControllerToServiceRector::class); $rectorConfig->disableParallel(); //define sets of rules diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonCategoryController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonCategoryController.php index 6d0b825cc..fccf8172c 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonCategoryController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonCategoryController.php @@ -22,6 +22,9 @@ use Symfony\Component\HttpFoundation\Request; */ class ActivityReasonCategoryController extends AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Creates a new ActivityReasonCategory entity. * @@ -34,7 +37,7 @@ class ActivityReasonCategoryController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -54,7 +57,7 @@ class ActivityReasonCategoryController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReasonCategory::class)->find($id); @@ -77,7 +80,7 @@ class ActivityReasonCategoryController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReasonCategory::class)->findAll(); @@ -109,7 +112,7 @@ class ActivityReasonCategoryController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReasonCategory::class)->find($id); @@ -129,7 +132,7 @@ class ActivityReasonCategoryController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReasonCategory::class)->find($id); diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php index 141398cc4..f7a35565a 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php @@ -24,7 +24,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; */ class ActivityReasonController extends AbstractController { - public function __construct(private readonly ActivityReasonRepository $activityReasonRepository) {} + public function __construct(private readonly ActivityReasonRepository $activityReasonRepository, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * Creates a new ActivityReason entity. @@ -38,7 +38,7 @@ class ActivityReasonController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -58,7 +58,7 @@ class ActivityReasonController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReason::class)->find($id); @@ -81,7 +81,7 @@ class ActivityReasonController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $this->activityReasonRepository->findAll(); @@ -113,7 +113,7 @@ class ActivityReasonController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReason::class)->find($id); @@ -133,7 +133,7 @@ class ActivityReasonController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReason::class)->find($id); diff --git a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php index 38d4d82f5..60b2a0b95 100644 --- a/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php +++ b/src/Bundle/ChillBudgetBundle/Controller/AbstractElementController.php @@ -25,7 +25,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; abstract class AbstractElementController extends AbstractController { - public function __construct(protected EntityManagerInterface $em, protected TranslatorInterface $translator, protected LoggerInterface $chillMainLogger) {} + public function __construct(protected EntityManagerInterface $em, protected TranslatorInterface $translator, protected LoggerInterface $chillMainLogger, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * Route( @@ -60,7 +60,7 @@ abstract class AbstractElementController extends AbstractController 'type' => $element->getType(), ]); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->remove($element); $em->flush(); @@ -105,7 +105,7 @@ abstract class AbstractElementController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); $this->addFlash('success', $this->translator->trans($flashOnSuccess)); @@ -145,7 +145,7 @@ abstract class AbstractElementController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($element); $em->flush(); diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index f4694614f..039d9efde 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -58,7 +58,8 @@ class CalendarController extends AbstractController private readonly PersonRepository $personRepository, private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly UserRepositoryInterface $userRepository, - private readonly TranslatorInterface $translator + private readonly TranslatorInterface $translator, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -68,7 +69,7 @@ class CalendarController extends AbstractController */ public function deleteAction(Request $request, Calendar $entity) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); [$person, $accompanyingPeriod] = [$entity->getPerson(), $entity->getAccompanyingPeriod()]; @@ -124,7 +125,7 @@ class CalendarController extends AbstractController return $this->remoteCalendarConnector->getMakeReadyResponse($request->getUri()); } - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); [$person, $accompanyingPeriod] = [$entity->getPerson(), $entity->getAccompanyingPeriod()]; @@ -293,7 +294,7 @@ class CalendarController extends AbstractController } $view = null; - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); [$person, $accompanyingPeriod] = $this->getEntity($request); @@ -391,7 +392,7 @@ class CalendarController extends AbstractController { throw new \Exception('not implemented'); $view = null; - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); [$user, $accompanyingPeriod] = $this->getEntity($request); @@ -531,7 +532,7 @@ class CalendarController extends AbstractController */ private function getEntity(Request $request): array { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $accompanyingPeriod = null; if ($request->query->has('person_id')) { diff --git a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php index 00e377bde..b9c574ddc 100644 --- a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php +++ b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php @@ -25,7 +25,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class CustomFieldController extends AbstractController { - public function __construct(private readonly TranslatorInterface $translator) {} + public function __construct(private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * Creates a new CustomField entity. @@ -39,7 +39,7 @@ class CustomFieldController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -65,7 +65,7 @@ class CustomFieldController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(CustomField::class)->find($id); @@ -94,7 +94,7 @@ class CustomFieldController extends AbstractController $cfGroupId = $request->query->get('customFieldsGroup', null); if (null !== $cfGroupId) { - $cfGroup = $this->getDoctrine()->getManager() + $cfGroup = $this->managerRegistry->getManager() ->getRepository(CustomFieldsGroup::class) ->find($cfGroupId); @@ -119,7 +119,7 @@ class CustomFieldController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomField::class)->find($id); diff --git a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php index a8e77d059..92923b331 100644 --- a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php +++ b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldsGroupController.php @@ -36,7 +36,8 @@ class CustomFieldsGroupController extends AbstractController /** * CustomFieldsGroupController constructor. */ - public function __construct(private readonly CustomFieldProvider $customFieldProvider, private readonly TranslatorInterface $translator) {} + public function __construct( + private readonly CustomFieldProvider $customFieldProvider, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * Creates a new CustomFieldsGroup entity. @@ -50,7 +51,7 @@ class CustomFieldsGroupController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -76,7 +77,7 @@ class CustomFieldsGroupController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($id); @@ -99,7 +100,7 @@ class CustomFieldsGroupController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $cfGroups = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->findAll(); $defaultGroups = $this->getDefaultGroupsId(); @@ -131,7 +132,7 @@ class CustomFieldsGroupController extends AbstractController $cFGroupId = $form->get('id')->getData(); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->findOneById($cFGroupId); @@ -192,7 +193,7 @@ class CustomFieldsGroupController extends AbstractController */ public function renderFormAction($id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($id); @@ -236,7 +237,7 @@ class CustomFieldsGroupController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($id); @@ -260,7 +261,7 @@ class CustomFieldsGroupController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($id); @@ -313,7 +314,7 @@ class CustomFieldsGroupController extends AbstractController ->add('submit', SubmitType::class); $builder->get('customFieldsGroup') ->addViewTransformer(new CustomFieldsGroupToIdTransformer( - $this->getDoctrine()->getManager() + $this->managerRegistry->getManager() )); return $builder->getForm(); @@ -380,7 +381,7 @@ class CustomFieldsGroupController extends AbstractController */ private function getDefaultGroupsId() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $customFieldsGroupIds = $em->createQuery('SELECT g.id FROM ' .CustomFieldsDefaultGroup::class.' d ' diff --git a/src/Bundle/ChillCustomFieldsBundle/config/services/controller.yaml b/src/Bundle/ChillCustomFieldsBundle/config/services/controller.yaml index 2a25ea048..5a334025f 100644 --- a/src/Bundle/ChillCustomFieldsBundle/config/services/controller.yaml +++ b/src/Bundle/ChillCustomFieldsBundle/config/services/controller.yaml @@ -10,7 +10,6 @@ services: Chill\CustomFieldsBundle\Controller\CustomFieldsGroupController: arguments: $customFieldProvider: '@chill.custom_field.provider' - $translator: '@Symfony\Contracts\Translation\TranslatorInterface' tags: ['controller.service_arguments'] ## TODO ## cfr. https://github.com/symfony/symfony/issues/27436#issuecomment-393576416 diff --git a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php index e3f45a7fd..f42462dc8 100644 --- a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php +++ b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php @@ -32,7 +32,6 @@ class ChillDocGeneratorExtension extends Extension implements PrependExtensionIn $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); - $loader->load('services/controller.yaml'); $loader->load('services/fixtures.yaml'); $loader->load('services/form.yaml'); } diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml index 5fef6fb22..7a18360b0 100644 --- a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml +++ b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml @@ -32,6 +32,7 @@ services: resource: "../Controller" autowire: true autoconfigure: true + tags: ['controller.service_arguments'] Chill\DocGeneratorBundle\Form\: resource: "../Form/" diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml deleted file mode 100644 index 73d240428..000000000 --- a/src/Bundle/ChillDocGeneratorBundle/config/services/controller.yaml +++ /dev/null @@ -1,6 +0,0 @@ -services: - Chill\DocGeneratorBundle\Controller\: - autowire: true - autoconfigure: true - resource: '../../Controller' - tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 44feb5a47..c7f6e1920 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -36,7 +36,8 @@ class DocumentAccompanyingCourseController extends AbstractController public function __construct( protected TranslatorInterface $translator, protected EventDispatcherInterface $eventDispatcher, - protected AuthorizationHelper $authorizationHelper + protected AuthorizationHelper $authorizationHelper, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -52,8 +53,8 @@ class DocumentAccompanyingCourseController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->remove($document); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->remove($document); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully removed')); @@ -91,7 +92,7 @@ class DocumentAccompanyingCourseController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully updated')); @@ -141,7 +142,7 @@ class DocumentAccompanyingCourseController extends AbstractController 'creation of this activity not allowed' ); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($document); $em->flush(); diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php index fc58dff18..6d84036a5 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php @@ -25,12 +25,15 @@ use Symfony\Component\Routing\Annotation\Route; */ class DocumentCategoryController extends AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * @Route("/{bundleId}/{idInsideBundle}", name="document_category_delete", methods="DELETE") */ public function delete(Request $request, mixed $bundleId, mixed $idInsideBundle): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $documentCategory = $em ->getRepository(\Chill\DocStoreBundle\Entity\DocumentCategory::class) ->findOneBy( @@ -50,7 +53,7 @@ class DocumentCategoryController extends AbstractController */ public function edit(Request $request, mixed $bundleId, mixed $idInsideBundle): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $documentCategory = $em ->getRepository(\Chill\DocStoreBundle\Entity\DocumentCategory::class) ->findOneBy( @@ -61,7 +64,7 @@ class DocumentCategoryController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('document_category_index', [ 'bundleId' => $documentCategory->getBundleId(), @@ -79,7 +82,7 @@ class DocumentCategoryController extends AbstractController * @Route("/", name="chill_docstore_category_admin", methods="GET") */ public function index(): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $categories = $em->getRepository(DocumentCategory::class)->findAll(); return $this->render( @@ -95,7 +98,7 @@ class DocumentCategoryController extends AbstractController */ public function new(Request $request): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $nextId = $em ->createQuery( @@ -115,7 +118,7 @@ class DocumentCategoryController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($documentCategory); $em->flush(); @@ -133,7 +136,7 @@ class DocumentCategoryController extends AbstractController */ public function show(mixed $bundleId, mixed $idInsideBundle): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $documentCategory = $em ->getRepository(\Chill\DocStoreBundle\Entity\DocumentCategory::class) ->findOneBy( diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php index 73fffa1c4..3c93acf5c 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentPersonController.php @@ -42,7 +42,8 @@ class DocumentPersonController extends AbstractController public function __construct( protected TranslatorInterface $translator, protected EventDispatcherInterface $eventDispatcher, - protected AuthorizationHelper $authorizationHelper + protected AuthorizationHelper $authorizationHelper, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -58,8 +59,8 @@ class DocumentPersonController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->remove($document); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->remove($document); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully removed')); @@ -101,7 +102,7 @@ class DocumentPersonController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The document is successfully updated')); @@ -167,7 +168,7 @@ class DocumentPersonController extends AbstractController 'creation of this activity not allowed' ); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($document); $em->flush(); diff --git a/src/Bundle/ChillEventBundle/Controller/EventController.php b/src/Bundle/ChillEventBundle/Controller/EventController.php index e6ea264e4..91bba2a0b 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventController.php @@ -77,7 +77,8 @@ class EventController extends AbstractController AuthorizationHelper $authorizationHelper, FormFactoryInterface $formFactoryInterface, TranslatorInterface $translator, - PaginatorFactory $paginator + PaginatorFactory $paginator, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) { $this->eventDispatcher = $eventDispatcher; $this->authorizationHelper = $authorizationHelper; @@ -91,7 +92,7 @@ class EventController extends AbstractController */ public function deleteAction($event_id, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $event = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->findOneBy([ 'id' => $event_id, ]); @@ -144,7 +145,7 @@ class EventController extends AbstractController */ public function editAction($event_id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->find($event_id); @@ -171,7 +172,7 @@ class EventController extends AbstractController */ public function listByPersonAction($person_id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id); @@ -235,7 +236,7 @@ class EventController extends AbstractController { if (null === $center) { $center_id = $request->query->get('center_id'); - $center = $this->getDoctrine()->getRepository(Center::class)->find($center_id); + $center = $this->managerRegistry->getRepository(Center::class)->find($center_id); } $entity = new Event(); @@ -245,7 +246,7 @@ class EventController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -350,7 +351,7 @@ class EventController extends AbstractController */ public function updateAction(Request $request, $event_id): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Event::class)->find($event_id); diff --git a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php index b96fb9cb9..1b120876f 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventTypeController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventTypeController.php @@ -22,6 +22,9 @@ use Symfony\Component\HttpFoundation\Request; */ class EventTypeController extends AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Creates a new EventType entity. * @@ -34,7 +37,7 @@ class EventTypeController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -58,7 +61,7 @@ class EventTypeController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\EventType::class)->find($id); if (!$entity) { @@ -79,7 +82,7 @@ class EventTypeController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\EventType::class)->find($id); @@ -104,7 +107,7 @@ class EventTypeController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $em->getRepository(\Chill\EventBundle\Entity\EventType::class)->findAll(); @@ -136,7 +139,7 @@ class EventTypeController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\EventType::class)->find($id); @@ -159,7 +162,7 @@ class EventTypeController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\EventType::class)->find($id); diff --git a/src/Bundle/ChillEventBundle/Controller/ParticipationController.php b/src/Bundle/ChillEventBundle/Controller/ParticipationController.php index b80e33d2b..b40a2d865 100644 --- a/src/Bundle/ChillEventBundle/Controller/ParticipationController.php +++ b/src/Bundle/ChillEventBundle/Controller/ParticipationController.php @@ -33,7 +33,8 @@ class ParticipationController extends AbstractController /** * ParticipationController constructor. */ - public function __construct(private readonly LoggerInterface $logger, private readonly TranslatorInterface $translator) {} + public function __construct( + private readonly LoggerInterface $logger, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/event/participation/create", name="chill_event_participation_create") @@ -169,7 +170,7 @@ class ParticipationController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $data = $form->getData(); foreach ($data['participations'] as $participation) { @@ -207,7 +208,7 @@ class ParticipationController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($participation); $em->flush(); @@ -238,7 +239,7 @@ class ParticipationController extends AbstractController */ public function deleteAction($participation_id, Request $request): Response|\Symfony\Component\HttpFoundation\RedirectResponse { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $participation = $em->getRepository(\Chill\EventBundle\Entity\Participation::class)->findOneBy([ 'id' => $participation_id, ]); @@ -288,7 +289,7 @@ class ParticipationController extends AbstractController public function editAction(int $participation_id): Response { /** @var Participation $participation */ - $participation = $this->getDoctrine()->getManager() + $participation = $this->managerRegistry->getManager() ->getRepository(Participation::class) ->find($participation_id); @@ -319,7 +320,7 @@ class ParticipationController extends AbstractController */ public function editMultipleAction($event_id): Response|\Symfony\Component\HttpFoundation\RedirectResponse { - $event = $this->getDoctrine()->getRepository(\Chill\EventBundle\Entity\Event::class) + $event = $this->managerRegistry->getRepository(\Chill\EventBundle\Entity\Event::class) ->find($event_id); if (null === $event) { @@ -412,7 +413,7 @@ class ParticipationController extends AbstractController public function updateAction(int $participation_id, Request $request): Response { /** @var Participation $participation */ - $participation = $this->getDoctrine()->getManager() + $participation = $this->managerRegistry->getManager() ->getRepository(Participation::class) ->find($participation_id); @@ -431,7 +432,7 @@ class ParticipationController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); @@ -456,7 +457,7 @@ class ParticipationController extends AbstractController public function updateMultipleAction(mixed $event_id, Request $request) { /** @var \Chill\EventBundle\Entity\Event $event */ - $event = $this->getDoctrine()->getRepository(\Chill\EventBundle\Entity\Event::class) + $event = $this->managerRegistry->getRepository(\Chill\EventBundle\Entity\Event::class) ->find($event_id); if (null === $event) { @@ -479,7 +480,7 @@ class ParticipationController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('The participations ' .'have been successfully updated.')); @@ -547,7 +548,7 @@ class ParticipationController extends AbstractController Participation $participation, bool $multiple = false ): array|\Chill\EventBundle\Entity\Participation { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); if ($em->contains($participation)) { throw new \LogicException('The participation object should not be managed by the object manager using the method '.__METHOD__); diff --git a/src/Bundle/ChillEventBundle/Controller/RoleController.php b/src/Bundle/ChillEventBundle/Controller/RoleController.php index 1b2ad2b25..17cbd0870 100644 --- a/src/Bundle/ChillEventBundle/Controller/RoleController.php +++ b/src/Bundle/ChillEventBundle/Controller/RoleController.php @@ -22,6 +22,9 @@ use Symfony\Component\HttpFoundation\Request; */ class RoleController extends AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Creates a new Role entity. * @@ -34,7 +37,7 @@ class RoleController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -58,7 +61,7 @@ class RoleController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Role::class)->find($id); if (!$entity) { @@ -79,7 +82,7 @@ class RoleController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Role::class)->find($id); @@ -104,7 +107,7 @@ class RoleController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $em->getRepository(\Chill\EventBundle\Entity\Role::class)->findAll(); @@ -136,7 +139,7 @@ class RoleController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Role::class)->find($id); @@ -159,7 +162,7 @@ class RoleController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Role::class)->find($id); diff --git a/src/Bundle/ChillEventBundle/Controller/StatusController.php b/src/Bundle/ChillEventBundle/Controller/StatusController.php index 90bb7c1f2..63c6980d1 100644 --- a/src/Bundle/ChillEventBundle/Controller/StatusController.php +++ b/src/Bundle/ChillEventBundle/Controller/StatusController.php @@ -22,6 +22,9 @@ use Symfony\Component\HttpFoundation\Request; */ class StatusController extends AbstractController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Creates a new Status entity. * @@ -34,7 +37,7 @@ class StatusController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entity); $em->flush(); @@ -58,7 +61,7 @@ class StatusController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id); if (!$entity) { @@ -79,7 +82,7 @@ class StatusController extends AbstractController */ public function editAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id); @@ -104,7 +107,7 @@ class StatusController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->findAll(); @@ -136,7 +139,7 @@ class StatusController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id); @@ -159,7 +162,7 @@ class StatusController extends AbstractController */ public function updateAction(Request $request, mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = $em->getRepository(\Chill\EventBundle\Entity\Status::class)->find($id); diff --git a/src/Bundle/ChillEventBundle/config/services/controller.yaml b/src/Bundle/ChillEventBundle/config/services/controller.yaml index 0ba2fac8e..efbb4a25b 100644 --- a/src/Bundle/ChillEventBundle/config/services/controller.yaml +++ b/src/Bundle/ChillEventBundle/config/services/controller.yaml @@ -7,10 +7,12 @@ services: $formFactoryInterface: '@Symfony\Component\Form\FormFactoryInterface' $translator: '@Symfony\Contracts\Translation\TranslatorInterface' $paginator: '@chill_main.paginator_factory' + $managerRegistry: '@Doctrine\Persistence\ManagerRegistry' public: true tags: ['controller.service_arguments'] Chill\EventBundle\Controller\ParticipationController: arguments: $logger: '@Psr\Log\LoggerInterface' + $managerRegistry: '@Doctrine\Persistence\ManagerRegistry' tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php index cfbe52218..7efb0c3b2 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php @@ -31,6 +31,9 @@ abstract class AbstractCRUDController extends AbstractController * This configuration si defined by `chill_main['crud']` or `chill_main['apis']` */ protected array $crudConfig = []; + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * get the role given from the config. @@ -91,7 +94,7 @@ abstract class AbstractCRUDController extends AbstractController */ protected function buildQueryEntities(string $action, Request $request) { - $qb = $this->getDoctrine()->getManager() + $qb = $this->managerRegistry->getManager() ->createQueryBuilder() ->select('e') ->from($this->getEntityClass(), 'e'); @@ -163,8 +166,7 @@ abstract class AbstractCRUDController extends AbstractController */ protected function getEntity(mixed $action, string $id, Request $request): object { - $e = $this - ->getDoctrine() + $e = $this->managerRegistry ->getRepository($this->getEntityClass()) ->find($id); diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index 345da5bc5..ad28c4a1c 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -23,6 +23,9 @@ use Symfony\Component\Validator\ConstraintViolationListInterface; class ApiController extends AbstractCRUDController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Base method for handling api action. * @@ -80,8 +83,8 @@ class ApiController extends AbstractCRUDController return $response; } - $this->getDoctrine()->getManager()->remove($entity); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->remove($entity); + $this->managerRegistry->getManager()->flush(); $response = $this->onAfterFlush($action, $request, $_format, $entity, $errors); @@ -153,7 +156,7 @@ class ApiController extends AbstractCRUDController return $response; } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $response = $this->onAfterFlush($action, $request, $_format, $entity, $errors); @@ -269,10 +272,10 @@ class ApiController extends AbstractCRUDController } if ($forcePersist && Request::METHOD_POST === $request->getMethod()) { - $this->getDoctrine()->getManager()->persist($postedData); + $this->managerRegistry->getManager()->persist($postedData); } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $response = $this->onAfterFlush($action, $request, $_format, $entity, $errors, [$postedData]); @@ -403,8 +406,8 @@ class ApiController extends AbstractCRUDController return $response; } - $this->getDoctrine()->getManager()->persist($entity); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->persist($entity); + $this->managerRegistry->getManager()->flush(); $response = $this->onAfterFlush($action, $request, $_format, $entity, $errors); diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php index 39cef87b7..18dedebf5 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/CRUDController.php @@ -37,6 +37,9 @@ class CRUDController extends AbstractController * This configuration si defined by `chill_main['crud']`. */ protected array $crudConfig; + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } public function CRUD(?string $parameter): Response { @@ -150,8 +153,7 @@ class CRUDController extends AbstractController */ protected function buildQueryEntities(string $action, Request $request) { - $query = $this - ->getDoctrine() + $query = $this->managerRegistry ->getManager() ->createQueryBuilder() ->select('e') @@ -265,7 +267,7 @@ class CRUDController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $this->onFormValid($action, $entity, $form, $request); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $this->onPreRemove($action, $entity, $form, $request); $this->removeEntity($action, $entity, $form, $request); @@ -310,7 +312,7 @@ class CRUDController extends AbstractController $id = $request->query->get('duplicate_id', 0); $originalEntity = $this->getEntity($action, $id, $request); - $this->getDoctrine()->getManager() + $this->managerRegistry->getManager() ->detach($originalEntity); return $originalEntity; @@ -382,7 +384,7 @@ class CRUDController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $this->onFormValid($action, $entity, $form, $request); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $this->onPrePersist($action, $entity, $form, $request); $em->persist($entity); @@ -485,7 +487,7 @@ class CRUDController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $this->onFormValid($action, $entity, $form, $request); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $this->onPreFlush($action, $entity, $form, $request); $em->flush(); @@ -599,7 +601,7 @@ class CRUDController extends AbstractController */ protected function getEntity(mixed $action, $id, Request $request): ?object { - return $this->getDoctrine() + return $this->managerRegistry ->getRepository($this->getEntityClass()) ->find($id); } @@ -918,7 +920,7 @@ class CRUDController extends AbstractController protected function removeEntity(string $action, $entity, FormInterface $form, Request $request) { - $this->getDoctrine() + $this->managerRegistry ->getManager() ->remove($entity); } diff --git a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php index 8664dbde5..23aa9fd10 100644 --- a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php +++ b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php @@ -19,7 +19,7 @@ use Symfony\Component\Routing\Annotation\Route; class AbsenceController extends AbstractController { - public function __construct(private readonly ChillSecurity $security) {} + public function __construct(private readonly ChillSecurity $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route( @@ -36,7 +36,7 @@ class AbsenceController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); return $this->redirectToRoute('chill_main_user_absence_index'); @@ -60,7 +60,7 @@ class AbsenceController extends AbstractController $user = $this->security->getUser(); $user->setAbsenceStart(null); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); return $this->redirectToRoute('chill_main_user_absence_index'); diff --git a/src/Bundle/ChillMainBundle/Controller/AddressApiController.php b/src/Bundle/ChillMainBundle/Controller/AddressApiController.php index 6bc952923..acc7f27c3 100644 --- a/src/Bundle/ChillMainBundle/Controller/AddressApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/AddressApiController.php @@ -20,6 +20,9 @@ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; class AddressApiController extends ApiController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Duplicate an existing address. * @@ -31,7 +34,7 @@ class AddressApiController extends ApiController $this->denyAccessUnlessGranted('ROLE_USER'); $new = Address::createFromAddress($address); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($new); $em->flush(); diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index 37b715ebd..ea79317bf 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -40,7 +40,7 @@ use function in_array; */ class NotificationController extends AbstractController { - public function __construct(private readonly EntityManagerInterface $em, private readonly LoggerInterface $chillLogger, private readonly LoggerInterface $logger, private readonly ChillSecurity $security, private readonly NotificationRepository $notificationRepository, private readonly NotificationHandlerManager $notificationHandlerManager, private readonly PaginatorFactory $paginatorFactory, private readonly TranslatorInterface $translator, private readonly UserRepository $userRepository) {} + public function __construct(private readonly EntityManagerInterface $em, private readonly LoggerInterface $chillLogger, private readonly LoggerInterface $logger, private readonly ChillSecurity $security, private readonly NotificationRepository $notificationRepository, private readonly NotificationHandlerManager $notificationHandlerManager, private readonly PaginatorFactory $paginatorFactory, private readonly TranslatorInterface $translator, private readonly UserRepository $userRepository, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route("/create", name="chill_main_notification_create") @@ -159,7 +159,7 @@ class NotificationController extends AbstractController $notification->addAddressee($this->security->getUser()); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $logMsg = '[Notification] a user is granted access to notification trough an access key'; $context = [ diff --git a/src/Bundle/ChillMainBundle/Controller/PasswordController.php b/src/Bundle/ChillMainBundle/Controller/PasswordController.php index c6815f2cf..e65c70672 100644 --- a/src/Bundle/ChillMainBundle/Controller/PasswordController.php +++ b/src/Bundle/ChillMainBundle/Controller/PasswordController.php @@ -40,7 +40,7 @@ final class PasswordController extends AbstractController /** * PasswordController constructor. */ - public function __construct(private readonly LoggerInterface $chillLogger, private readonly UserPasswordEncoderInterface $passwordEncoder, private readonly RecoverPasswordHelper $recoverPasswordHelper, private readonly TokenManager $tokenManager, private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher, private readonly ChillSecurity $security) {} + public function __construct(private readonly LoggerInterface $chillLogger, private readonly UserPasswordEncoderInterface $passwordEncoder, private readonly RecoverPasswordHelper $recoverPasswordHelper, private readonly TokenManager $tokenManager, private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher, private readonly ChillSecurity $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @return Response @@ -68,7 +68,7 @@ final class PasswordController extends AbstractController $hash = $query->getAlnum(TokenManager::HASH); $token = $query->getAlnum(TokenManager::TOKEN); $timestamp = $query->getAlnum(TokenManager::TIMESTAMP); - $user = $this->getDoctrine()->getRepository(User::class) + $user = $this->managerRegistry->getRepository(User::class) ->findOneByUsernameCanonical($username); if (null === $user) { @@ -107,7 +107,7 @@ final class PasswordController extends AbstractController ] ); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('password_request_recover_changed'); } @@ -137,7 +137,7 @@ final class PasswordController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { /** @var \Doctrine\ORM\QueryBuilder $qb */ - $qb = $this->getDoctrine()->getManager() + $qb = $this->managerRegistry->getManager() ->createQueryBuilder(); $qb->select('u') ->from(User::class, 'u') @@ -236,7 +236,7 @@ final class PasswordController extends AbstractController $user->setPassword($this->passwordEncoder->encodePassword($user, $password)); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); $this->addFlash('success', $this->translator->trans('Password successfully updated!')); @@ -262,7 +262,7 @@ final class PasswordController extends AbstractController 'constraints' => [ new Callback([ 'callback' => function ($pattern, ExecutionContextInterface $context, $payload) { - $qb = $this->getDoctrine()->getManager() + $qb = $this->managerRegistry->getManager() ->createQueryBuilder(); $qb->select('COUNT(u)') ->from(User::class, 'u') diff --git a/src/Bundle/ChillMainBundle/Controller/PostalCodeController.php b/src/Bundle/ChillMainBundle/Controller/PostalCodeController.php index f186561d5..b7ea48328 100644 --- a/src/Bundle/ChillMainBundle/Controller/PostalCodeController.php +++ b/src/Bundle/ChillMainBundle/Controller/PostalCodeController.php @@ -29,7 +29,7 @@ class PostalCodeController extends AbstractController */ protected $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) + public function __construct(TranslatableStringHelper $translatableStringHelper, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) { $this->translatableStringHelper = $translatableStringHelper; } @@ -49,7 +49,7 @@ class PostalCodeController extends AbstractController return new JsonResponse(['results' => [], 'pagination' => ['more' => false]]); } - $query = $this->getDoctrine()->getManager() + $query = $this->managerRegistry->getManager() ->createQuery( sprintf( 'SELECT p.id AS id, p.name AS name, p.code AS code, ' diff --git a/src/Bundle/ChillMainBundle/Controller/ScopeController.php b/src/Bundle/ChillMainBundle/Controller/ScopeController.php index ab2012a5c..b7e142e04 100644 --- a/src/Bundle/ChillMainBundle/Controller/ScopeController.php +++ b/src/Bundle/ChillMainBundle/Controller/ScopeController.php @@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Response; class ScopeController extends AbstractController { public function __construct( - private readonly EntityManagerInterface $entityManager + private readonly EntityManagerInterface $entityManager, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -41,7 +41,7 @@ class ScopeController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($scope); $em->flush(); @@ -83,7 +83,7 @@ class ScopeController extends AbstractController */ public function indexAction() { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entities = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->findAll(); @@ -113,7 +113,7 @@ class ScopeController extends AbstractController */ public function showAction(mixed $id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $scope = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->find($id); diff --git a/src/Bundle/ChillMainBundle/Controller/UserController.php b/src/Bundle/ChillMainBundle/Controller/UserController.php index 8e0e8ad1b..b68448da4 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserController.php @@ -46,7 +46,8 @@ class UserController extends CRUDController private readonly UserRepository $userRepository, protected ParameterBagInterface $parameterBag, private readonly TranslatorInterface $translator, - private readonly ChillSecurity $security + private readonly ChillSecurity $security, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -55,7 +56,7 @@ class UserController extends CRUDController */ public function addLinkGroupCenterAction(Request $request, mixed $uid): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $user = $em->getRepository(\Chill\MainBundle\Entity\User::class)->find($uid); @@ -107,7 +108,7 @@ class UserController extends CRUDController */ public function deleteLinkGroupCenterAction(mixed $uid, mixed $gcid, Request $request): RedirectResponse { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $user = $em->getRepository(\Chill\MainBundle\Entity\User::class)->find($uid); @@ -165,7 +166,7 @@ class UserController extends CRUDController if ($form->isSubmitted() && $form->isValid()) { $this->onFormValid($action, $entity, $form, $request); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $this->onPreFlush($action, $entity, $form, $request); $em->flush(); @@ -216,7 +217,7 @@ class UserController extends CRUDController $user->setCurrentLocation($currentLocation); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('Current location successfully updated')); return $this->redirect( @@ -252,7 +253,7 @@ class UserController extends CRUDController $user->setPassword($this->passwordEncoder->encodePassword($user, $password)); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('Password successfully updated!')); return $this->redirect( @@ -431,7 +432,7 @@ class UserController extends CRUDController private function getPersistedGroupCenter(GroupCenter $groupCenter) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $groupCenterManaged = $em->getRepository(\Chill\MainBundle\Entity\GroupCenter::class) ->findOneBy([ diff --git a/src/Bundle/ChillMainBundle/Controller/UserProfileController.php b/src/Bundle/ChillMainBundle/Controller/UserProfileController.php index 0867bf2cd..ecdde78a5 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserProfileController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserProfileController.php @@ -27,6 +27,7 @@ final class UserProfileController extends AbstractController public function __construct( private readonly TranslatorInterface $translator, private readonly ChillSecurity $security, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} /** @@ -49,7 +50,7 @@ final class UserProfileController extends AbstractController $user->setPhonenumber($phonenumber); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('user.profile.Phonenumber successfully updated!')); return $this->redirectToRoute('chill_main_user_profile'); diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 1e93d6f49..b19f03c3b 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -38,7 +38,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; class WorkflowController extends AbstractController { - public function __construct(private readonly EntityWorkflowManager $entityWorkflowManager, private readonly EntityWorkflowRepository $entityWorkflowRepository, private readonly ValidatorInterface $validator, private readonly PaginatorFactory $paginatorFactory, private readonly Registry $registry, private readonly EntityManagerInterface $entityManager, private readonly TranslatorInterface $translator, private readonly ChillSecurity $security) {} + public function __construct(private readonly EntityWorkflowManager $entityWorkflowManager, private readonly EntityWorkflowRepository $entityWorkflowRepository, private readonly ValidatorInterface $validator, private readonly PaginatorFactory $paginatorFactory, private readonly Registry $registry, private readonly EntityManagerInterface $entityManager, private readonly TranslatorInterface $translator, private readonly ChillSecurity $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route("/{_locale}/main/workflow/create", name="chill_main_workflow_create") @@ -79,7 +79,7 @@ class WorkflowController extends AbstractController $this->denyAccessUnlessGranted(EntityWorkflowVoter::CREATE, $entityWorkflow); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($entityWorkflow); $em->flush(); diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index 428147961..794923e65 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -30,8 +30,6 @@ services: tags: ['controller.service_arguments'] Chill\MainBundle\Controller\NotificationController: - arguments: - $security: '@Symfony\Component\Security\Core\Security' tags: ['controller.service_arguments'] Chill\MainBundle\Controller\RegroupmentController: diff --git a/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php b/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php index 12df5a0f9..4c7a7f6fa 100644 --- a/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php +++ b/src/Bundle/ChillPersonBundle/CRUD/Controller/EntityPersonCRUDController.php @@ -23,6 +23,9 @@ use Symfony\Component\HttpFoundation\Response; */ class EntityPersonCRUDController extends CRUDController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * Override the base method to add a filtering step to a person. * @@ -102,7 +105,7 @@ class EntityPersonCRUDController extends CRUDController return null; } - $person = $this->getDoctrine() + $person = $this->managerRegistry ->getRepository(Person::class) ->find($request->query->getInt('person_id')); diff --git a/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php b/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php index a163e9bbd..c01bd148a 100644 --- a/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php +++ b/src/Bundle/ChillPersonBundle/CRUD/Controller/OneToOneEntityPersonCRUDController.php @@ -20,6 +20,9 @@ use Symfony\Component\HttpFoundation\Response; class OneToOneEntityPersonCRUDController extends CRUDController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } protected function generateRedirectOnCreateRoute($action, Request $request, $entity): string { throw new \BadMethodCallException('Not implemented yet.'); @@ -31,7 +34,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController if (null === $entity) { $entity = $this->createEntity($action, $request); - $person = $this->getDoctrine() + $person = $this->managerRegistry ->getManager() ->getRepository(Person::class) ->find($id); @@ -58,7 +61,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController protected function onPostFetchEntity($action, Request $request, $entity): ?Response { - if (false === $this->getDoctrine()->getManager()->contains($entity)) { + if (false === $this->managerRegistry->getManager()->contains($entity)) { return new RedirectResponse($this->generateRedirectOnCreateRoute($action, $request, $entity)); } @@ -67,6 +70,6 @@ class OneToOneEntityPersonCRUDController extends CRUDController protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request) { - $this->getDoctrine()->getManager()->persist($entity); + $this->managerRegistry->getManager()->persist($entity); } } diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 7819ebb46..6caa6be4c 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -46,7 +46,7 @@ use Symfony\Component\Workflow\Registry; final class AccompanyingCourseApiController extends ApiController { - public function __construct(private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ReferralsSuggestionInterface $referralAvailable, private readonly Registry $registry, private readonly ValidatorInterface $validator) {} + public function __construct(private readonly AccompanyingPeriodRepository $accompanyingPeriodRepository, private readonly AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ReferralsSuggestionInterface $referralAvailable, private readonly Registry $registry, private readonly ValidatorInterface $validator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} public function commentApi($id, Request $request, string $_format): Response { @@ -72,7 +72,7 @@ final class AccompanyingCourseApiController extends ApiController $workflow->apply($accompanyingPeriod, 'confirm'); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->json($accompanyingPeriod, Response::HTTP_OK, [], [ 'groups' => ['read'], @@ -172,7 +172,7 @@ final class AccompanyingCourseApiController extends ApiController return $this->json($errors, 422); } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->json($participation, 200, [], ['groups' => ['read']]); } @@ -220,7 +220,7 @@ final class AccompanyingCourseApiController extends ApiController return $this->json($errors, 422); } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->json($accompanyingPeriod->getRequestor(), 200, [], ['groups' => ['read']]); } @@ -289,7 +289,7 @@ final class AccompanyingCourseApiController extends ApiController $accompanyingCourse->setConfidential(!$accompanyingCourse->isConfidential()); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); } return $this->json($accompanyingCourse->isConfidential(), Response::HTTP_OK, [], ['groups' => ['read']]); @@ -307,7 +307,7 @@ final class AccompanyingCourseApiController extends ApiController $status = 'regular' === $accompanyingCourse->getIntensity() ? 'occasional' : 'regular'; $accompanyingCourse->setIntensity($status); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); } return $this->json($accompanyingCourse->getIntensity(), Response::HTTP_OK, [], ['groups' => ['read']]); diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php index 895011085..641648264 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php @@ -30,7 +30,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; class AccompanyingCourseCommentController extends AbstractController { - public function __construct(private readonly EntityManagerInterface $entityManager, private readonly FormFactoryInterface $formFactory, private readonly TranslatorInterface $translator) {} + public function __construct(private readonly EntityManagerInterface $entityManager, private readonly FormFactoryInterface $formFactory, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * Page of comments in Accompanying Course section. @@ -43,7 +43,7 @@ class AccompanyingCourseCommentController extends AbstractController { $this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE_DETAILS, $accompanyingCourse); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $afterSuccessfulRedirectResponse = $this->redirectToRoute('chill_person_accompanying_period_comment_list', [ 'accompanying_period_id' => $accompanyingCourse->getId(), ]); @@ -162,7 +162,7 @@ class AccompanyingCourseCommentController extends AbstractController $comment->getAccompanyingPeriod()->setPinnedComment($comment); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('accompanying_course.comment is pinned')); @@ -180,7 +180,7 @@ class AccompanyingCourseCommentController extends AbstractController $comment->getAccompanyingPeriod()->setPinnedComment(null); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('accompanying_course.comment is unpinned')); diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 870f07cb4..330065776 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -46,6 +46,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle private readonly TranslatorInterface $translator, private readonly Security $security, private readonly PersonRepository $personRepository, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} /** @@ -64,7 +65,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $workflow = $this->registry->get($accompanyingCourse); @@ -102,7 +103,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle */ public function deleteAction(Request $request, AccompanyingPeriod $accompanyingCourse) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person_id = $request->query->get('person_id'); @@ -205,7 +206,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle } } - $activities = $this->getDoctrine()->getManager()->getRepository(Activity::class)->findBy( + $activities = $this->managerRegistry->getManager()->getRepository(Activity::class)->findBy( ['accompanyingPeriod' => $accompanyingCourse], ['date' => 'DESC', 'id' => 'DESC'], ); @@ -239,7 +240,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle } $period = new AccompanyingPeriod(); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $personIds = $request->query->all('person_id'); @@ -279,7 +280,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle } $period = new AccompanyingPeriod(); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); if ($request->query->has('household_id')) { $householdId = $request->query->get('household_id'); @@ -324,7 +325,7 @@ final class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle if ($form->isSubmitted() && $form->isValid()) { $accompanyingCourse->reOpen(); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('chill_person_accompanying_course_index', [ 'accompanying_period_id' => $accompanyingCourse->getId(), diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php index 89ec1ae17..728328400 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php @@ -40,7 +40,8 @@ final class AccompanyingCourseWorkController extends AbstractController private readonly PaginatorFactory $paginator, private readonly LoggerInterface $chillLogger, private readonly TranslatableStringHelperInterface $translatableStringHelper, - private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory + private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -87,7 +88,7 @@ final class AccompanyingCourseWorkController extends AbstractController { $this->denyAccessUnlessGranted(AccompanyingPeriodWorkVoter::UPDATE, $work); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $form = $this->createDeleteForm($work->getId()); diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php index 55b985b85..cd0abd873 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodController.php @@ -38,7 +38,8 @@ class AccompanyingPeriodController extends AbstractController protected AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, private readonly EventDispatcherInterface $eventDispatcher, private readonly ValidatorInterface $validator, - private readonly TranslatorInterface $translator + private readonly TranslatorInterface $translator, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -86,7 +87,7 @@ class AccompanyingPeriodController extends AbstractController '%name%' => $person->__toString(), ])); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('chill_person_accompanying_period_list', [ 'person_id' => $person->getId(), @@ -159,7 +160,7 @@ class AccompanyingPeriodController extends AbstractController $form->isValid(['Default', 'closed']) && 0 === \count($errors) ) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($accompanyingPeriod); $em->flush(); $flashBag->add( @@ -271,7 +272,7 @@ class AccompanyingPeriodController extends AbstractController ['%name%' => $person->__toString()] )); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('chill_person_accompanying_period_list', [ 'person_id' => $person->getId(), @@ -327,7 +328,7 @@ class AccompanyingPeriodController extends AbstractController $this->_validatePerson($person); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans( 'The period has been re-opened' @@ -357,7 +358,7 @@ class AccompanyingPeriodController extends AbstractController */ public function updateAction(int $person_id, int $period_id, Request $request): Response { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); /** @var AccompanyingPeriod $accompanyingPeriod */ $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($period_id); @@ -430,7 +431,7 @@ class AccompanyingPeriodController extends AbstractController */ private function _getPerson(int $id): Person { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($id); if (null === $person) { diff --git a/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php b/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php index 2943615f5..b903ffb61 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ClosingMotiveController.php @@ -21,6 +21,9 @@ use Symfony\Component\HttpFoundation\Request; */ class ClosingMotiveController extends CRUDController { + public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) + { + } /** * @param string $action */ @@ -31,7 +34,7 @@ class ClosingMotiveController extends CRUDController if ($request->query->has('parent_id')) { $parentId = $request->query->getInt('parent_id'); - $parent = $this->getDoctrine()->getManager() + $parent = $this->managerRegistry->getManager() ->getRepository($this->getEntityClass()) ->find($parentId); diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php index a5b1081d5..a6d5ed2c5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdApiController.php @@ -31,7 +31,7 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class HouseholdApiController extends ApiController { - public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly HouseholdRepository $householdRepository, private readonly HouseholdACLAwareRepositoryInterface $householdACLAwareRepository) {} + public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly HouseholdRepository $householdRepository, private readonly HouseholdACLAwareRepositoryInterface $householdACLAwareRepository, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route("/api/1.0/person/household/by-address-reference/{id}.json", @@ -93,7 +93,7 @@ class HouseholdApiController extends ApiController return $this->json($errors, 422); } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->json( $address, diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index c85edaaf7..ae74d365b 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -34,7 +34,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class HouseholdController extends AbstractController { - public function __construct(private readonly TranslatorInterface $translator, private readonly PositionRepository $positionRepository, private readonly SerializerInterface $serializer, private readonly Security $security) {} + public function __construct(private readonly TranslatorInterface $translator, private readonly PositionRepository $positionRepository, private readonly SerializerInterface $serializer, private readonly Security $security, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route( @@ -105,7 +105,7 @@ class HouseholdController extends AbstractController // TODO ACL $address_id = $request->query->get('address_id'); - $address = $this->getDoctrine()->getManager() + $address = $this->managerRegistry->getManager() ->getRepository(Address::class) ->find($address_id); @@ -210,7 +210,7 @@ class HouseholdController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $household->makeAddressConsistent(); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('chill_person_household_addresses', [ 'household_id' => $household->getId(), @@ -244,7 +244,7 @@ class HouseholdController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator->trans('household.data_saved')); diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index 0b7326636..aa2f80a43 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -44,6 +44,7 @@ class HouseholdMemberController extends ApiController private readonly HouseholdRepository $householdRepository, private readonly Security $security, private readonly PositionRepository $positionRepository, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} /** @@ -62,7 +63,7 @@ class HouseholdMemberController extends ApiController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator ->trans('household.successfully saved member')); @@ -204,7 +205,7 @@ class HouseholdMemberController extends ApiController // launch events on post move $editor->postMove(); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); // if new household, persist it if ( diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php index 193aad950..bcb5c8ccd 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php @@ -29,14 +29,14 @@ class PersonAddressController extends AbstractController /** * PersonAddressController constructor. */ - public function __construct(private readonly ValidatorInterface $validator, private readonly TranslatorInterface $translator) {} + public function __construct(private readonly ValidatorInterface $validator, private readonly TranslatorInterface $translator, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/address/create", name="chill_person_address_create", methods={"POST"}) */ public function createAction(mixed $person_id, Request $request) { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -65,7 +65,7 @@ class PersonAddressController extends AbstractController $this->addFlash('error', $error->getMessage()); } } elseif ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->flush(); $this->addFlash( @@ -93,7 +93,7 @@ class PersonAddressController extends AbstractController */ public function editAction(mixed $person_id, mixed $address_id) { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -123,7 +123,7 @@ class PersonAddressController extends AbstractController */ public function listAction(mixed $person_id) { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -147,7 +147,7 @@ class PersonAddressController extends AbstractController */ public function newAction(mixed $person_id) { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -176,7 +176,7 @@ class PersonAddressController extends AbstractController */ public function updateAction(mixed $person_id, mixed $address_id, Request $request) { - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -203,7 +203,7 @@ class PersonAddressController extends AbstractController $this->addFlash('error', $error->getMessage()); } } elseif ($form->isValid()) { - $this->getDoctrine()->getManager() + $this->managerRegistry->getManager() ->flush(); $this->addFlash('success', $this->translator->trans( @@ -276,7 +276,7 @@ class PersonAddressController extends AbstractController */ protected function findAddressById(Person $person, $address_id) { - $address = $this->getDoctrine()->getManager() + $address = $this->managerRegistry->getManager() ->getRepository(Address::class) ->find($address_id); diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index 7444dce5a..119780b47 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -39,6 +39,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll private readonly PersonMove $personMove, private readonly EventDispatcherInterface $eventDispatcher, private readonly Security $security, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} /** @@ -84,7 +85,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll $sqls = $this->personMove->getSQL($person2, $person1); - $connection = $this->getDoctrine()->getConnection(); + $connection = $this->managerRegistry->getConnection(); $connection->beginTransaction(); @@ -173,7 +174,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll 'You are not allowed to see this person.' ); - $personNotDuplicate = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) + $personNotDuplicate = $this->managerRegistry->getRepository(PersonNotDuplicate::class) ->findOneBy(['person1' => $person1, 'person2' => $person2]); if (!$personNotDuplicate instanceof PersonNotDuplicate) { @@ -182,8 +183,8 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll $personNotDuplicate->setPerson2($person2); $personNotDuplicate->setUser($user); - $this->getDoctrine()->getManager()->persist($personNotDuplicate); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->persist($personNotDuplicate); + $this->managerRegistry->getManager()->flush(); } return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); @@ -202,12 +203,12 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll 'You are not allowed to see this person.' ); - $personNotDuplicate = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) + $personNotDuplicate = $this->managerRegistry->getRepository(PersonNotDuplicate::class) ->findOneBy(['person1' => $person1, 'person2' => $person2]); if ($personNotDuplicate instanceof PersonNotDuplicate) { - $this->getDoctrine()->getManager()->remove($personNotDuplicate); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->remove($personNotDuplicate); + $this->managerRegistry->getManager()->flush(); } return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); @@ -244,7 +245,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll private function _getCounters($id): ?array { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $nb_activity = $em->getRepository(Activity::class)->findBy(['person' => $id]); $nb_document = $em->getRepository(PersonDocument::class)->findBy(['person' => $id]); diff --git a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php index 4b8278f9d..4cf3e0d6e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ResidentialAddressController.php @@ -27,7 +27,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; final class ResidentialAddressController extends AbstractController { - public function __construct(private readonly UrlGeneratorInterface $generator, private readonly TranslatorInterface $translator, private readonly ResidentialAddressRepository $residentialAddressRepository) {} + public function __construct(private readonly UrlGeneratorInterface $generator, private readonly TranslatorInterface $translator, private readonly ResidentialAddressRepository $residentialAddressRepository, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @Route("/{_locale}/person/residential-address/{id}/delete", name="chill_person_residential_address_delete") @@ -41,7 +41,7 @@ final class ResidentialAddressController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->remove($residentialAddress); $em->flush(); @@ -75,7 +75,7 @@ final class ResidentialAddressController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator ->trans('The residential address was updated successfully')); @@ -127,8 +127,8 @@ final class ResidentialAddressController extends AbstractController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->persist($residentialAddress); - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->persist($residentialAddress); + $this->managerRegistry->getManager()->flush(); $this->addFlash('success', $this->translator ->trans('The new residential address was created successfully')); diff --git a/src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php b/src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php index 21792444e..5cfc26cc7 100644 --- a/src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php @@ -22,14 +22,14 @@ use Symfony\Component\HttpFoundation\Request; class TimelinePersonController extends AbstractController { - public function __construct(protected EventDispatcherInterface $eventDispatcher, protected TimelineBuilder $timelineBuilder, protected PaginatorFactory $paginatorFactory) {} + public function __construct(protected EventDispatcherInterface $eventDispatcher, protected TimelineBuilder $timelineBuilder, protected PaginatorFactory $paginatorFactory, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {} /** * @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/timeline", name="chill_person_timeline") */ public function personAction(Request $request, mixed $person_id) { - $person = $this->getDoctrine() + $person = $this->managerRegistry ->getRepository(Person::class) ->find($person_id); diff --git a/src/Bundle/ChillReportBundle/Controller/ReportController.php b/src/Bundle/ChillReportBundle/Controller/ReportController.php index 22830a8df..7b341e440 100644 --- a/src/Bundle/ChillReportBundle/Controller/ReportController.php +++ b/src/Bundle/ChillReportBundle/Controller/ReportController.php @@ -36,7 +36,8 @@ class ReportController extends AbstractController private readonly EventDispatcherInterface $eventDispatcher, private readonly AuthorizationHelper $authorizationHelper, private readonly PaginatorFactory $paginator, - private readonly TranslatorInterface $translator + private readonly TranslatorInterface $translator, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry ) {} /** @@ -50,7 +51,7 @@ class ReportController extends AbstractController */ public function createAction($person_id, $cf_group_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $entity = new Report(); $cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class) @@ -112,7 +113,7 @@ class ReportController extends AbstractController */ public function editAction(int|string $person_id, int|string $report_id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); /** @var Report $report */ $report = $em->getRepository('ChillReportBundle:Report')->find($report_id); @@ -154,7 +155,7 @@ class ReportController extends AbstractController */ public function exportAction($cf_group_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->find($cf_group_id); $reports = $em->getRepository('ChillReportBundle:Report')->findByCFGroup($cFGroup); @@ -180,7 +181,7 @@ class ReportController extends AbstractController */ public function listAction($person_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id); @@ -237,7 +238,7 @@ class ReportController extends AbstractController */ public function newAction($person_id, $cf_group_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id); $cFGroup = $em @@ -285,7 +286,7 @@ class ReportController extends AbstractController */ public function selectReportTypeAction($person_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class) ->find($person_id); @@ -355,7 +356,7 @@ class ReportController extends AbstractController return $this->redirectToRoute('report_export_list', ['cf_group_id' => $cFGroupId]); } - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $cFGroups = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class) ->findByEntity(\Chill\ReportBundle\Entity\Report::class); @@ -396,7 +397,7 @@ class ReportController extends AbstractController */ public function updateAction($person_id, $report_id, Request $request) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $report = $em->getRepository('ChillReportBundle:Report')->find($report_id); @@ -456,7 +457,7 @@ class ReportController extends AbstractController */ public function viewAction($report_id, $person_id) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $person = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($person_id); diff --git a/src/Bundle/ChillReportBundle/config/services/controller.yaml b/src/Bundle/ChillReportBundle/config/services/controller.yaml index eb11b0426..c96d09119 100644 --- a/src/Bundle/ChillReportBundle/config/services/controller.yaml +++ b/src/Bundle/ChillReportBundle/config/services/controller.yaml @@ -1,4 +1,8 @@ services: + _defaults: + autoconfigure: true + autowire: true + Chill\ReportBundle\Controller\ReportController: arguments: $eventDispatcher: '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface' diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 4c1687b5f..af517cda2 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -59,6 +59,7 @@ final class SingleTaskController extends AbstractController private readonly SingleTaskStateRepository $singleTaskStateRepository, private readonly SingleTaskRepository $singleTaskRepository, private readonly Security $security, + private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, ) {} /** @@ -70,7 +71,7 @@ final class SingleTaskController extends AbstractController public function deleteAction(Request $request, mixed $id) { $course = null; - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $task = $em->getRepository(SingleTask::class)->find($id); if (null === $task) { @@ -84,7 +85,7 @@ final class SingleTaskController extends AbstractController return new Response('You must provide a person_id', Response::HTTP_BAD_REQUEST); } - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(Person::class) ->find($personId); @@ -98,7 +99,7 @@ final class SingleTaskController extends AbstractController return new Response('You must provide a course_id', Response::HTTP_BAD_REQUEST); } - $course = $this->getDoctrine()->getManager() + $course = $this->managerRegistry->getManager() ->getRepository(AccompanyingPeriod::class) ->find($courseId); @@ -127,7 +128,7 @@ final class SingleTaskController extends AbstractController // 'scope_id' => $task->getScope()->getId(), ]); - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->remove($task); $em->flush(); @@ -185,7 +186,7 @@ final class SingleTaskController extends AbstractController if ($form->isSubmitted()) { if ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($task); $em->flush(); @@ -515,7 +516,7 @@ final class SingleTaskController extends AbstractController switch ($entityType) { case 'person': - $person = $this->getDoctrine()->getManager() + $person = $this->managerRegistry->getManager() ->getRepository(Person::class) ->find($entityId); @@ -529,7 +530,7 @@ final class SingleTaskController extends AbstractController break; case 'course': - $course = $this->getDoctrine()->getManager() + $course = $this->managerRegistry->getManager() ->getRepository(AccompanyingPeriod::class) ->find($entityId); @@ -555,7 +556,7 @@ final class SingleTaskController extends AbstractController if ($form->isSubmitted()) { if ($form->isValid()) { - $em = $this->getDoctrine()->getManager(); + $em = $this->managerRegistry->getManager(); $em->persist($task); $this->eventDispatcher->dispatch(new TaskEvent($task), TaskEvent::PERSIST); diff --git a/src/Bundle/ChillTaskBundle/config/services/controller.yaml b/src/Bundle/ChillTaskBundle/config/services/controller.yaml index 76799c72d..d8f4bf7ca 100644 --- a/src/Bundle/ChillTaskBundle/config/services/controller.yaml +++ b/src/Bundle/ChillTaskBundle/config/services/controller.yaml @@ -2,5 +2,5 @@ services: Chill\TaskBundle\Controller\: resource: "../../Controller" autowire: true - autoconfigure: ture + autoconfigure: true tags: ["controller.service_arguments"]