Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions module/Application/migrations/Version20250807174014.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

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

/**
* phpcs:disable Generic.Files.LineLength.TooLong
* phpcs:disable SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall
*/
final class Version20250807174014 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update mailing list definitions from GEWISDB.';
}

public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE MailingListMember (email VARCHAR(255) NOT NULL, member INT NOT NULL, mailingList VARCHAR(255) NOT NULL, INDEX IDX_3A8467A97B1AC3ED (mailingList), INDEX IDX_3A8467A970E4FA78 (member), UNIQUE INDEX mailinglistmember_unique_idx (mailingList, member, email), PRIMARY KEY(mailingList, member, email)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE MailingListMember ADD CONSTRAINT FK_3A8467A97B1AC3ED FOREIGN KEY (mailingList) REFERENCES MailingList (name)');
$this->addSql('ALTER TABLE MailingListMember ADD CONSTRAINT FK_3A8467A970E4FA78 FOREIGN KEY (member) REFERENCES Member (lidnr)');
$this->addSql('ALTER TABLE members_mailinglists DROP FOREIGN KEY FK_5AD357D95E237E06');
$this->addSql('ALTER TABLE members_mailinglists DROP FOREIGN KEY FK_5AD357D9D665E01D');
$this->addSql('DROP TABLE members_mailinglists');
$this->addSql('ALTER TABLE MailingList DROP onForm, DROP defaultSub');
}

public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE members_mailinglists (lidnr INT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, INDEX IDX_5AD357D95E237E06 (name), INDEX IDX_5AD357D9D665E01D (lidnr), PRIMARY KEY(lidnr, name)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE members_mailinglists ADD CONSTRAINT FK_5AD357D95E237E06 FOREIGN KEY (name) REFERENCES MailingList (name)');
$this->addSql('ALTER TABLE members_mailinglists ADD CONSTRAINT FK_5AD357D9D665E01D FOREIGN KEY (lidnr) REFERENCES Member (lidnr)');
$this->addSql('ALTER TABLE MailingListMember DROP FOREIGN KEY FK_3A8467A97B1AC3ED');
$this->addSql('ALTER TABLE MailingListMember DROP FOREIGN KEY FK_3A8467A970E4FA78');
$this->addSql('DROP TABLE MailingListMember');
$this->addSql('ALTER TABLE MailingList ADD onForm TINYINT(1) NOT NULL, ADD defaultSub TINYINT(1) NOT NULL');
}
}
104 changes: 14 additions & 90 deletions module/Decision/src/Model/MailingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\OneToMany;

/**
* Mailing List model.
* Mailing List model (partial)
*
* ReportDB does not know about mailman and doesn't need to know.
*
* @psalm-type MailingListGdprArrayType = array{
* name: string,
Expand All @@ -24,7 +26,7 @@
class MailingList
{
/**
* Mailman-identifier / name.
* Name of the mailing list
*/
#[Id]
#[Column(type: 'string')]
Expand All @@ -42,34 +44,20 @@ class MailingList
#[Column(type: 'text')]
protected string $en_description;

/**
* If the mailing list should be on the form.
*/
#[Column(type: 'boolean')]
protected bool $onForm;

/**
* If members should be subscribed by default.
*
* (when it is on the form, that means that the checkbox is checked by default)
*/
#[Column(type: 'boolean')]
protected bool $defaultSub;

/**
* Mailing list members.
*
* @var Collection<array-key, Member>
* @var Collection<array-key, MailingListMember>
*/
#[ManyToMany(
targetEntity: Member::class,
mappedBy: 'lists',
#[OneToMany(
targetEntity: MailingListMember::class,
mappedBy: 'mailingList',
)]
protected Collection $members;
protected Collection $mailingListMemberships;

public function __construct()
{
$this->members = new ArrayCollection();
$this->mailingListMemberships = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -120,78 +108,14 @@ public function setNlDescription(string $description): void
$this->nl_description = $description;
}

/**
* Get the description.
*/
public function getDescription(): string
{
return $this->getNlDescription();
}

/**
* Set the description.
*/
public function setDescription(string $description): void
{
$this->setNlDescription($description);
}

/**
* Get if it should be on the form.
*/
public function getOnForm(): bool
{
return $this->onForm;
}

/**
* Set if it should be on the form.
*/
public function setOnForm(bool $onForm): void
{
$this->onForm = $onForm;
}

/**
* Get if it is a default list.
*/
public function getDefaultSub(): bool
{
return $this->defaultSub;
}

/**
* Set if it is a default list.
*/
public function setDefaultSub(bool $default): void
{
$this->defaultSub = $default;
}

/**
* Get subscribed members.
*
* @return Collection<array-key, Member>
*/
public function getMembers(): Collection
{
return $this->members;
}

/**
* Add a member.
*/
public function addMember(Member $member): void
{
$this->members[] = $member;
}

/**
* Remove a member.
* @return Collection<array-key, MailingListMember>
*/
public function removeMember(Member $member): void
public function getMailingListMemberships(): Collection
{
$this->members->removeElement($member);
return $this->mailingListMemberships;
}

/**
Expand Down
136 changes: 136 additions & 0 deletions module/Decision/src/Model/MailingListMember.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

declare(strict_types=1);

namespace Decision\Model;

use Decision\Model\MailingList as MailingListModel;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\UniqueConstraint;

/**
* Mailing List Member model (partial)
*
* To allow having additional properties in the many-to-many association between {@see MailingList}s and {@see Member}s
* we use this class as a connector.
*
* Report assumes a full sync has happened (e.g. toBeDeleted entires don't exist)
*
* @psalm-import-type MailingListGdprArrayType from MailingListModel as ImportedMailingListGdprArrayType
* @psalm-type MailingListMemberGdprArrayType = array{
* list: ImportedMailingListGdprArrayType,
* email: string,
* }
*/
#[Entity]
#[UniqueConstraint(
name: 'mailinglistmember_unique_idx',
columns: ['mailingList', 'member', 'email'],
)]
class MailingListMember
{
/**
* Mailing list.
*/
#[Id]
#[ManyToOne(
targetEntity: MailingList::class,
inversedBy: 'mailingListMemberships',
)]
#[JoinColumn(
name: 'mailingList',
referencedColumnName: 'name',
)]
private MailingList $mailingList;

/**
* Member.
*/
#[Id]
#[ManyToOne(
targetEntity: Member::class,
inversedBy: 'mailingListMemberships',
)]
#[JoinColumn(
name: 'member',
referencedColumnName: 'lidnr',
)]
private Member $member;

/**
* Email address on the list
*/
#[Id]
#[Column(
type: 'string',
nullable: false,
)]
private string $email;

public function __construct()
{
}

/**
* Get the mailing list.
*/
public function getMailingList(): MailingList
{
return $this->mailingList;
}

/**
* Set the mailing list.
*/
public function setMailingList(MailingList $mailingList): void
{
$this->mailingList = $mailingList;
}

/**
* Get the member.
*/
public function getMember(): Member
{
return $this->member;
}

/**
* Set the member.
*/
public function setMember(Member $member): void
{
$this->member = $member;
}

/**
* Get the email address of this subscription
*/
public function getEmail(): string
{
return $this->email;
}

/**
* Set the email address of this subscription
*/
public function setEmail(string $email): void
{
$this->email = $email;
}

/**
* @return MailingListMemberGdprArrayType
*/
public function toGdprArray(): array
{
return [
'list' => $this->mailingList->toGdprArray(),
'email' => $this->getEmail(),
];
}
}
Loading
Loading