From 524c2ce91c8a04e3c9508cd346745a5d02b9f85d Mon Sep 17 00:00:00 2001 From: Gassan Gousseinov Date: Tue, 17 Sep 2024 12:49:04 +0200 Subject: [PATCH] fix purge without foreign check on mariadb (doctrine/dbal:^4.0) --- 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; + } }