Loading module/Oscar/src/Oscar/Controller/PersonController.php +1 −35 Original line number Diff line number Diff line Loading @@ -102,46 +102,12 @@ class PersonController extends AbstractOscarController return $this->getResponseBadRequest("Opération non-authorisée"); } // TODO Mettre ça dans PersonService $this->getPersonDeleteService()->delete($this->params()->fromRoute('id')); $person = $this->getPersonService()->getPersonById($this->params()->fromRoute('id'), true); // Test de déclaration // TODO Tester si la personne est déclarante, et lever une exception $del = $this->getEntityManager()->createQueryBuilder()->delete(NotificationPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(ProjectMember::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(ActivityPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(OrganizationPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $this->getEntityManager()->remove($person); $this->getEntityManager()->flush(); if ($this->getOscarUserContextService()->check(Privileges::PERSON_INDEX)) { $this->redirect()->toRoute('person/index'); } $this->redirect()->toRoute('home'); } catch (ForeignKeyConstraintViolationException $e) { $this->getLoggerService()->error($e->getMessage()); throw new OscarException("Impossible de supprimer $person, elle est utilisée."); } catch (\Exception $e) { throw new OscarException("PAS POSSIBLE : " . $e->getMessage()); } Loading module/Oscar/src/Oscar/Service/PersonDeleteService.php +10 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Oscar\Service; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Oscar\Entity\ActivityPerson; use Oscar\Entity\OrganizationPerson; use Oscar\Entity\Person; Loading @@ -16,14 +17,17 @@ use Oscar\Exception\OscarException; use Oscar\Provider\Privileges; use Oscar\Traits\UseEntityManager; use Oscar\Traits\UseEntityManagerTrait; use Oscar\Traits\UseLoggerService; use Oscar\Traits\UseLoggerServiceTrait; use Oscar\Traits\UseOscarUserContextService; use Oscar\Traits\UseOscarUserContextServiceTrait; class PersonDeleteService implements UseOscarUserContextService, UseEntityManager class PersonDeleteService implements UseOscarUserContextService, UseEntityManager, UseLoggerService { use UseOscarUserContextServiceTrait, UseEntityManagerTrait; use UseOscarUserContextServiceTrait, UseEntityManagerTrait, UseLoggerServiceTrait; function delete(int $person_id) { try { $this->getOscarUserContextService()->check(Privileges::PERSON_EDIT); $person = $this->getEntityManager()->getRepository(Person::class)->find($person_id); Loading Loading @@ -78,5 +82,9 @@ class PersonDeleteService implements UseOscarUserContextService, UseEntityManage $this->getEntityManager()->remove($person); $this->getEntityManager()->flush(); } catch (ForeignKeyConstraintViolationException $e) { $this->getLoggerService()->error($e->getMessage()); throw new OscarException("Impossible de supprimer $person_id, elle est utilisée."); } } } module/Oscar/src/Oscar/Service/PersonDeleteServiceFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ class PersonDeleteServiceFactory implements FactoryInterface $s = new PersonDeleteService(); $s->setOscarUserContextService($container->get(OscarUserContext::class)); $s->setEntityManager($container->get(EntityManager::class)); $s->setLoggerService($container->get('Logger')); return $s; } } Loading
module/Oscar/src/Oscar/Controller/PersonController.php +1 −35 Original line number Diff line number Diff line Loading @@ -102,46 +102,12 @@ class PersonController extends AbstractOscarController return $this->getResponseBadRequest("Opération non-authorisée"); } // TODO Mettre ça dans PersonService $this->getPersonDeleteService()->delete($this->params()->fromRoute('id')); $person = $this->getPersonService()->getPersonById($this->params()->fromRoute('id'), true); // Test de déclaration // TODO Tester si la personne est déclarante, et lever une exception $del = $this->getEntityManager()->createQueryBuilder()->delete(NotificationPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(ProjectMember::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(ActivityPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $del = $this->getEntityManager()->createQueryBuilder()->delete(OrganizationPerson::class, 'n') ->where('n.person = :person') ->setParameter('person', $person); $del->getQuery()->execute(); $this->getEntityManager()->remove($person); $this->getEntityManager()->flush(); if ($this->getOscarUserContextService()->check(Privileges::PERSON_INDEX)) { $this->redirect()->toRoute('person/index'); } $this->redirect()->toRoute('home'); } catch (ForeignKeyConstraintViolationException $e) { $this->getLoggerService()->error($e->getMessage()); throw new OscarException("Impossible de supprimer $person, elle est utilisée."); } catch (\Exception $e) { throw new OscarException("PAS POSSIBLE : " . $e->getMessage()); } Loading
module/Oscar/src/Oscar/Service/PersonDeleteService.php +10 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Oscar\Service; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Oscar\Entity\ActivityPerson; use Oscar\Entity\OrganizationPerson; use Oscar\Entity\Person; Loading @@ -16,14 +17,17 @@ use Oscar\Exception\OscarException; use Oscar\Provider\Privileges; use Oscar\Traits\UseEntityManager; use Oscar\Traits\UseEntityManagerTrait; use Oscar\Traits\UseLoggerService; use Oscar\Traits\UseLoggerServiceTrait; use Oscar\Traits\UseOscarUserContextService; use Oscar\Traits\UseOscarUserContextServiceTrait; class PersonDeleteService implements UseOscarUserContextService, UseEntityManager class PersonDeleteService implements UseOscarUserContextService, UseEntityManager, UseLoggerService { use UseOscarUserContextServiceTrait, UseEntityManagerTrait; use UseOscarUserContextServiceTrait, UseEntityManagerTrait, UseLoggerServiceTrait; function delete(int $person_id) { try { $this->getOscarUserContextService()->check(Privileges::PERSON_EDIT); $person = $this->getEntityManager()->getRepository(Person::class)->find($person_id); Loading Loading @@ -78,5 +82,9 @@ class PersonDeleteService implements UseOscarUserContextService, UseEntityManage $this->getEntityManager()->remove($person); $this->getEntityManager()->flush(); } catch (ForeignKeyConstraintViolationException $e) { $this->getLoggerService()->error($e->getMessage()); throw new OscarException("Impossible de supprimer $person_id, elle est utilisée."); } } }
module/Oscar/src/Oscar/Service/PersonDeleteServiceFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ class PersonDeleteServiceFactory implements FactoryInterface $s = new PersonDeleteService(); $s->setOscarUserContextService($container->get(OscarUserContext::class)); $s->setEntityManager($container->get(EntityManager::class)); $s->setLoggerService($container->get('Logger')); return $s; } }