Fix installer when database not exists

This commit is contained in:
Nicolas Lœuillet 2023-07-19 15:33:56 +02:00
parent 911e0238b7
commit 2c688daf2a

View file

@ -372,24 +372,25 @@ class InstallCommand extends Command
private function isDatabasePresent() private function isDatabasePresent()
{ {
$connection = $this->entityManager->getConnection(); $connection = $this->entityManager->getConnection();
$databaseName = $connection->getDatabase();
try { try {
$schemaManager = $connection->getSchemaManager(); $databaseName = $connection->getDatabase();
} catch (\Exception $exception) { } catch (\Exception $exception) {
// mysql & sqlite // mysql & sqlite
if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { if (false !== strpos($exception->getMessage(), 'Unknown database')) {
return false; return false;
} }
// pgsql // pgsql
if (false !== strpos($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) { if (false !== strpos($exception->getMessage(), 'does not exist')) {
return false; return false;
} }
throw $exception; throw $exception;
} }
$schemaManager = $connection->getSchemaManager();
// custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite // custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite
if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) { if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) {
$params = $connection->getParams(); $params = $connection->getParams();