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()
{
$connection = $this->entityManager->getConnection();
$databaseName = $connection->getDatabase();
try {
$schemaManager = $connection->getSchemaManager();
$databaseName = $connection->getDatabase();
} catch (\Exception $exception) {
// mysql & sqlite
if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) {
if (false !== strpos($exception->getMessage(), 'Unknown database')) {
return false;
}
// pgsql
if (false !== strpos($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) {
if (false !== strpos($exception->getMessage(), 'does not exist')) {
return false;
}
throw $exception;
}
$schemaManager = $connection->getSchemaManager();
// custom verification for sqlite, since `getListDatabasesSQL` doesn't work for sqlite
if ('sqlite' === $schemaManager->getDatabasePlatform()->getName()) {
$params = $connection->getParams();