BUGFIX: Ensure that when a page is deleted from stage or live, its descendants are also deleted.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@77461 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-21 00:34:58 +00:00
parent 5a277c7a2c
commit 1eee3cc54b
2 changed files with 47 additions and 9 deletions

View File

@ -1042,6 +1042,18 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
parent::onAfterWrite();
}
function onBeforeDelete() {
parent::onBeforeDelete();
// If deleting this page, delete all its children.
if($children = $this->Children()) {
foreach($children as $child) {
$child->delete();
}
}
}
function onAfterDelete() {
// Need to flush cache to avoid outdated versionnumber references
$this->flushCache();
@ -1387,8 +1399,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
}
}
if($this->canEdit()) {
if($this->IsDeletedFromStage) {
if($this->can('CMSEdit')) {
if($this->ExistsOnLive) {
// "restore"
$actions->push(new FormAction('revert',_t('CMSMain.RESTORE','Restore')));
@ -1398,9 +1410,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
// "restore"
$actions->push(new FormAction('restore',_t('CMSMain.RESTORE','Restore')));
}
}
} else {
if($this->canEdit()) {
// "delete"
$actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete from the draft site')));
$deleteAction->addExtraClass('delete');

View File

@ -80,6 +80,8 @@ class SiteTreeTest extends SapphireTest {
$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
$this->assertEquals("V1", $checkSiteTree->Title);
Versioned::reading_stage($oldStage);
}
function testChidrenOfRootAreTopLevelPages() {
@ -188,7 +190,7 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals('Page', $requeriedPage->class);
$page2 = $this->objFromFixture('Page', 'staff');
$page2 = $this->objFromFixture('Page', 'products');
$page2ID = $page2->ID;
$page2->doUnpublish();
$page2->delete();
@ -202,7 +204,7 @@ class SiteTreeTest extends SapphireTest {
Versioned::reading_stage('Stage');
$requeriedPage = DataObject::get_by_id("Page", $page2ID);
$this->assertEquals('Staff', $requeriedPage->Title);
$this->assertEquals('Products', $requeriedPage->Title);
$this->assertEquals('Page', $requeriedPage->class);
}
@ -219,6 +221,32 @@ class SiteTreeTest extends SapphireTest {
$this->assertFalse(SiteTree::get_by_url("home", "1 = 2"));
}
function testDeleteFromStageOperatesRecursively() {
$parentPage = $this->objFromFixture('Page', 'about');
$parentPage->delete();
$this->assertFalse($this->objFromFixture('Page', 'about'));
$this->assertFalse($this->objFromFixture('Page', 'staff'));
$this->assertFalse($this->objFromFixture('Page', 'staffduplicate'));
}
function testDeleteFromLiveOperatesRecursively() {
$this->objFromFixture('Page', 'about')->doPublish();
$this->objFromFixture('Page', 'staff')->doPublish();
$this->objFromFixture('Page', 'staffduplicate')->doPublish();
$parentPage = $this->objFromFixture('Page', 'about');
$parentPage->doDeleteFromLive();
Versioned::reading_stage('Live');
$this->assertFalse($this->objFromFixture('Page', 'about'));
$this->assertFalse($this->objFromFixture('Page', 'staff'));
$this->assertFalse($this->objFromFixture('Page', 'staffduplicate'));
Versioned::reading_stage('Stage');
}
}
// We make these extend page since that's what all page types are expected to do