mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8470 from kinglozzer/suf-fixing-the-suffix
FIX: Re-instate missing SS_DATABASE_SUFFIX functionality (fixes #7966)
This commit is contained in:
commit
516267ed46
@ -223,7 +223,7 @@ class CoreKernel implements Kernel
|
|||||||
// Case 1: $databaseConfig global exists. Merge $database in as needed
|
// Case 1: $databaseConfig global exists. Merge $database in as needed
|
||||||
if (!empty($databaseConfig)) {
|
if (!empty($databaseConfig)) {
|
||||||
if (!empty($database)) {
|
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
|
// 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
|
// Case 2: $database merged into existing config
|
||||||
if (!empty($database)) {
|
if (!empty($database)) {
|
||||||
$existing = DB::getConfig();
|
$existing = DB::getConfig();
|
||||||
$existing['database'] = $this->getDatabasePrefix() . $database;
|
$existing['database'] = $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||||
|
|
||||||
DB::setConfig($existing);
|
DB::setConfig($existing);
|
||||||
}
|
}
|
||||||
@ -374,6 +374,14 @@ class CoreKernel implements Kernel
|
|||||||
return Environment::getEnv('SS_DATABASE_PREFIX') ?: '';
|
return Environment::getEnv('SS_DATABASE_PREFIX') ?: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getDatabaseSuffix()
|
||||||
|
{
|
||||||
|
return Environment::getEnv('SS_DATABASE_SUFFIX') ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name of database
|
* Get name of database
|
||||||
*
|
*
|
||||||
@ -385,7 +393,7 @@ class CoreKernel implements Kernel
|
|||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if (!empty($database)) {
|
if (!empty($database)) {
|
||||||
return $this->getDatabasePrefix() . $database;
|
return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
global $databaseConfig;
|
global $databaseConfig;
|
||||||
@ -398,7 +406,7 @@ class CoreKernel implements Kernel
|
|||||||
$database = Environment::getEnv('SS_DATABASE_NAME');
|
$database = Environment::getEnv('SS_DATABASE_NAME');
|
||||||
|
|
||||||
if ($database) {
|
if ($database) {
|
||||||
return $this->getDatabasePrefix() . $database;
|
return $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-detect name
|
// Auto-detect name
|
||||||
|
@ -11,6 +11,7 @@ use SilverStripe\Core\Injector\Injector;
|
|||||||
use SilverStripe\Core\Manifest\ClassLoader;
|
use SilverStripe\Core\Manifest\ClassLoader;
|
||||||
use SilverStripe\Dev\DevelopmentAdmin;
|
use SilverStripe\Dev\DevelopmentAdmin;
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\ORM\Connect\DatabaseException;
|
||||||
use SilverStripe\ORM\FieldType\DBClassName;
|
use SilverStripe\ORM\FieldType\DBClassName;
|
||||||
use SilverStripe\Security\Permission;
|
use SilverStripe\Security\Permission;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
@ -261,9 +262,25 @@ class DatabaseAdmin extends Controller
|
|||||||
}
|
}
|
||||||
$database = $parameters['database'];
|
$database = $parameters['database'];
|
||||||
|
|
||||||
// Establish connection and create database in two steps
|
// Establish connection
|
||||||
unset($parameters['database']);
|
unset($parameters['database']);
|
||||||
DB::connect($parameters);
|
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);
|
DB::create_database($database);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user