Skip to content

Commit

Permalink
Merge pull request #442 from raziel057/fix-deprecation-dbal
Browse files Browse the repository at this point in the history
Fix deprecations raised for support of Doctrine DBAL 4
  • Loading branch information
bartmcleod authored Aug 28, 2023
2 parents 55f2058 + e9a0cb6 commit 58b77c4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Storage/DoctrineORMStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as SQLiteDriver;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;

/**
Expand Down Expand Up @@ -36,8 +38,17 @@ public function translationsTablesExist()
unset($params['dbname'], $params['path'], $params['url']);

try {
$tmpConnection = DriverManager::getConnection($params);
$dbExists = in_array($connection->getDatabase(), $tmpConnection->getSchemaManager()->listDatabases());
$configuration = new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$tmpConnection = DriverManager::getConnection($params, $configuration);
$schemaManager = method_exists($tmpConnection, 'createSchemaManager')
? $tmpConnection->createSchemaManager()
: $tmpConnection->getSchemaManager();

$dbExists = in_array($connection->getDatabase(), $schemaManager->listDatabases());
$tmpConnection->close();
} catch (ConnectionException|\Exception $e) {
$dbExists = false;
Expand All @@ -54,7 +65,11 @@ public function translationsTablesExist()
$em->getClassMetadata($this->getModelClass('translation'))->getTableName(),
];

return $connection->getSchemaManager()->tablesExist($tables);
$schemaManager = method_exists($connection, 'createSchemaManager')
? $connection->createSchemaManager()
: $connection->getSchemaManager();

return $schemaManager->tablesExist($tables);
}

/**
Expand Down

0 comments on commit 58b77c4

Please sign in to comment.