Fix bug to delete previous supervision before applying new
This commit is contained in:
parent
2c623fd902
commit
09f9ef1ef5
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user