mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
SiteTree check if in DB before delete children
This commit is contained in:
parent
0f2ff54557
commit
9ae6fbffe1
@ -1574,7 +1574,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
parent::onBeforeDelete();
|
parent::onBeforeDelete();
|
||||||
|
|
||||||
// If deleting this page, delete all its children.
|
// If deleting this page, delete all its children.
|
||||||
if(SiteTree::config()->enforce_strict_hierarchy && $children = $this->AllChildren()) {
|
if($this->isInDB() && SiteTree::config()->enforce_strict_hierarchy && $children = $this->AllChildren()) {
|
||||||
foreach($children as $child) {
|
foreach($children as $child) {
|
||||||
$child->delete();
|
$child->delete();
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,25 @@ class SiteTreeTest extends SapphireTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetByLink() {
|
public function testNoCascadingDeleteWithoutID() {
|
||||||
|
Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true);
|
||||||
|
$count = SiteTree::get()->count();
|
||||||
|
$this->assertNotEmpty($count);
|
||||||
|
$obj = new SiteTree();
|
||||||
|
$this->assertFalse($obj->exists());
|
||||||
|
$fail = true;
|
||||||
|
try {
|
||||||
|
$obj->delete();
|
||||||
|
} catch (LogicException $e) {
|
||||||
|
$fail = false;
|
||||||
|
}
|
||||||
|
if ($fail) {
|
||||||
|
$this->fail('Failed to throw delete exception');
|
||||||
|
}
|
||||||
|
$this->assertCount($count, SiteTree::get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetByLink() {
|
||||||
$home = $this->objFromFixture('Page', 'home');
|
$home = $this->objFromFixture('Page', 'home');
|
||||||
$about = $this->objFromFixture('Page', 'about');
|
$about = $this->objFromFixture('Page', 'about');
|
||||||
$staff = $this->objFromFixture('Page', 'staff');
|
$staff = $this->objFromFixture('Page', 'staff');
|
||||||
|
Loading…
Reference in New Issue
Block a user