diff --git a/src/DataFixtures/ConfirmerFixture.php b/src/DataFixtures/ConfirmerFixture.php new file mode 100644 index 0000000..ad1fc93 --- /dev/null +++ b/src/DataFixtures/ConfirmerFixture.php @@ -0,0 +1,40 @@ +setEmail('hhv@invalid.com'); + $confirmer->setName('HHV 1'); + $this->addReference(self::HHV_1, $confirmer); + $manager->persist($confirmer); + + $confirmer = new Confirmer(); + $confirmer->setEmail('treasurer@invalid.com'); + $confirmer->setName('Treasurer 1'); + $this->addReference(self::TREASURER_1, $confirmer); + $manager->persist($confirmer); + + $confirmer = new Confirmer(); + $confirmer->setEmail('treasurer2@invalid.com'); + $confirmer->setName('Treasurer 2'); + $this->addReference(self::TREASURER_2, $confirmer); + $manager->persist($confirmer); + + $manager->flush(); + } +} \ No newline at end of file diff --git a/src/DataFixtures/DepartmentFixture.php b/src/DataFixtures/DepartmentFixture.php index 4b72fb4..9e42a56 100644 --- a/src/DataFixtures/DepartmentFixture.php +++ b/src/DataFixtures/DepartmentFixture.php @@ -3,13 +3,15 @@ namespace App\DataFixtures; use App\Entity\BankAccount; +use App\Entity\Confirmer; use App\Entity\Department; use App\Entity\DepartmentTypes; use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ObjectManager; -final class DepartmentFixture extends Fixture +final class DepartmentFixture extends Fixture implements DependentFixtureInterface { public const DEPARTMENT1_REFERENCE = 'department1'; public const DEPARTMENT2_REFERENCE = 'department2'; @@ -35,8 +37,9 @@ public function load(ObjectManager $manager): void $department->setBlocked(true); $department->setSkipBlockedValidationTokens(['token1', 'token2']); $department->setContactEmails(['test@invalid.com', 'test@invalid.de']); - $department->setEmailHhv(['hhv@invalid.com']); - $department->setEmailTreasurer(['treasurer@invalid.com', 'treasurer2@invalid.com']); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::HHV_1, Confirmer::class)); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::TREASURER_1, Confirmer::class)); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::TREASURER_2, Confirmer::class)); $this->addReference(self::DEPARTMENT2_REFERENCE, $department); $manager->persist($department); @@ -46,8 +49,9 @@ public function load(ObjectManager $manager): void $department->setBankAccount($this->getReference(BankAccountFixture::BANK_ACCOUNT1_REFERENCE, BankAccount::class)); $department->setComment('Test'); $department->setContactEmails(['test@invalid.com', 'test@invalid.de']); - $department->setEmailHhv(['hhv@invalid.com']); - $department->setEmailTreasurer(['treasurer@invalid.com', 'treasurer2@invalid.com']); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::HHV_1, Confirmer::class)); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::TREASURER_1, Confirmer::class)); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::TREASURER_2, Confirmer::class)); $this->addReference(self::DEPARTMENT3_REFERENCE, $department); $manager->persist($department); @@ -63,10 +67,17 @@ public function load(ObjectManager $manager): void $department->setName('Department 5'); $department->setType(DepartmentTypes::SECTION); $department->setBankAccount($this->getReference(BankAccountFixture::BANK_ACCOUNT3_REFERENCE, BankAccount::class)); - $department->setEmailHhv(['hhv@invalid.com']); + $department->getConfirmers()->add($this->getReference(ConfirmerFixture::HHV_1, Confirmer::class)); $this->addReference(self::DEPARTMENT5_REFERENCE, $department); $manager->persist($department); $manager->flush(); } + + public function getDependencies(): array + { + return [ + ConfirmerFixture::class + ]; + } } diff --git a/src/DataFixtures/PaymentOrderFixture.php b/src/DataFixtures/PaymentOrderFixture.php index ed85960..c8dae3f 100644 --- a/src/DataFixtures/PaymentOrderFixture.php +++ b/src/DataFixtures/PaymentOrderFixture.php @@ -2,19 +2,30 @@ namespace App\DataFixtures; +use App\Entity\ConfirmationToken; +use App\Entity\Confirmer; use App\Entity\Department; use App\Entity\PaymentOrder; use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ObjectManager; use Symfony\Component\HttpFoundation\File\UploadedFile; -final class PaymentOrderFixture extends Fixture +final class PaymentOrderFixture extends Fixture implements DependentFixtureInterface { public function __construct() { } + public function getDependencies(): array + { + return [ + DepartmentFixture::class, + ConfirmerFixture::class, + ]; + } + public function load(ObjectManager $manager): void { $payment_order = new PaymentOrder(); @@ -26,8 +37,21 @@ public function load(ObjectManager $manager): void $payment_order->setDepartment($this->getReference(DepartmentFixture::DEPARTMENT3_REFERENCE, Department::class)); $payment_order->setAmount(12340); $payment_order->setComment('Test'); - $payment_order->setConfirm1Token(password_hash('token1', PASSWORD_DEFAULT)); - $payment_order->setConfirm2Token(password_hash('token2', PASSWORD_DEFAULT)); + + $token1 = new ConfirmationToken( + confirmer: $this->getReference(ConfirmerFixture::HHV_1, Confirmer::class), + paymentOrder: $payment_order, + hashedToken: password_hash('token1', PASSWORD_DEFAULT) + ); + $payment_order->addConfirmationToken($token1); + + $token2 = new ConfirmationToken( + confirmer: $this->getReference(ConfirmerFixture::TREASURER_1, Confirmer::class), + paymentOrder: $payment_order, + hashedToken: password_hash('token2', PASSWORD_DEFAULT) + ); + $payment_order->addConfirmationToken($token2); + $payment_order->getBankInfo() ->setAccountOwner('John Doe'); $payment_order->getBankInfo() @@ -51,8 +75,12 @@ public function load(ObjectManager $manager): void $payment_order->setDepartment($this->getReference(DepartmentFixture::DEPARTMENT2_REFERENCE, Department::class)); $payment_order->setAmount(12340); $payment_order->setComment('Test'); - $payment_order->setConfirm1Token(password_hash('token1', PASSWORD_DEFAULT)); - $payment_order->setConfirm2Token(null); + $token1 = new ConfirmationToken( + confirmer: $this->getReference(ConfirmerFixture::HHV_1, Confirmer::class), + paymentOrder: $payment_order, + hashedToken: password_hash('token1', PASSWORD_DEFAULT) + ); + $payment_order->addConfirmationToken($token1); $payment_order->getBankInfo() ->setAccountOwner('John Doe'); $payment_order->getBankInfo() diff --git a/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php b/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php index 0fbf6cd..7463081 100644 --- a/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php +++ b/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php @@ -31,12 +31,8 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; -use function array_reverse; -use function assert; -use function count; -use function is_callable; -use function method_exists; -use function preg_match; +use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping; + /** * Class responsible for purging databases of data before reloading data fixtures. @@ -160,7 +156,7 @@ public function purge(): void foreach ($orderedTables as $tbl) { // If we have a filter expression, check it and skip if necessary - if (! $emptyFilterExpression && ! preg_match($filterExpr, (string) $tbl)) { + if (in_array($tbl, $this->excluded)) { continue; } @@ -301,21 +297,16 @@ private function getTableName(ClassMetadata $class, AbstractPlatform $platform): return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } + /** @param ManyToManyOwningSideMapping|mixed[] $assoc */ private function getJoinTableName( - array $assoc, + $assoc, ClassMetadata $class, - AbstractPlatform $platform + AbstractPlatform $platform, ): string { - if (isset($assoc['joinTable']['schema']) && ! method_exists($class, 'getSchemaName')) { - return $assoc['joinTable']['schema'] . '.' . - $this->em->getConfiguration() - ->getQuoteStrategy() - ->getJoinTableName($assoc, $class, $platform); - } - return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } + private function getDeleteFromTableSQL(string $tableName, AbstractPlatform $platform): string { $tableIdentifier = new Identifier($tableName); diff --git a/src/Entity/PaymentOrder.php b/src/Entity/PaymentOrder.php index 36d5bc1..30e851f 100644 --- a/src/Entity/PaymentOrder.php +++ b/src/Entity/PaymentOrder.php @@ -286,7 +286,7 @@ class PaymentOrder implements DBElementInterface, TimestampedElementInterface, \ /** * @var Collection The confirmation tokens that can be used to confirm this payment order */ - #[ORM\OneToMany(targetEntity: ConfirmationToken::class, mappedBy: 'paymentOrder', orphanRemoval: true)] + #[ORM\OneToMany(targetEntity: ConfirmationToken::class, mappedBy: 'paymentOrder', orphanRemoval: true, cascade: ['persist', 'remove'])] private Collection $confirmationTokens; public function __construct()