mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Clean database, to avoid double participations on event
This commit is contained in:
parent
6b7b2ae522
commit
6d04e477f8
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,10 @@
|
||||
{{ form_row(edit_form.type, { 'label': 'Event type' }) }}
|
||||
{{ form_row(edit_form.moderator) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="cancel">
|
||||
|
||||
{% set returnPath = app.request.get('return_path') %}
|
||||
{% set returnLabel = app.request.get('return_label') %}
|
||||
|
||||
<a href="{{ returnPath |default( path('chill_event_list_most_recent') ) }}" class="btn btn-cancel">
|
||||
{{ returnLabel |default('Back to the most recent events'|trans) }}
|
||||
<a href="{{ chill_path_add_return_path('chill_event_event_list') }}" class="btn btn-cancel">
|
||||
{{ 'List of events'|trans|chill_return_path_label }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Event;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20231128114959 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add unique index on participation and drop column participation::lastUpdate';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('UPDATE chill_event_participation SET updatedAt=lastupdate WHERE updatedat IS NULL');
|
||||
$this->addSql('ALTER TABLE chill_event_participation DROP lastupdate');
|
||||
$this->addSql('WITH ordering AS (SELECT id, event_id, person_id, rank() OVER (PARTITION BY event_id, person_id ORDER BY id DESC) as ranked FROM chill_event_participation),
|
||||
not_last AS (SELECT * FROM ordering where ranked > 1)
|
||||
DELETE FROM chill_event_participation WHERE id IN (select id FROM not_last)');
|
||||
$this->addSql('CREATE UNIQUE INDEX chill_event_participation_event_person_unique_idx ON chill_event_participation (event_id, person_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP INDEX chill_event_participation_event_person_unique_idx');
|
||||
$this->addSql('ALTER TABLE chill_event_participation ADD lastupdate TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL');
|
||||
$this->addSql('UPDATE chill_event_participation set lastupdate = updatedat');
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ Event edit: Modifier un événement
|
||||
Edit the event: Modifier l'événement
|
||||
The event was updated: L'événement a été modifié
|
||||
The event was created: L'événement a été créé
|
||||
List of events: Liste des événements
|
||||
|
||||
#crud participation
|
||||
Edit all the participations: Modifier toutes les participations
|
||||
|
Loading…
x
Reference in New Issue
Block a user