mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
MINOR Added ability to create databases through installer checks for PostgreSQL
This commit is contained in:
parent
11d16b3c7f
commit
e33bd117d4
@ -84,17 +84,12 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
||||
* Ensure that the database connection is able to use an existing database,
|
||||
* or be able to create one if it doesn't exist.
|
||||
*
|
||||
* Unfortunately, PostgreSQLDatabase doesn't support automatically creating databases
|
||||
* at the moment, so we can only check that the chosen database exists.
|
||||
*
|
||||
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
||||
* @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
|
||||
*/
|
||||
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
||||
$success = false;
|
||||
$alreadyExists = false;
|
||||
$canCreate = false;
|
||||
|
||||
$check = $this->requireDatabaseConnection($databaseConfig);
|
||||
$conn = $check['connection'];
|
||||
|
||||
@ -102,13 +97,17 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
||||
if(pg_fetch_array($result)) {
|
||||
$success = true;
|
||||
$alreadyExists = true;
|
||||
$canCreate = true;
|
||||
} else {
|
||||
if(@pg_query("CREATE DATABASE testing123", $conn)) {
|
||||
pg_query("DROP DATABASE testing123", $conn);
|
||||
$success = true;
|
||||
$alreadyExists = false;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => $success,
|
||||
'alreadyExists' => $alreadyExists,
|
||||
'canCreate' => $canCreate
|
||||
'alreadyExists' => $alreadyExists
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user