mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1993 from open-sausages/pulls/4/hierarchy-cascading-deletes
Force SiteTree to check in DB before deleting children
This commit is contained in:
commit
c2d9a0dc3b
@ -1486,7 +1486,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
parent::onBeforeDelete();
|
||||
|
||||
// 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) {
|
||||
/** @var SiteTree $child */
|
||||
$child->delete();
|
||||
|
@ -26,6 +26,7 @@ use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\Parsers\Diff;
|
||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||
use LogicException;
|
||||
|
||||
class SiteTreeTest extends SapphireTest
|
||||
{
|
||||
@ -332,6 +333,25 @@ class SiteTreeTest extends SapphireTest
|
||||
$this->assertInstanceOf('Page', $requeriedPage);
|
||||
}
|
||||
|
||||
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');
|
||||
|
Loading…
Reference in New Issue
Block a user