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:
Sam Minnee 2010-01-31 21:33:17 +00:00
parent 3740874e99
commit 17a5887a80
2 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -55,7 +55,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());
}
}