Skip to content

Commit

Permalink
fix purge without foreign check on mariadb (doctrine/dbal:^4.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
gassan committed Sep 18, 2024
1 parent 39a2fb2 commit 524c2ce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Bridge/Doctrine/Purger/Purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 524c2ce

Please sign in to comment.