Skip to content

Commit

Permalink
[Event] add unique constraint on eventRegistration (#11316)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano authored Jan 15, 2025
1 parent 295576f commit 1e2c05e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
33 changes: 33 additions & 0 deletions migrations/Version20250114160957.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250114160957 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE events_registrations CHANGE email_address email_address VARCHAR(255) DEFAULT NULL');

$this->addSql('UPDATE events_registrations SET email_address = NULL WHERE email_address = \'\' OR email_address = \'null\'');
$this->addSql('UPDATE events_registrations SET adherent_uuid = NULL WHERE adherent_uuid = \'\' OR adherent_uuid = \'null\'');

$this->addSql('CREATE UNIQUE INDEX UNIQ_EEFA30C06D80402471F7E88B ON events_registrations (adherent_uuid, event_id)');
$this->addSql('ALTER TABLE
events_registrations RENAME INDEX event_registration_email_address_idx TO IDX_EEFA30C0B08E074E');
$this->addSql('ALTER TABLE
events_registrations RENAME INDEX event_registration_adherent_uuid_idx TO IDX_EEFA30C06D804024');
}

public function down(Schema $schema): void
{
$this->addSql('DROP INDEX UNIQ_EEFA30C06D80402471F7E88B ON events_registrations');
$this->addSql('ALTER TABLE events_registrations CHANGE email_address email_address VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE
events_registrations RENAME INDEX idx_eefa30c06d804024 TO event_registration_adherent_uuid_idx');
$this->addSql('ALTER TABLE
events_registrations RENAME INDEX idx_eefa30c0b08e074e TO event_registration_email_address_idx');
}
}
2 changes: 1 addition & 1 deletion src/DataFixtures/ORM/LoadDefaultEventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function loadEvents(ObjectManager $manager): void
$senatorialCandidate = $this->getReference('senatorial-candidate', Adherent::class);
$adherent5 = $this->getReference('adherent-5', Adherent::class);
$adherentRe4 = $this->getReference('renaissance-user-4', Adherent::class);
$pad92 = $this->getReference('renaissance-user-4', Adherent::class);
$pad92 = $this->getReference('president-ad-1', Adherent::class);

$eventCategory7 = $this->getReference('CE007', EventCategory::class);

Expand Down
12 changes: 4 additions & 8 deletions src/Entity/Event/EventRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: EventRegistrationRepository::class)]
#[ORM\Index(columns: ['email_address'], name: 'event_registration_email_address_idx')]
#[ORM\Index(columns: ['adherent_uuid'], name: 'event_registration_adherent_uuid_idx')]
#[ORM\Index(columns: ['email_address'])]
#[ORM\Index(columns: ['adherent_uuid'])]
#[ORM\Table(name: 'events_registrations')]
#[ORM\UniqueConstraint(columns: ['adherent_uuid', 'event_id'])]
class EventRegistration
{
use EntityIdentityTrait;
Expand All @@ -22,7 +23,7 @@ class EventRegistration
#[ORM\ManyToOne(targetEntity: BaseEvent::class)]
private $event;

#[ORM\Column]
#[ORM\Column(nullable: true)]
private $emailAddress;

#[ORM\Column(length: 15, nullable: true)]
Expand Down Expand Up @@ -94,11 +95,6 @@ public function isEventFinished(): bool
return $this->event->isFinished();
}

public function getAttendedAt(): \DateTimeImmutable
{
return \DateTimeImmutable::createFromMutable($this->event->getBeginAt());
}

public function getFullName(): string
{
return $this->firstName.' '.$this->lastName;
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/EventRegistrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public function anonymizeAdherentRegistrations(Adherent $adherent): void
$qb = $this->createQueryBuilder('r');

$qb->update()
->set('r.adherentUuid', $qb->expr()->literal('null'))
->set('r.adherentUuid', 'NULL')
->set('r.firstName', $qb->expr()->literal('Anonyme'))
->set('r.emailAddress', $qb->expr()->literal('null'))
->set('r.emailAddress', 'NULL')
->where('r.adherentUuid = :uuid')
->setParameter(':uuid', $adherent->getUuid()->toString())
->getQuery()
Expand Down

0 comments on commit 1e2c05e

Please sign in to comment.