BUGFIX: SiteTree::batch_permission_check() doesn't recurse with ID=0 calls

ENHANCEMENT: SiteTree::batch_permission_check() populates its own cache (from r97900)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99302 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-02-16 22:19:53 +00:00 committed by Sam Minnee
parent d616f9b8bb
commit 833db1b5a6

View File

@ -1064,18 +1064,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;
}
}
}
}
@ -1084,8 +1090,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();
}
}
/**