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 (from r97827)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102538 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3000087ead
commit
68fb898c6d
@ -171,6 +171,9 @@ abstract class SS_Database {
|
||||
$this->schemaUpdateTransaction = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes a schema-updated transaction, executing all the schema chagnes.
|
||||
*/
|
||||
function endSchemaUpdate() {
|
||||
foreach($this->schemaUpdateTransaction as $tableName => $changes) {
|
||||
switch($changes['command']) {
|
||||
@ -186,6 +189,20 @@ abstract class SS_Database {
|
||||
}
|
||||
$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
|
||||
|
||||
|
@ -57,7 +57,22 @@ class DatabaseTest extends SapphireTest {
|
||||
"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