diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index a180922c3..f71d38dce 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1415,7 +1415,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // If deleting this page, delete all its children. if(SiteTree::enforce_strict_hierarchy() && $children = $this->Children()) { - // if($children = $this->Children()) { foreach($children as $child) { $child->delete(); } diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index 50adb1cf3..4759d35b8 100755 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -354,6 +354,29 @@ class SiteTreeTest extends SapphireTest { SiteTree::enforce_strict_hierarchy(true); } + function testUnpublishDoesNotDeleteChildrenWithLooseHierachyOn() { + SiteTree::enforce_strict_hierarchy(false); + $this->logInWithPermssion('ADMIN'); + + $pageAbout = $this->objFromFixture('Page', 'about'); + $pageAbout->doPublish(); + $pageStaff = $this->objFromFixture('Page', 'staff'); + $pageStaff->doPublish(); + $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageStaffDuplicate->doPublish(); + + $parentPage = $this->objFromFixture('Page', 'about'); + $parentPage->doUnpublish(); + + Versioned::reading_stage('Live'); + $this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID)); + $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); + $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); + Versioned::reading_stage('Stage'); + SiteTree::enforce_strict_hierarchy(true); + } + + function testDeleteFromLiveOperatesRecursivelyStrict() { $this->logInWithPermssion('ADMIN');