From 09f9ef1ef5b57e1b650d7303b4f24a8e7dd7ac41 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sat, 7 Dec 2024 22:52:05 -0500 Subject: [PATCH] Fix bug to delete previous supervision before applying new --- src/Controller/AdminController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 4b9691b..1b519a9 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -205,6 +205,7 @@ class AdminController extends AbstractController /** @var User $user */ $user = $userRepo->find($id); + $prevSup = $this->entityManager->getRepository(Supervision::class)->findBy(['user' => $user]); $form = $this->createForm(SupervisorFormType::class); $form->handleRequest($request); @@ -212,6 +213,11 @@ class AdminController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $supervisor = $form->get('supervisor')->getData(); + if (count($prevSup) > 0) { + $this->entityManager->remove($prevSup[0]); + $this->entityManager->flush(); + } + $sup = new Supervision(); $sup->setSupervisor($supervisor); $sup->setWorker($user);