mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Refactor code to directly use Doctrine's ManagerRegistry
Replaced most of the invocations of getDoctrine()->getManager() with ManagerRegistry->getManager(), and added ManagerRegistry injection to controllers where needed. This is part of an ongoing effort to improve code clarity, and avoid unnecessary method chaining in various parts of the codebase.
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user