mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Remove dummy entry created by Versioned if record is first written to Live stage (fixes #5596, thanks muzdowski)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@107537 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7ac4a9ec4d
commit
b20f1fd59d
@ -396,6 +396,11 @@ class Versioned extends DataObjectDecorator {
|
||||
|
||||
// If we're editing Live, then use (table)_Live instead of (table)
|
||||
if(Versioned::current_stage() && Versioned::current_stage() != $this->defaultStage) {
|
||||
// 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'");
|
||||
}
|
||||
|
||||
$newTable = $table . '_' . Versioned::current_stage();
|
||||
$manipulation[$newTable] = $manipulation[$table];
|
||||
unset($manipulation[$table]);
|
||||
|
@ -117,6 +117,48 @@ class VersionedTest extends SapphireTest {
|
||||
$this->assertEquals(0, DB::query('SELECT COUNT(*) FROM "SiteTree_Live" WHERE "ID" = '.$pageID)->value());
|
||||
}
|
||||
|
||||
function testWritingNewToStage() {
|
||||
$origStage = Versioned::current_stage();
|
||||
|
||||
Versioned::reading_stage("Stage");
|
||||
$page = new Page();
|
||||
$page->Title = "testWritingNewToStage";
|
||||
$page->URLSegment = "testWritingNewToStage";
|
||||
$page->write();
|
||||
|
||||
$live = Versioned::get_by_stage('SiteTree', 'Live', "\"SiteTree_Live\".\"ID\"='$page->ID'");
|
||||
$this->assertNull($live);
|
||||
|
||||
$stage = Versioned::get_by_stage('SiteTree', 'Stage', "\"SiteTree\".\"ID\"='$page->ID'");
|
||||
$this->assertNotNull($stage);
|
||||
$this->assertEquals($stage->First()->Title, 'testWritingNewToStage');
|
||||
|
||||
Versioned::reading_stage($origStage);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests for the situation described in the ticket #5596.
|
||||
* Writing new Page to live first creates a row in SiteTree table (to get the new ID), then "changes
|
||||
* it's mind" in Versioned and writes SiteTree_Live. It does not remove the SiteTree record though.
|
||||
*/
|
||||
function testWritingNewToLive() {
|
||||
$origStage = Versioned::current_stage();
|
||||
|
||||
Versioned::reading_stage("Live");
|
||||
$page = new Page();
|
||||
$page->Title = "testWritingNewToLive";
|
||||
$page->URLSegment = "testWritingNewToLive";
|
||||
$page->write();
|
||||
|
||||
$live = Versioned::get_by_stage('SiteTree', 'Live', "\"SiteTree_Live\".\"ID\"='$page->ID'");
|
||||
$this->assertNotNull($live->First());
|
||||
$this->assertEquals($live->First()->Title, 'testWritingNewToLive');
|
||||
|
||||
$stage = Versioned::get_by_stage('SiteTree', 'Stage', "\"SiteTree\".\"ID\"='$page->ID'");
|
||||
$this->assertNull($stage);
|
||||
|
||||
Versioned::reading_stage($origStage);
|
||||
}
|
||||
}
|
||||
|
||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||
|
Loading…
x
Reference in New Issue
Block a user