mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33: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:
@@ -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([
|
||||
|
Reference in New Issue
Block a user