Internal: Fix duplicate entry error in session_rel_user table - refs BT#21913

pull/5709/head
christianbeeznst 1 year ago
parent a461f75cb5
commit bcc2ec174c
  1. 16
      src/CoreBundle/Repository/SessionRepository.php

@ -219,6 +219,18 @@ class SessionRepository extends ServiceEntityRepository
throw new Exception(sprintf('Cannot handle relationType %s', $relationType));
}
$entityManager = $this->getEntityManager();
$existingRecord = $entityManager->getRepository(SessionRelUser::class)->findOneBy([
'session' => $session,
'user' => $user,
'relationType' => $relationType,
]);
if ($existingRecord) {
$entityManager->remove($existingRecord);
$entityManager->flush();
}
switch ($relationType) {
case Session::DRH:
if ($user->hasRole('ROLE_HR')) {
@ -249,8 +261,12 @@ class SessionRepository extends ServiceEntityRepository
break;
}
$entityManager->persist($session);
$entityManager->flush();
}
/**
* @return array<SessionRelCourse>
*/

Loading…
Cancel
Save