From be3a0cd073e06d9ca059ec60a1b93664944c1ca7 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sat, 13 Jan 2024 18:22:41 +0100 Subject: [PATCH] feat: don't call deprecated method getName() on doctrine platform --- .../DatabaseTools/AbstractDatabaseTool.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Services/DatabaseTools/AbstractDatabaseTool.php b/src/Services/DatabaseTools/AbstractDatabaseTool.php index 5460b7be..e016cf61 100644 --- a/src/Services/DatabaseTools/AbstractDatabaseTool.php +++ b/src/Services/DatabaseTools/AbstractDatabaseTool.php @@ -16,6 +16,9 @@ use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader; use Doctrine\Common\DataFixtures\Executor\AbstractExecutor; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ObjectManager; use Liip\TestFixturesBundle\Services\DatabaseBackup\DatabaseBackupInterface; @@ -58,10 +61,7 @@ abstract class AbstractDatabaseTool */ protected $om; - /** - * @var Connection - */ - protected $connection; + protected Connection $connection; /** * @var int|null @@ -193,7 +193,7 @@ protected function getBackupService(): ?DatabaseBackupInterface { $backupServiceParamName = strtolower('liip_test_fixtures.cache_db.'.( ('ORM' === $this->getType()) - ? $this->connection->getDatabasePlatform()->getName() + ? $this->getPlatformName() : $this->getType() )); @@ -270,4 +270,19 @@ protected function getCacheMetadataParameter() return $this->container->hasParameter(self::CACHE_METADATA_PARAMETER_NAME) && false !== $this->container->getParameter(self::CACHE_METADATA_PARAMETER_NAME); } + + private function getPlatformName(): string + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof AbstractMySQLPlatform) { + return 'mysql'; + } elseif ($platform instanceof SqlitePlatform) { + return 'sqlite'; + } elseif ($platform instanceof PostgreSQLPlatform) { + return 'pgsql'; + } + + return (new \ReflectionClass($platform))->getShortName(); + } }