From da2a530274adde841c8ca3992913408058d4b469 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 14 Apr 2010 04:11:18 +0000 Subject: [PATCH] BUGFIX: SiteTree::batch_permission_check() doesn't recurse with ID=0 calls ENHANCEMENT: SiteTree::batch_permission_check() populates its own cache (from r97900) (from r99302) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102853 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SiteTree.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index a64d59761..18bac0028 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1084,18 +1084,24 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // Group $potentiallyInherited by ParentID; we'll look at the permission of all those // parents and then see which ones the user has permission on $siteConfigPermission = SiteConfig::current_site_config()->{$siteConfigMethod}($memberID); + $groupedByParent = array(); foreach($potentiallyInherited as $item) { - if (!isset($groupedByParent[$item->ParentID])) $groupedByParent[$item->ParentID] = array(); - if ($item->ParentID) $groupedByParent[$item->ParentID][] = $item->ID; - else $result[$item->ID] = $siteConfigPermission; + if($item->ParentID) { + if(!isset($groupedByParent[$item->ParentID])) $groupedByParent[$item->ParentID] = array(); + $groupedByParent[$item->ParentID][] = $item->ID; + } else { + $result[$item->ID] = $siteConfigPermission; + } } - $actuallyInherited = self::batch_permission_check(array_keys($groupedByParent), $memberID, $typeField, $groupJoinTable, $siteConfigMethod); - if($actuallyInherited) { - $parentIDs = array_keys(array_filter($actuallyInherited)); - foreach($parentIDs as $parentID) { - // Set all the relevant items in $result to true - $result = array_fill_keys($groupedByParent[$parentID], true) + $result; + if($groupedByParent) { + $actuallyInherited = self::batch_permission_check(array_keys($groupedByParent), $memberID, $typeField, $groupJoinTable, $siteConfigMethod); + if($actuallyInherited) { + $parentIDs = array_keys(array_filter($actuallyInherited)); + foreach($parentIDs as $parentID) { + // Set all the relevant items in $result to true + $result = array_fill_keys($groupedByParent[$parentID], true) + $result; + } } } } @@ -1104,8 +1110,16 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } } - - return isset($combinedStageResult) ? $combinedStageResult : array(); + + if(isset($combinedStageResult)) { + // Cache results + foreach($combinedStageResult as $id => $val) { + self::$cache_permissions[$typeField][$id] = $val; + } + return $combinedStageResult; + } else { + array(); + } } /**