Skip to content

Commit

Permalink
Merge pull request #291 from mbabker/2.x-min-deps
Browse files Browse the repository at this point in the history
[2.x] Update minimum versions for optional dependencies and fix DBAL 2.x compat
  • Loading branch information
alexislefebvre authored Mar 11, 2024
2 parents f5e8237 + 1fb2ccb commit 164f1fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
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",
"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",
"doctrine/mongodb-odm-bundle": "^4.2.1 || ^5.0",
"doctrine/orm": "^2.14",
"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",
"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",
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

0 comments on commit 164f1fa

Please sign in to comment.