mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Fixed support for single stage in Versioned
This used to work in 2.4, so is considered a regression. To test, simply add a Versioned("Stage") extension to some record in 2.4 vs. 3.1.
This commit is contained in:
parent
2266d77237
commit
dfabd54bdb
@ -616,7 +616,11 @@ class Versioned extends DataExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're editing Live, then use (table)_Live instead of (table)
|
// 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 the record has already been inserted in the (table), get rid of it.
|
||||||
if($manipulation[$table]['command']=='insert') {
|
if($manipulation[$table]['command']=='insert') {
|
||||||
DB::query("DELETE FROM \"{$table}\" WHERE \"ID\"='$id'");
|
DB::query("DELETE FROM \"{$table}\" WHERE \"ID\"='$id'");
|
||||||
|
@ -11,7 +11,8 @@ class VersionedTest extends SapphireTest {
|
|||||||
protected $extraDataObjects = array(
|
protected $extraDataObjects = array(
|
||||||
'VersionedTest_DataObject',
|
'VersionedTest_DataObject',
|
||||||
'VersionedTest_Subclass',
|
'VersionedTest_Subclass',
|
||||||
'VersionedTest_RelatedWithoutVersion'
|
'VersionedTest_RelatedWithoutVersion',
|
||||||
|
'VersionedTest_SingleStage'
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $requiredExtensions = array(
|
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 {
|
class VersionedTest_UnversionedWithField extends DataObject implements TestOnly {
|
||||||
private static $db = array('Version' => 'Varchar(255)');
|
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…
x
Reference in New Issue
Block a user