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:
2023-12-16 19:09:34 +01:00
parent 655dc02538
commit 5703fd0046
54 changed files with 281 additions and 228 deletions

View File

@@ -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(),