From 1fff8b0f867dfae95a1fdfc621c454ef4abed4ab Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 11 Mar 2024 09:47:49 -0400 Subject: [PATCH 1/3] Update minimum required versions of optional integrations, add conflicts to prevent installing newer releases with incompatible versions --- composer.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 1a3ac779..c7193ae9 100644 --- a/composer.json +++ b/composer.json @@ -26,8 +26,8 @@ }, "require-dev": { "doctrine/data-fixtures": "^1.7", - "doctrine/doctrine-bundle": "^2.11", - "doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0", + "doctrine/doctrine-bundle": "^2.8", + "doctrine/doctrine-fixtures-bundle": "^3.4.4 || ^4.0", "doctrine/mongodb-odm-bundle": "^4.4 || ^5.0", "doctrine/orm": "^2.7", "doctrine/mongodb-odm": "^2.5", @@ -39,8 +39,10 @@ "theofidry/alice-data-fixtures": "^1.5.2" }, "conflict": { - "doctrine/annotations": "<1.2.7 || >=3.0", - "doctrine/dbal": "<2.11" + "doctrine/annotations": "<1.13.1 || >=3.0", + "doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0", + "doctrine/mongodb-odm": "<2.2 || >=3.0", + "doctrine/orm": "<2.14 || >=3.0" }, "suggest": { "doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite", From fd7bef7dbcab456a511bd21747de9c12745d1d2c Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 11 Mar 2024 13:05:46 -0400 Subject: [PATCH 2/3] Resolve DBAL 2.13 compat issues --- src/Services/DatabaseTools/AbstractDbalDatabaseTool.php | 6 ++++-- src/Services/DatabaseTools/ORMDatabaseTool.php | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php b/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php index 30ce62e0..8abdba98 100755 --- a/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php +++ b/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -32,7 +33,8 @@ protected function getPlatformName(): string { $platform = $this->connection->getDatabasePlatform(); - if ($platform instanceof AbstractMySQLPlatform) { + // 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'; @@ -40,6 +42,6 @@ protected function getPlatformName(): string return 'pgsql'; } - return parent::getPlatformName(); + return (new \ReflectionClass($platform))->getShortName(); } } diff --git a/src/Services/DatabaseTools/ORMDatabaseTool.php b/src/Services/DatabaseTools/ORMDatabaseTool.php index f587fabe..00dea6bd 100644 --- a/src/Services/DatabaseTools/ORMDatabaseTool.php +++ b/src/Services/DatabaseTools/ORMDatabaseTool.php @@ -126,9 +126,12 @@ protected function createDatabaseIfNotExists(): void $tmpConnection = DriverManager::getConnection($params); + $schemaManager = $tmpConnection->createSchemaManager(); + + // DBAL 4.x does not support creating databases for SQLite anymore; for now we silently ignore this error try { - if (!\in_array($dbName, $tmpConnection->createSchemaManager()->listDatabases(), true)) { - $tmpConnection->createSchemaManager()->createDatabase($dbName); + if (!\in_array($dbName, $schemaManager->listDatabases(), true)) { + $schemaManager->createDatabase($dbName); } } catch (\Doctrine\DBAL\Platforms\Exception\NotSupported $e) { } From 1894de466dbc7a61a32eb84514d44a6dab339e9c Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Mon, 11 Mar 2024 19:45:49 +0100 Subject: [PATCH 3/3] chore: remove getPlatformName() --- .../DatabaseTools/AbstractDatabaseTool.php | 2 - .../AbstractDbalDatabaseTool.php | 47 ------------------- .../DatabaseTools/ORMDatabaseTool.php | 11 ++++- 3 files changed, 10 insertions(+), 50 deletions(-) delete mode 100755 src/Services/DatabaseTools/AbstractDbalDatabaseTool.php diff --git a/src/Services/DatabaseTools/AbstractDatabaseTool.php b/src/Services/DatabaseTools/AbstractDatabaseTool.php index c929a1fb..bffaf7c3 100644 --- a/src/Services/DatabaseTools/AbstractDatabaseTool.php +++ b/src/Services/DatabaseTools/AbstractDatabaseTool.php @@ -219,6 +219,4 @@ 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 deleted file mode 100755 index 8abdba98..00000000 --- a/src/Services/DatabaseTools/AbstractDbalDatabaseTool.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * 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 00dea6bd..143115f8 100644 --- a/src/Services/DatabaseTools/ORMDatabaseTool.php +++ b/src/Services/DatabaseTools/ORMDatabaseTool.php @@ -17,6 +17,7 @@ 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; @@ -28,7 +29,7 @@ /** * @author Aleksey Tupichenkov */ -class ORMDatabaseTool extends AbstractDbalDatabaseTool +class ORMDatabaseTool extends AbstractDatabaseTool { /** * @var EntityManager @@ -37,6 +38,14 @@ class ORMDatabaseTool extends AbstractDbalDatabaseTool private bool $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';