Skip to content

Commit 164f1fa

Browse files
Merge pull request #291 from mbabker/2.x-min-deps
[2.x] Update minimum versions for optional dependencies and fix DBAL 2.x compat
2 parents f5e8237 + 1fb2ccb commit 164f1fa

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

composer.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
2626
},
2727
"require-dev": {
28-
"doctrine/annotations": "^1.8.0 || ^2.0",
29-
"doctrine/data-fixtures": "^1.7",
30-
"doctrine/doctrine-bundle": "^2.11",
31-
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
32-
"doctrine/mongodb-odm-bundle": "^4.2 || ^5.0",
33-
"doctrine/orm": "^2.7",
28+
"doctrine/annotations": "^1.13.1 || ^2.0",
29+
"doctrine/data-fixtures": "^1.4.4",
30+
"doctrine/dbal": "^2.13.1 || ^3.1",
31+
"doctrine/doctrine-bundle": "^2.2",
32+
"doctrine/doctrine-fixtures-bundle": "^3.4.4 || ^4.0",
33+
"doctrine/mongodb-odm": "^2.2",
34+
"doctrine/mongodb-odm-bundle": "^4.2.1 || ^5.0",
35+
"doctrine/orm": "^2.14",
3436
"doctrine/phpcr-bundle": "^2.4.3 || ^3.0",
3537
"doctrine/phpcr-odm": "^1.7.2 || ^2.0",
3638
"jackalope/jackalope-doctrine-dbal": "^1.10.1 || ^2.0",
@@ -43,8 +45,10 @@
4345
"theofidry/alice-data-fixtures": "^1.5.2"
4446
},
4547
"conflict": {
46-
"doctrine/annotations": "<1.2.7 || >=3.0",
47-
"doctrine/dbal": "<2.11"
48+
"doctrine/annotations": "<1.13.1 || >=3.0",
49+
"doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0",
50+
"doctrine/mongodb-odm": "<2.2 || >=3.0",
51+
"doctrine/orm": "<2.14 || >=3.0"
4852
},
4953
"suggest": {
5054
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",

src/Services/DatabaseTools/AbstractDbalDatabaseTool.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Doctrine\DBAL\Connection;
1717
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
18+
use Doctrine\DBAL\Platforms\MySqlPlatform;
1819
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1920
use Doctrine\DBAL\Platforms\SqlitePlatform;
2021

@@ -32,14 +33,15 @@ protected function getPlatformName(): string
3233
{
3334
$platform = $this->connection->getDatabasePlatform();
3435

35-
if ($platform instanceof AbstractMySQLPlatform) {
36+
// AbstractMySQLPlatform was introduced in DBAL 3.3, keep the MySQLPlatform checks for compatibility with older versions
37+
if ($platform instanceof AbstractMySQLPlatform || $platform instanceof MySqlPlatform) {
3638
return 'mysql';
3739
} elseif ($platform instanceof SqlitePlatform) {
3840
return 'sqlite';
3941
} elseif ($platform instanceof PostgreSQLPlatform) {
4042
return 'pgsql';
4143
}
4244

43-
return parent::getPlatformName();
45+
return (new \ReflectionClass($platform))->getShortName();
4446
}
4547
}

src/Services/DatabaseTools/ORMDatabaseTool.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,16 @@ protected function createDatabaseIfNotExists(): void
178178

179179
$tmpConnection = DriverManager::getConnection($params);
180180

181+
if (method_exists($tmpConnection, 'createSchemaManager')) {
182+
$schemaManager = $tmpConnection->createSchemaManager();
183+
} else {
184+
$schemaManager = $tmpConnection->getSchemaManager();
185+
}
186+
187+
// DBAL 4.x does not support creating databases for SQLite anymore; for now we silently ignore this error
181188
try {
182-
if (!\in_array($dbName, $tmpConnection->createSchemaManager()->listDatabases(), true)) {
183-
$tmpConnection->createSchemaManager()->createDatabase($dbName);
189+
if (!\in_array($dbName, $schemaManager->listDatabases(), true)) {
190+
$schemaManager->createDatabase($dbName);
184191
}
185192
} catch (\Doctrine\DBAL\Platforms\Exception\NotSupported $e) {
186193
}

0 commit comments

Comments
 (0)