From 2ca04d2512158906dcdc986554381cfcd9158e1a Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 2 Jul 2024 23:17:44 +0200 Subject: [PATCH] Revert "chore: remove getPlatformName()" This reverts commit 1894de466dbc7a61a32eb84514d44a6dab339e9c. --- .../DatabaseTools/AbstractDatabaseTool.php | 2 + .../AbstractDbalDatabaseTool.php | 47 +++++++++++++++++++ .../DatabaseTools/ORMDatabaseTool.php | 11 +---- 3 files changed, 50 insertions(+), 10 deletions(-) create mode 100755 src/Services/DatabaseTools/AbstractDbalDatabaseTool.php diff --git a/src/Services/DatabaseTools/AbstractDatabaseTool.php b/src/Services/DatabaseTools/AbstractDatabaseTool.php index 22c73d17..495d36a5 100644 --- a/src/Services/DatabaseTools/AbstractDatabaseTool.php +++ b/src/Services/DatabaseTools/AbstractDatabaseTool.php @@ -263,4 +263,6 @@ protected function getCacheMetadataParameter() return $this->container->hasParameter(self::CACHE_METADATA_PARAMETER_NAME) && false !== $this->container->getParameter(self::CACHE_METADATA_PARAMETER_NAME); } + + abstract protected function getPlatformName(): string; } diff --git a/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php b/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php new file mode 100755 index 00000000..8abdba98 --- /dev/null +++ b/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php @@ -0,0 +1,47 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Liip\TestFixturesBundle\Services\DatabaseTools; + +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; + +abstract class AbstractDbalDatabaseTool extends AbstractDatabaseTool +{ + protected Connection $connection; + + public function setObjectManagerName(?string $omName = null): void + { + parent::setObjectManagerName($omName); + $this->connection = $this->registry->getConnection($omName); + } + + protected function getPlatformName(): string + { + $platform = $this->connection->getDatabasePlatform(); + + // AbstractMySQLPlatform was introduced in DBAL 3.3, keep the MySQLPlatform checks for compatibility with older versions + if ($platform instanceof AbstractMySQLPlatform || $platform instanceof MySqlPlatform) { + return 'mysql'; + } elseif ($platform instanceof SqlitePlatform) { + return 'sqlite'; + } elseif ($platform instanceof PostgreSQLPlatform) { + return 'pgsql'; + } + + return (new \ReflectionClass($platform))->getShortName(); + } +} diff --git a/src/Services/DatabaseTools/ORMDatabaseTool.php b/src/Services/DatabaseTools/ORMDatabaseTool.php index 287b9ae9..06acd911 100644 --- a/src/Services/DatabaseTools/ORMDatabaseTool.php +++ b/src/Services/DatabaseTools/ORMDatabaseTool.php @@ -17,7 +17,6 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\ProxyReferenceRepository; use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\ORM\Configuration; @@ -32,7 +31,7 @@ /** * @author Aleksey Tupichenkov */ -class ORMDatabaseTool extends AbstractDatabaseTool +class ORMDatabaseTool extends AbstractDbalDatabaseTool { /** * @var EntityManager @@ -44,14 +43,6 @@ class ORMDatabaseTool extends AbstractDatabaseTool */ private $shouldEnableForeignKeyChecks = false; - protected Connection $connection; - - public function setObjectManagerName(?string $omName = null): void - { - parent::setObjectManagerName($omName); - $this->connection = $this->registry->getConnection($omName); - } - public function getType(): string { return 'ORM';