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
This commit is contained in:
Ingo Schommer 2010-04-14 04:11:18 +00:00
parent e99d56df3f
commit da2a530274

View File

@ -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();
}
}
/**