mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
parent
3906228fc1
commit
e810a9928c
@ -16,6 +16,15 @@ abstract class SS_Database {
|
|||||||
*/
|
*/
|
||||||
protected $connector = null;
|
protected $connector = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In cases where your environment does not have 'SHOW DATABASES' permission,
|
||||||
|
* you can set this to true. Then selectDatabase() will always connect without
|
||||||
|
* doing databaseExists() check.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private static $optimistic_connect = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current connector
|
* Get the current connector
|
||||||
*
|
*
|
||||||
@ -630,7 +639,13 @@ abstract class SS_Database {
|
|||||||
* @return boolean Flag indicating success
|
* @return boolean Flag indicating success
|
||||||
*/
|
*/
|
||||||
public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) {
|
public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) {
|
||||||
if (!$this->schemaManager->databaseExists($name)) {
|
// In case our live environment is locked down, we can bypass a SHOW DATABASE check
|
||||||
|
$canConnect = Config::inst()->get(get_class($this), 'optimistic_connect')
|
||||||
|
|| $this->schemaManager->databaseExists($name);
|
||||||
|
if($canConnect) {
|
||||||
|
return $this->connector->selectDatabase($name);
|
||||||
|
}
|
||||||
|
|
||||||
// Check DB creation permisson
|
// Check DB creation permisson
|
||||||
if (!$create) {
|
if (!$create) {
|
||||||
if ($errorLevel !== false) {
|
if ($errorLevel !== false) {
|
||||||
@ -641,7 +656,6 @@ abstract class SS_Database {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->schemaManager->createDatabase($name);
|
$this->schemaManager->createDatabase($name);
|
||||||
}
|
|
||||||
return $this->connector->selectDatabase($name);
|
return $this->connector->selectDatabase($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user