mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 07:33:50 +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:
@@ -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();
|
||||
|
||||
|
@@ -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(
|
||||
|
@@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user