From 38daaf7e35e31bdd43143904fe9178d736ffa9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:39:40 +0100 Subject: [PATCH] fix: Disable foreign keys check for purge (#281) Co-authored-by: Gassan Gousseinov --- src/Bridge/Doctrine/Purger/Purger.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Doctrine/Purger/Purger.php b/src/Bridge/Doctrine/Purger/Purger.php index 0eee442..15c6e3c 100644 --- a/src/Bridge/Doctrine/Purger/Purger.php +++ b/src/Bridge/Doctrine/Purger/Purger.php @@ -17,6 +17,7 @@ use Doctrine\Common\DataFixtures\Purger\ORMPurger as DoctrineOrmPurger; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger as DoctrinePhpCrPurger; use Doctrine\Common\DataFixtures\Purger\PurgerInterface as DoctrinePurgerInterface; +use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\ODM\MongoDB\DocumentManager as DoctrineMongoDocumentManager; use Doctrine\ODM\PHPCR\DocumentManager as DoctrinePhpCrDocumentManager; @@ -93,7 +94,7 @@ public function purge(): void $disableFkChecks = ( $this->purger instanceof DoctrineOrmPurger && in_array($this->purgeMode->getValue(), [PurgeMode::createDeleteMode()->getValue(), PurgeMode::createTruncateMode()->getValue()]) - && $this->purger->getObjectManager()->getConnection()->getDatabasePlatform() instanceof MySqlPlatform + && $this->doesDatabaseSupportTruncate() ); if ($disableFkChecks) { @@ -136,4 +137,12 @@ private static function createPurger(ObjectManager $manager, ?PurgeMode $purgeMo ) ); } + + private function doesDatabaseSupportTruncate(): bool + { + $platform = $this->purger->getObjectManager()->getConnection()->getDatabasePlatform(); + + return $platform instanceof MySqlPlatform + || $platform instanceof MariaDBPlatform; + } }