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
@ -83,9 +83,6 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
/**
|
/**
|
||||||
* Ensure that the database connection is able to use an existing database,
|
* Ensure that the database connection is able to use an existing database,
|
||||||
* or be able to create one if it doesn't exist.
|
* 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
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
||||||
* @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
|
* @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
|
||||||
@ -93,8 +90,6 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
||||||
$success = false;
|
$success = false;
|
||||||
$alreadyExists = false;
|
$alreadyExists = false;
|
||||||
$canCreate = false;
|
|
||||||
|
|
||||||
$check = $this->requireDatabaseConnection($databaseConfig);
|
$check = $this->requireDatabaseConnection($databaseConfig);
|
||||||
$conn = $check['connection'];
|
$conn = $check['connection'];
|
||||||
|
|
||||||
@ -102,13 +97,17 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
if(pg_fetch_array($result)) {
|
if(pg_fetch_array($result)) {
|
||||||
$success = true;
|
$success = true;
|
||||||
$alreadyExists = 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(
|
return array(
|
||||||
'success' => $success,
|
'success' => $success,
|
||||||
'alreadyExists' => $alreadyExists,
|
'alreadyExists' => $alreadyExists
|
||||||
'canCreate' => $canCreate
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user