mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: Added cancelSchemaUpdate() and doesSchemaNeedUpdating() to the Database class
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97827 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3740874e99
commit
17a5887a80
@ -171,6 +171,9 @@ abstract class SS_Database {
|
|||||||
$this->schemaUpdateTransaction = array();
|
$this->schemaUpdateTransaction = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completes a schema-updated transaction, executing all the schema chagnes.
|
||||||
|
*/
|
||||||
function endSchemaUpdate() {
|
function endSchemaUpdate() {
|
||||||
foreach($this->schemaUpdateTransaction as $tableName => $changes) {
|
foreach($this->schemaUpdateTransaction as $tableName => $changes) {
|
||||||
switch($changes['command']) {
|
switch($changes['command']) {
|
||||||
@ -186,6 +189,20 @@ abstract class SS_Database {
|
|||||||
}
|
}
|
||||||
$this->schemaUpdateTransaction = null;
|
$this->schemaUpdateTransaction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the schema updates requested after a beginSchemaUpdate() call.
|
||||||
|
*/
|
||||||
|
function cancelSchemaUpdate() {
|
||||||
|
$this->schemaUpdateTransaction = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if schema modifications were requested after a beginSchemaUpdate() call.
|
||||||
|
*/
|
||||||
|
function doesSchemaNeedUpdating() {
|
||||||
|
return (bool)$this->schemaUpdateTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
// Transactional schema altering functions - they don't do anyhting except for update schemaUpdateTransaction
|
// Transactional schema altering functions - they don't do anyhting except for update schemaUpdateTransaction
|
||||||
|
|
||||||
|
@ -55,7 +55,22 @@ class DatabaseTest extends SapphireTest {
|
|||||||
"MySQLDatabase tables can be changed to InnoDB through DataObject::\$create_table_options"
|
"MySQLDatabase tables can be changed to InnoDB through DataObject::\$create_table_options"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSchemaUpdateChecking() {
|
||||||
|
$db = DB::getConn();
|
||||||
|
|
||||||
|
// Initially, no schema changes necessary
|
||||||
|
$db->beginSchemaUpdate();
|
||||||
|
$this->assertFalse($db->doesSchemaNeedUpdating());
|
||||||
|
|
||||||
|
// If we make a change, then the schema will need updating
|
||||||
|
$db->transCreateTable("TestTable");
|
||||||
|
$this->assertTrue($db->doesSchemaNeedUpdating());
|
||||||
|
|
||||||
|
// If we make cancel the change, then schema updates are no longer necessary
|
||||||
|
$db->cancelSchemaUpdate();
|
||||||
|
$this->assertFalse($db->doesSchemaNeedUpdating());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user