mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: The advancedOptions variable now passed to the database connection
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88293 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
dbc560d59b
commit
e31b4abb7b
@ -78,12 +78,12 @@ abstract class Database {
|
|||||||
* - 'temporary' - If true, then a temporary table will be created
|
* - 'temporary' - If true, then a temporary table will be created
|
||||||
* @return The table name generated. This may be different from the table name, for example with temporary tables.
|
* @return The table name generated. This may be different from the table name, for example with temporary tables.
|
||||||
*/
|
*/
|
||||||
abstract function createTable($table, $fields = null, $indexes = null, $options = null);
|
abstract function createTable($table, $fields = null, $indexes = null, $options = null, $advancedOptions = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alter a table's schema.
|
* Alter a table's schema.
|
||||||
*/
|
*/
|
||||||
abstract function alterTable($table, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null);
|
abstract function alterTable($table, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null, $alteredOptions=null, $advancedOptions=null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a table.
|
* Rename a table.
|
||||||
@ -182,12 +182,12 @@ abstract class Database {
|
|||||||
foreach($this->schemaUpdateTransaction as $tableName => $changes) {
|
foreach($this->schemaUpdateTransaction as $tableName => $changes) {
|
||||||
switch($changes['command']) {
|
switch($changes['command']) {
|
||||||
case 'create':
|
case 'create':
|
||||||
$this->createTable($tableName, $changes['newFields'], $changes['newIndexes'], $changes['options']);
|
$this->createTable($tableName, $changes['newFields'], $changes['newIndexes'], $changes['options'], @$changes['advancedOptions']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'alter':
|
case 'alter':
|
||||||
$this->alterTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
$this->alterTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
||||||
$changes['alteredFields'], $changes['alteredIndexes'], $changes['alteredOptions']);
|
$changes['alteredFields'], $changes['alteredIndexes'], $changes['alteredOptions'], @$changes['advancedOptions']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,17 +200,18 @@ abstract class Database {
|
|||||||
* @param string $table
|
* @param string $table
|
||||||
* @param string $options
|
* @param string $options
|
||||||
*/
|
*/
|
||||||
function transCreateTable($table, $options = null) {
|
function transCreateTable($table, $options = null, $advanced_options = null) {
|
||||||
$this->schemaUpdateTransaction[$table] = array('command' => 'create', 'newFields' => array(), 'newIndexes' => array(), 'options' => $options);
|
$this->schemaUpdateTransaction[$table] = array('command' => 'create', 'newFields' => array(), 'newIndexes' => array(), 'options' => $options, 'advancedOptions' => $advanced_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
function transAlterTable($table, $options) {
|
function transAlterTable($table, $options, $advanced_options) {
|
||||||
$this->transInitTable($table);
|
$this->transInitTable($table);
|
||||||
$this->schemaUpdateTransaction[$table]['alteredOptions'] = $options;
|
$this->schemaUpdateTransaction[$table]['alteredOptions'] = $options;
|
||||||
|
$this->schemaUpdateTransaction[$table]['advancedOptions'] = $advanced_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transCreateField($table, $field, $schema) {
|
function transCreateField($table, $field, $schema) {
|
||||||
@ -258,16 +259,18 @@ abstract class Database {
|
|||||||
* @param string $indexSchema A list of indexes to create. See {@link requireIndex()}
|
* @param string $indexSchema A list of indexes to create. See {@link requireIndex()}
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*/
|
*/
|
||||||
function requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK=true, $options = null) {
|
function requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK=true, $options = Array(), $extensions=false) {
|
||||||
|
|
||||||
if(!isset($this->tableList[strtolower($table)])) {
|
if(!isset($this->tableList[strtolower($table)])) {
|
||||||
$this->transCreateTable($table, $options);
|
$this->transCreateTable($table, $options, $extensions);
|
||||||
Database::alteration_message("Table $table: created","created");
|
Database::alteration_message("Table $table: created","created");
|
||||||
} else {
|
} else {
|
||||||
$this->checkAndRepairTable($table, $options);
|
$this->checkAndRepairTable($table, $options);
|
||||||
|
|
||||||
// Check if options changed
|
// Check if options changed
|
||||||
if($options && isset($options[get_class($this)])) {
|
|
||||||
$tableOptionsChanged = false;
|
$tableOptionsChanged = false;
|
||||||
|
if(isset($options[get_class($this)]) || true) {
|
||||||
|
if(isset($options[get_class($this)])) {
|
||||||
if(preg_match('/ENGINE=([^\s]*)/', $options[get_class($this)], $alteredEngineMatches)) {
|
if(preg_match('/ENGINE=([^\s]*)/', $options[get_class($this)], $alteredEngineMatches)) {
|
||||||
$alteredEngine = $alteredEngineMatches[1];
|
$alteredEngine = $alteredEngineMatches[1];
|
||||||
$tableStatus = DB::query(sprintf(
|
$tableStatus = DB::query(sprintf(
|
||||||
@ -276,11 +279,12 @@ abstract class Database {
|
|||||||
))->first();
|
))->first();
|
||||||
$tableOptionsChanged = ($tableStatus['Engine'] != $alteredEngine);
|
$tableOptionsChanged = ($tableStatus['Engine'] != $alteredEngine);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($tableOptionsChanged || ($extensions && DB::getConn()->supportsExtensions()))
|
||||||
|
$this->transAlterTable($table, $options, $extensions);
|
||||||
|
|
||||||
if($tableOptionsChanged) {
|
|
||||||
$this->transAlterTable($table, $options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//DB ABSTRACTION: we need to convert this to a db-specific version:
|
//DB ABSTRACTION: we need to convert this to a db-specific version:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user