From e9a0cb64775563dc1990216691e5c19d23aea705 Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 22 Aug 2023 14:18:26 +0200 Subject: [PATCH] Update DoctrineORMStorage.php --- Storage/DoctrineORMStorage.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Storage/DoctrineORMStorage.php b/Storage/DoctrineORMStorage.php index a71c5bec..8c020e7c 100644 --- a/Storage/DoctrineORMStorage.php +++ b/Storage/DoctrineORMStorage.php @@ -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; /** @@ -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; @@ -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); } /**