Skip to content

Commit

Permalink
Update DoctrineORMStorage.php
Browse files Browse the repository at this point in the history
  • Loading branch information
raziel057 authored Aug 22, 2023
1 parent 55f2058 commit e9a0cb6
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 e9a0cb6

Please sign in to comment.