mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 10:05:03 +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:
@@ -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]);
|
||||
|
Reference in New Issue
Block a user