mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2604 from chillu/pulls/versioned-single-stage
Fixed support for single stage in Versioned
This commit is contained in:
commit
a0b7bfc7a5
@ -616,7 +616,11 @@ class Versioned extends DataExtension {
|
||||
}
|
||||
|
||||
// If we're editing Live, then use (table)_Live instead of (table)
|
||||
if(Versioned::current_stage() && Versioned::current_stage() != $this->defaultStage) {
|
||||
if(
|
||||
Versioned::current_stage()
|
||||
&& Versioned::current_stage() != $this->defaultStage
|
||||
&& in_array(Versioned::current_stage(), $this->stages)
|
||||
) {
|
||||
// If the record has already been inserted in the (table), get rid of it.
|
||||
if($manipulation[$table]['command']=='insert') {
|
||||
DB::query("DELETE FROM \"{$table}\" WHERE \"ID\"='$id'");
|
||||
|
@ -11,7 +11,8 @@ class VersionedTest extends SapphireTest {
|
||||
protected $extraDataObjects = array(
|
||||
'VersionedTest_DataObject',
|
||||
'VersionedTest_Subclass',
|
||||
'VersionedTest_RelatedWithoutVersion'
|
||||
'VersionedTest_RelatedWithoutVersion',
|
||||
'VersionedTest_SingleStage'
|
||||
);
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
@ -452,6 +453,46 @@ class VersionedTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testVersionedWithSingleStage() {
|
||||
$tables = DB::tableList();
|
||||
$this->assertContains(
|
||||
'VersionedTest_SingleStage',
|
||||
array_values($tables),
|
||||
'Contains base table'
|
||||
);
|
||||
$this->assertContains(
|
||||
'VersionedTest_SingleStage_versions',
|
||||
array_values($tables),
|
||||
'Contains versions table'
|
||||
);
|
||||
$this->assertNotContains(
|
||||
'VersionedTest_SingleStage_Live',
|
||||
array_values($tables),
|
||||
'Does not contain separate table with _Live suffix'
|
||||
);
|
||||
$this->assertNotContains(
|
||||
'VersionedTest_SingleStage_Stage',
|
||||
array_values($tables),
|
||||
'Does not contain separate table with _Stage suffix'
|
||||
);
|
||||
|
||||
Versioned::reading_stage("Stage");
|
||||
$obj = new VersionedTest_SingleStage(array('Name' => 'MyObj'));
|
||||
$obj->write();
|
||||
$this->assertNotNull(
|
||||
VersionedTest_SingleStage::get()->byID($obj->ID),
|
||||
'Writes to and reads from default stage if its set explicitly'
|
||||
);
|
||||
|
||||
Versioned::reading_stage("Live");
|
||||
$obj = new VersionedTest_SingleStage(array('Name' => 'MyObj'));
|
||||
$obj->write();
|
||||
$this->assertNotNull(
|
||||
VersionedTest_SingleStage::get()->byID($obj->ID),
|
||||
'Writes to and reads from default stage even if a non-matching stage is set'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -517,3 +558,13 @@ class VersionedTest_Subclass extends VersionedTest_DataObject implements TestOnl
|
||||
class VersionedTest_UnversionedWithField extends DataObject implements TestOnly {
|
||||
private static $db = array('Version' => 'Varchar(255)');
|
||||
}
|
||||
|
||||
class VersionedTest_SingleStage extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar'
|
||||
);
|
||||
|
||||
private static $extensions = array(
|
||||
'Versioned("Stage")'
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user