Skip to content

Commit

Permalink
further refactoring verifyDatabaseCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushwebkul committed Nov 1, 2019
1 parent 8a492e9 commit 99c88d0
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/Controller/ConfigureHelpdesk.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,29 @@ public function verifyDatabaseCredentials(Request $request)

if ($shouldCreateDatabase) {
$databaseConnection->getSchemaManager()->createDatabase($databaseConnection->getDatabasePlatform()->quoteSingleIdentifier($dbname));
}
// Closing the existing connection
$databaseConnection->close();

// Creating a new Connection (with database name)
$dbParams = array_merge($dbParams, ['dbname' => $dbname]);
$databaseConnection = DriverManager::getConnection($dbParams);

if (!$databaseConnection->isConnected()) {
// Try connecting with the database if the connection is not active.
$databaseConnection->connect();
}

if (in_array($dbname, $databaseConnection->getSchemaManager()->listDatabases())) {

// Storing database configuration to session.
$_SESSION['DB_CONFIG'] = [
'host' => $dbParams['host'] . (!empty($dbParams['port']) ? ":$dbParams[port]" : ""),
'username' => $dbParams['user'],
'password' => $dbParams['password'],
'database' => $dbParams['dbname'],
'database' => $dbname,
];


// Closing the existing connection
$databaseConnection->close();

return new Response(json_encode(['status' => true]), 200, self::DEFAULT_JSON_HEADERS);
}
} catch (\Exception $e) {
// Unable to create database
// Connection failed
// @TODO: Error reporting to user.
return new Response(json_encode(['status' => false]), 200, self::DEFAULT_JSON_HEADERS);
}

return new Response(json_encode(['status' => false]), 200, self::DEFAULT_JSON_HEADERS);
}

public function prepareSuperUserDetailsXHR(Request $request)
Expand Down

0 comments on commit 99c88d0

Please sign in to comment.