mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
03c3d59ba0
commit
c7b47d8a8b
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user