mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR refactored setting/getting strict hierarchy setting. (from r98654) (from r99064)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102832 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
809072d1bf
commit
000d892256
@ -198,15 +198,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
*/
|
||||
private static $enforce_strict_hierarchy = true;
|
||||
|
||||
/**
|
||||
* Getter and setter for enforce_strict_hierarchy. With no
|
||||
* args it returns current value. Pass arg to set.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function enforce_strict_hierarchy() {
|
||||
$args = func_get_args();
|
||||
if (count($args)) self::$enforce_strict_hierarchy = (bool) $args[0];
|
||||
public static function set_enforce_strict_hierarchy($to) {
|
||||
self::$enforce_strict_hierarchy = $to;
|
||||
}
|
||||
|
||||
public static function get_enforce_strict_hierarchy() {
|
||||
return self::$enforce_strict_hierarchy;
|
||||
}
|
||||
|
||||
@ -1420,7 +1416,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
parent::onBeforeDelete();
|
||||
|
||||
// If deleting this page, delete all its children.
|
||||
if(SiteTree::enforce_strict_hierarchy() && $children = $this->Children()) {
|
||||
if(SiteTree::get_enforce_strict_hierarchy() && $children = $this->Children()) {
|
||||
foreach($children as $child) {
|
||||
$child->delete();
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testDeleteFromStageOperatesRecursively() {
|
||||
SiteTree::enforce_strict_hierarchy(false);
|
||||
SiteTree::set_enforce_strict_hierarchy(false);
|
||||
$pageAbout = $this->objFromFixture('Page', 'about');
|
||||
$pageStaff = $this->objFromFixture('Page', 'staff');
|
||||
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
||||
@ -317,7 +317,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);
|
||||
SiteTree::enforce_strict_hierarchy(true);
|
||||
SiteTree::set_enforce_strict_hierarchy(true);
|
||||
}
|
||||
|
||||
function testDeleteFromStageOperatesRecursivelyStrict() {
|
||||
@ -333,7 +333,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testDeleteFromLiveOperatesRecursively() {
|
||||
SiteTree::enforce_strict_hierarchy(false);
|
||||
SiteTree::set_enforce_strict_hierarchy(false);
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
$pageAbout = $this->objFromFixture('Page', 'about');
|
||||
@ -351,11 +351,11 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);
|
||||
Versioned::reading_stage('Stage');
|
||||
SiteTree::enforce_strict_hierarchy(true);
|
||||
SiteTree::set_enforce_strict_hierarchy(true);
|
||||
}
|
||||
|
||||
function testUnpublishDoesNotDeleteChildrenWithLooseHierachyOn() {
|
||||
SiteTree::enforce_strict_hierarchy(false);
|
||||
SiteTree::set_enforce_strict_hierarchy(false);
|
||||
$this->logInWithPermssion('ADMIN');
|
||||
|
||||
$pageAbout = $this->objFromFixture('Page', 'about');
|
||||
@ -373,7 +373,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page);
|
||||
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page);
|
||||
Versioned::reading_stage('Stage');
|
||||
SiteTree::enforce_strict_hierarchy(true);
|
||||
SiteTree::set_enforce_strict_hierarchy(true);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user