BUGFIX: Don't let deleteFromStage() kill the ID of the original record. (from r106080)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112515 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 02:55:45 +00:00
parent 03c3d59ba0
commit c7b47d8a8b
2 changed files with 28 additions and 1 deletions

View File

@ -798,7 +798,8 @@ class Versioned extends DataObjectDecorator {
function deleteFromStage($stage) { function deleteFromStage($stage) {
$oldMode = Versioned::get_reading_mode(); $oldMode = Versioned::get_reading_mode();
Versioned::reading_stage($stage); Versioned::reading_stage($stage);
$result = $this->owner->delete(); $clone = clone $this->owner;
$result = $clone->delete();
Versioned::set_reading_mode($oldMode); Versioned::set_reading_mode($oldMode);
return $result; return $result;
} }

View File

@ -91,6 +91,32 @@ class VersionedTest extends SapphireTest {
$this->assertEquals('orig', $page1->Content, 'Copies the content from the old version'); $this->assertEquals('orig', $page1->Content, 'Copies the content from the old version');
} }
function testDeleteFromStage() {
$page1 = $this->objFromFixture('Page', 'page1');
$pageID = $page1->ID;
$page1->Content = 'orig';
$page1->write();
$page1->publish('Stage', 'Live');
$this->assertEquals(1, DB::query('SELECT COUNT(*) FROM "SiteTree" WHERE "ID" = '.$pageID)->value());
$this->assertEquals(1, DB::query('SELECT COUNT(*) FROM "SiteTree_Live" WHERE "ID" = '.$pageID)->value());
$page1->deleteFromStage('Live');
// Confirm that deleteFromStage() doesn't manipulate the original record
$this->assertEquals($pageID, $page1->ID);
$this->assertEquals(1, DB::query('SELECT COUNT(*) FROM "SiteTree" WHERE "ID" = '.$pageID)->value());
$this->assertEquals(0, DB::query('SELECT COUNT(*) FROM "SiteTree_Live" WHERE "ID" = '.$pageID)->value());
$page1->delete();
$this->assertEquals(0, $page1->ID);
$this->assertEquals(0, DB::query('SELECT COUNT(*) FROM "SiteTree" WHERE "ID" = '.$pageID)->value());
$this->assertEquals(0, DB::query('SELECT COUNT(*) FROM "SiteTree_Live" WHERE "ID" = '.$pageID)->value());
}
} }
class VersionedTest_DataObject extends DataObject implements TestOnly { class VersionedTest_DataObject extends DataObject implements TestOnly {