From e199795cab75b36859507300984126396507d2d1 Mon Sep 17 00:00:00 2001 From: Robert Baruck Date: Tue, 14 Nov 2023 16:25:32 +0100 Subject: [PATCH] BUGFIX: Correctly cascade deletion of second factor when deleting user --- Classes/Domain/Model/SecondFactor.php | 2 + Migrations/Mysql/Version20231114151915.php | 43 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Migrations/Mysql/Version20231114151915.php diff --git a/Classes/Domain/Model/SecondFactor.php b/Classes/Domain/Model/SecondFactor.php index 364c024..036cf86 100644 --- a/Classes/Domain/Model/SecondFactor.php +++ b/Classes/Domain/Model/SecondFactor.php @@ -23,6 +23,8 @@ class SecondFactor /** * @var Account * @ORM\ManyToOne + * If Account gets deleted also delete the second factors. + * @ORM\JoinColumn(onDelete="CASCADE") */ protected Account $account; diff --git a/Migrations/Mysql/Version20231114151915.php b/Migrations/Mysql/Version20231114151915.php new file mode 100644 index 0000000..b53950e --- /dev/null +++ b/Migrations/Mysql/Version20231114151915.php @@ -0,0 +1,43 @@ +abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'." + ); + + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor DROP FOREIGN KEY FK_29EF8A7F7D3656A4'); + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor ADD CONSTRAINT FK_29EF8A7F7D3656A4 FOREIGN KEY (account) REFERENCES neos_flow_security_account (persistence_object_identifier) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'." + ); + + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor DROP FOREIGN KEY FK_29EF8A7F7D3656A4'); + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor ADD CONSTRAINT FK_29EF8A7F7D3656A4 FOREIGN KEY (account) REFERENCES neos_flow_security_account (persistence_object_identifier)'); + } +}