Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Update minimum versions for optional dependencies and fix DBAL 2.x compat #291

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
"symfony/yaml": "^5.4 || ^6.3 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^1.8.0 || ^2.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
"doctrine/mongodb-odm-bundle": "^4.2 || ^5.0",
"doctrine/orm": "^2.7",
"doctrine/annotations": "^1.13.1 || ^2.0",
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
"doctrine/data-fixtures": "^1.4.4",
"doctrine/dbal": "^2.13.1 || ^3.1",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-fixtures-bundle": "^3.4.4 || ^4.0",
"doctrine/mongodb-odm": "^2.2",
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
"doctrine/mongodb-odm-bundle": "^4.2.1 || ^5.0",
"doctrine/orm": "^2.14",
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
"doctrine/phpcr-bundle": "^2.4.3 || ^3.0",
"doctrine/phpcr-odm": "^1.7.2 || ^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.10.1 || ^2.0",
Expand All @@ -43,8 +45,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",
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
"doctrine/mongodb-odm": "<2.2 || >=3.0",
"doctrine/orm": "<2.14 || >=3.0"
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
},
"suggest": {
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
Expand Down
6 changes: 4 additions & 2 deletions src/Services/DatabaseTools/AbstractDbalDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,14 +33,15 @@ 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';
} elseif ($platform instanceof PostgreSQLPlatform) {
return 'pgsql';
}

return parent::getPlatformName();
return (new \ReflectionClass($platform))->getShortName();
}
}
11 changes: 9 additions & 2 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,16 @@ protected function createDatabaseIfNotExists(): void

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

if (method_exists($tmpConnection, 'createSchemaManager')) {
$schemaManager = $tmpConnection->createSchemaManager();
} else {
$schemaManager = $tmpConnection->getSchemaManager();
}

// 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) {
}
Expand Down
Loading