mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #883 from mateusz/schema-updating-flag
API Add the ability to query if the schema update is in progress.
This commit is contained in:
commit
713fe809bb
@ -181,6 +181,10 @@ abstract class SS_Database {
|
||||
*/
|
||||
protected $indexList;
|
||||
|
||||
/**
|
||||
* Keeps track whether we are currently updating the schema.
|
||||
*/
|
||||
protected $schemaIsUpdating = false;
|
||||
|
||||
/**
|
||||
* Large array structure that represents a schema update transaction
|
||||
@ -193,6 +197,7 @@ abstract class SS_Database {
|
||||
* Once
|
||||
*/
|
||||
public function beginSchemaUpdate() {
|
||||
$this->schemaIsUpdating = true;
|
||||
$this->tableList = array();
|
||||
$tables = $this->tableList();
|
||||
foreach($tables as $table) $this->tableList[strtolower($table)] = $table;
|
||||
@ -221,6 +226,7 @@ abstract class SS_Database {
|
||||
}
|
||||
}
|
||||
$this->schemaUpdateTransaction = null;
|
||||
$this->schemaIsUpdating = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,6 +234,14 @@ abstract class SS_Database {
|
||||
*/
|
||||
public function cancelSchemaUpdate() {
|
||||
$this->schemaUpdateTransaction = null;
|
||||
$this->schemaIsUpdating = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we are during a schema update.
|
||||
*/
|
||||
function isSchemaUpdating() {
|
||||
return $this->schemaIsUpdating;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,6 +62,22 @@ class DatabaseTest extends SapphireTest {
|
||||
}
|
||||
}
|
||||
|
||||
function testIsSchemaUpdating() {
|
||||
$db = DB::getConn();
|
||||
|
||||
$this->assertFalse($db->isSchemaUpdating(), 'Before the transaction the flag is false.');
|
||||
|
||||
$db->beginSchemaUpdate();
|
||||
$this->assertTrue($db->isSchemaUpdating(), 'During the transaction the flag is true.');
|
||||
|
||||
$db->endSchemaUpdate();
|
||||
$this->assertFalse($db->isSchemaUpdating(), 'After the transaction the flag is false.');
|
||||
|
||||
$db->beginSchemaUpdate();
|
||||
$db->cancelSchemaUpdate();
|
||||
$this->assertFalse($db->doesSchemaNeedUpdating(), 'After cancelling the transaction the flag is false');
|
||||
}
|
||||
|
||||
public function testSchemaUpdateChecking() {
|
||||
$db = DB::getConn();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user