From 6d04e477f810598d8e2001fa81cb6139c8bdfabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 28 Nov 2023 13:00:04 +0100 Subject: [PATCH] Clean database, to avoid double participations on event --- .../ChillEventBundle/Entity/Participation.php | 37 ++++++------------- .../Resources/views/Event/edit.html.twig | 10 ++--- .../migrations/Version20231128114959.php | 33 +++++++++++++++++ .../translations/messages.fr.yml | 1 + 4 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 src/Bundle/ChillEventBundle/migrations/Version20231128114959.php diff --git a/src/Bundle/ChillEventBundle/Entity/Participation.php b/src/Bundle/ChillEventBundle/Entity/Participation.php index 1f7040c05..8076e8f5f 100644 --- a/src/Bundle/ChillEventBundle/Entity/Participation.php +++ b/src/Bundle/ChillEventBundle/Entity/Participation.php @@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\Scope; use Chill\PersonBundle\Entity\Person; use DateTime; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; /** @@ -30,7 +31,9 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; * @ORM\Entity( * repositoryClass="Chill\EventBundle\Repository\ParticipationRepository") * - * @ORM\Table(name="chill_event_participation") + * @ORM\Table(name="chill_event_participation", uniqueConstraints={ + * @ORM\UniqueConstraint(name="chill_event_participation_event_person_unique_idx", columns={"event_id", "person_id"}) + * }) * * @ORM\HasLifecycleCallbacks */ @@ -55,30 +58,28 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ private ?int $id = null; - /** - * @ORM\Column(type="datetime") - */ - private ?\DateTime $lastUpdate = null; - /** * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") + * @Assert\NotNull() */ private ?Person $person = null; /** * @ORM\ManyToOne(targetEntity="Chill\EventBundle\Entity\Role") + * @Assert\NotNull() */ private ?Role $role = null; /** * @ORM\ManyToOne(targetEntity="Chill\EventBundle\Entity\Status") + * @Assert\NotNull() */ private ?Status $status = null; /** * @return Center */ - public function getCenter() + public function getCenter(): null|Center { if (null === $this->getEvent()) { throw new \RuntimeException('The event is not linked with this instance. You should initialize the event with a valid center before.'); @@ -100,7 +101,7 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa * * @return int */ - public function getId() + public function getId(): int { return $this->id; } @@ -112,7 +113,7 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ public function getLastUpdate() { - return $this->lastUpdate; + return $this->getUpdatedAt(); } /** @@ -242,10 +243,6 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ public function setEvent(?Event $event = null) { - if ($this->event !== $event) { - $this->update(); - } - $this->event = $event; return $this; @@ -258,10 +255,6 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ public function setPerson(?Person $person = null) { - if ($person !== $this->person) { - $this->update(); - } - $this->person = $person; return $this; @@ -274,9 +267,6 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ public function setRole(?Role $role = null) { - if ($role !== $this->role) { - $this->update(); - } $this->role = $role; return $this; @@ -289,10 +279,6 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa */ public function setStatus(?Status $status = null) { - if ($this->status !== $status) { - $this->update(); - } - $this->status = $status; return $this; @@ -302,11 +288,10 @@ class Participation implements \ArrayAccess, HasCenterInterface, HasScopeInterfa * Set lastUpdate. * * @return Participation + * @deprecated */ protected function update() { - $this->lastUpdate = new \DateTime('now'); - return $this; } } diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig index a528f1f5c..af1e32cec 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig @@ -15,14 +15,10 @@ {{ form_row(edit_form.type, { 'label': 'Event type' }) }} {{ form_row(edit_form.moderator) }} -