mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
5a277c7a2c
commit
1eee3cc54b
@ -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');
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user