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();
|
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() {
|
function onAfterDelete() {
|
||||||
// Need to flush cache to avoid outdated versionnumber references
|
// Need to flush cache to avoid outdated versionnumber references
|
||||||
$this->flushCache();
|
$this->flushCache();
|
||||||
@ -1387,8 +1399,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->canEdit()) {
|
||||||
if($this->IsDeletedFromStage) {
|
if($this->IsDeletedFromStage) {
|
||||||
if($this->can('CMSEdit')) {
|
|
||||||
if($this->ExistsOnLive) {
|
if($this->ExistsOnLive) {
|
||||||
// "restore"
|
// "restore"
|
||||||
$actions->push(new FormAction('revert',_t('CMSMain.RESTORE','Restore')));
|
$actions->push(new FormAction('revert',_t('CMSMain.RESTORE','Restore')));
|
||||||
@ -1398,9 +1410,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
// "restore"
|
// "restore"
|
||||||
$actions->push(new FormAction('restore',_t('CMSMain.RESTORE','Restore')));
|
$actions->push(new FormAction('restore',_t('CMSMain.RESTORE','Restore')));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if($this->canEdit()) {
|
|
||||||
// "delete"
|
// "delete"
|
||||||
$actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete from the draft site')));
|
$actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete from the draft site')));
|
||||||
$deleteAction->addExtraClass('delete');
|
$deleteAction->addExtraClass('delete');
|
||||||
|
@ -80,6 +80,8 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
|
|
||||||
$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
|
$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
|
||||||
$this->assertEquals("V1", $checkSiteTree->Title);
|
$this->assertEquals("V1", $checkSiteTree->Title);
|
||||||
|
|
||||||
|
Versioned::reading_stage($oldStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testChidrenOfRootAreTopLevelPages() {
|
function testChidrenOfRootAreTopLevelPages() {
|
||||||
@ -188,7 +190,7 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
$this->assertEquals('Page', $requeriedPage->class);
|
$this->assertEquals('Page', $requeriedPage->class);
|
||||||
|
|
||||||
|
|
||||||
$page2 = $this->objFromFixture('Page', 'staff');
|
$page2 = $this->objFromFixture('Page', 'products');
|
||||||
$page2ID = $page2->ID;
|
$page2ID = $page2->ID;
|
||||||
$page2->doUnpublish();
|
$page2->doUnpublish();
|
||||||
$page2->delete();
|
$page2->delete();
|
||||||
@ -202,7 +204,7 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
|
|
||||||
Versioned::reading_stage('Stage');
|
Versioned::reading_stage('Stage');
|
||||||
$requeriedPage = DataObject::get_by_id("Page", $page2ID);
|
$requeriedPage = DataObject::get_by_id("Page", $page2ID);
|
||||||
$this->assertEquals('Staff', $requeriedPage->Title);
|
$this->assertEquals('Products', $requeriedPage->Title);
|
||||||
$this->assertEquals('Page', $requeriedPage->class);
|
$this->assertEquals('Page', $requeriedPage->class);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -219,6 +221,32 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
$this->assertFalse(SiteTree::get_by_url("home", "1 = 2"));
|
$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
|
// We make these extend page since that's what all page types are expected to do
|
||||||
|
Loading…
Reference in New Issue
Block a user