mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Re-instate missing SS_DATABASE_SUFFIX functionality (fixes #7966)
This commit is contained in:
parent
bd6c4fdda0
commit
ee21c42011
@ -223,7 +223,7 @@ class CoreKernel implements Kernel
|
||||
// Case 1: $databaseConfig global exists. Merge $database in as needed
|
||||
if (!empty($databaseConfig)) {
|
||||
if (!empty($database)) {
|
||||
$databaseConfig['database'] = $this->getDatabasePrefix() . $database;
|
||||
$databaseConfig['database'] = $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||
}
|
||||
|
||||
// Only set it if its valid, otherwise ignore $databaseConfig entirely
|
||||
@ -237,7 +237,7 @@ class CoreKernel implements Kernel
|
||||
// Case 2: $database merged into existing config
|
||||
if (!empty($database)) {
|
||||
$existing = DB::getConfig();
|
||||
$existing['database'] = $this->getDatabasePrefix() . $database;
|
||||
$existing['database'] = $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||
|
||||
DB::setConfig($existing);
|
||||
}
|
||||
@ -374,6 +374,14 @@ class CoreKernel implements Kernel
|
||||
return Environment::getEnv('SS_DATABASE_PREFIX') ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getDatabaseSuffix()
|
||||
{
|
||||
return Environment::getEnv('SS_DATABASE_SUFFIX') ?: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of database
|
||||
*
|
||||
@ -385,7 +393,7 @@ class CoreKernel implements Kernel
|
||||
global $database;
|
||||
|
||||
if (!empty($database)) {
|
||||
return $this->getDatabasePrefix() . $database;
|
||||
return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||
}
|
||||
|
||||
global $databaseConfig;
|
||||
@ -398,7 +406,7 @@ class CoreKernel implements Kernel
|
||||
$database = Environment::getEnv('SS_DATABASE_NAME');
|
||||
|
||||
if ($database) {
|
||||
return $this->getDatabasePrefix() . $database;
|
||||
return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||
}
|
||||
|
||||
// Auto-detect name
|
||||
|
@ -11,6 +11,7 @@ use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Manifest\ClassLoader;
|
||||
use SilverStripe\Dev\DevelopmentAdmin;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\Connect\DatabaseException;
|
||||
use SilverStripe\ORM\FieldType\DBClassName;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\Security;
|
||||
@ -261,9 +262,25 @@ class DatabaseAdmin extends Controller
|
||||
}
|
||||
$database = $parameters['database'];
|
||||
|
||||
// Establish connection and create database in two steps
|
||||
// Establish connection
|
||||
unset($parameters['database']);
|
||||
DB::connect($parameters);
|
||||
|
||||
// Check to ensure that the re-instated SS_DATABASE_SUFFIX functionality won't unexpectedly
|
||||
// rename the database. To be removed for SS5
|
||||
if ($suffix = Environment::getEnv('SS_DATABASE_SUFFIX')) {
|
||||
$previousName = preg_replace("/{$suffix}$/", '', $database);
|
||||
|
||||
if (!isset($_GET['force_suffix_rename']) && DB::get_conn()->databaseExists($previousName)) {
|
||||
throw new DatabaseException(
|
||||
"SS_DATABASE_SUFFIX was previously broken, but has now been fixed. This will result in your "
|
||||
. "database being named \"{$database}\" instead of \"{$previousName}\" from now on. If this "
|
||||
. "change is intentional, please visit dev/build?force_suffix_rename=1 to continue"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create database
|
||||
DB::create_database($database);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user