mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
MINOR Renamed variables and keys to conincide with r98795
This commit is contained in:
parent
48635c5167
commit
10a59a9a8d
@ -24,10 +24,10 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
/**
|
/**
|
||||||
* Ensure that the database server exists.
|
* Ensure that the database server 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('okay' => true, 'error' => 'details of error')
|
* @return array Result - e.g. array('success' => true, 'error' => 'details of error')
|
||||||
*/
|
*/
|
||||||
public function requireDatabaseServer($databaseConfig) {
|
public function requireDatabaseServer($databaseConfig) {
|
||||||
$okay = false;
|
$success = false;
|
||||||
$error = '';
|
$error = '';
|
||||||
$username = $databaseConfig['username'] ? $databaseConfig['username'] : '';
|
$username = $databaseConfig['username'] ? $databaseConfig['username'] : '';
|
||||||
$password = $databaseConfig['password'] ? $databaseConfig['password'] : '';
|
$password = $databaseConfig['password'] ? $databaseConfig['password'] : '';
|
||||||
@ -38,14 +38,14 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
|
|
||||||
$conn = @pg_connect($connstring);
|
$conn = @pg_connect($connstring);
|
||||||
if($conn) {
|
if($conn) {
|
||||||
$okay = true;
|
$success = true;
|
||||||
} else {
|
} else {
|
||||||
$okay = false;
|
$success = false;
|
||||||
$error = 'PostgreSQL requires a valid username and password to determine if the server exists.';
|
$error = 'PostgreSQL requires a valid username and password to determine if the server exists.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'okay' => $okay,
|
'success' => $success,
|
||||||
'error' => $error
|
'error' => $error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -55,10 +55,10 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
* The established connection resource is returned with the results as well.
|
* The established connection resource is returned with the results as well.
|
||||||
*
|
*
|
||||||
* @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('okay' => true, 'connection' => mysql link, 'error' => 'details of error')
|
* @return array Result - e.g. array('success' => true, 'connection' => mysql link, 'error' => 'details of error')
|
||||||
*/
|
*/
|
||||||
public function requireDatabaseConnection($databaseConfig) {
|
public function requireDatabaseConnection($databaseConfig) {
|
||||||
$okay = false;
|
$success = false;
|
||||||
$error = '';
|
$error = '';
|
||||||
$username = $databaseConfig['username'] ? $databaseConfig['username'] : '';
|
$username = $databaseConfig['username'] ? $databaseConfig['username'] : '';
|
||||||
$password = $databaseConfig['password'] ? $databaseConfig['password'] : '';
|
$password = $databaseConfig['password'] ? $databaseConfig['password'] : '';
|
||||||
@ -69,14 +69,14 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
|
|
||||||
$conn = @pg_connect($connstring);
|
$conn = @pg_connect($connstring);
|
||||||
if($conn) {
|
if($conn) {
|
||||||
$okay = true;
|
$success = true;
|
||||||
} else {
|
} else {
|
||||||
$okay = false;
|
$success = false;
|
||||||
$error = '';
|
$error = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'okay' => $okay,
|
'success' => $success,
|
||||||
'connection' => $conn,
|
'connection' => $conn,
|
||||||
'error' => $error
|
'error' => $error
|
||||||
);
|
);
|
||||||
@ -87,31 +87,31 @@ class PostgreSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelp
|
|||||||
* or be able to create one if it doesn't exist.
|
* or be able to create one if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @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('okay' => true, 'existsAlready' => 'true')
|
* @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
|
||||||
*/
|
*/
|
||||||
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
||||||
$okay = false;
|
$success = false;
|
||||||
$existsAlready = false;
|
$alreadyExists = false;
|
||||||
|
|
||||||
$check = $this->requireDatabaseConnection($databaseConfig);
|
$check = $this->requireDatabaseConnection($databaseConfig);
|
||||||
$conn = $check['connection'];
|
$conn = $check['connection'];
|
||||||
|
|
||||||
$result = pg_query($conn, "SELECT datname FROM pg_database WHERE datname = '$databaseConfig[database]'");
|
$result = pg_query($conn, "SELECT datname FROM pg_database WHERE datname = '$databaseConfig[database]'");
|
||||||
if(pg_fetch_array($result)) {
|
if(pg_fetch_array($result)) {
|
||||||
$okay = true;
|
$success = true;
|
||||||
$existsAlready = true;
|
$alreadyExists = true;
|
||||||
} else {
|
} else {
|
||||||
if(@pg_query($conn, "CREATE DATABASE testing123")) {
|
if(@pg_query($conn, "CREATE DATABASE testing123")) {
|
||||||
pg_query($conn, "DROP DATABASE testing123");
|
pg_query($conn, "DROP DATABASE testing123");
|
||||||
$okay = true;
|
$success = true;
|
||||||
$existsAlready = false;
|
$alreadyExists = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'okay' => $okay,
|
'success' => $success,
|
||||||
'existsAlready' => $existsAlready
|
'alreadyExists' => $alreadyExists
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user