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:
Ingo Schommer 2010-04-12 23:43:10 +00:00
parent 3000087ead
commit 68fb898c6d
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

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