From f7e872a1c26728f620118f43a9eb313b138536a7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 16 Feb 2010 01:17:41 +0000 Subject: [PATCH] API CHANGE: Let sitetree extensions prepopulate permisson cache for their own permissions. (from r98650) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99063 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SiteTree.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 883442f53..e37945056 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -972,11 +972,17 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid /** * Pre-populate the cache of canEdit, canView, canDelete, canPublish permissions. * This method will use the static can_(perm)_multiple method for efficiency. + * + * @param $permission String The permission: edit, view, publish, approve, etc. + * @param $ids array An array of page IDs + * @param $batchCallBack The function/static method to call to calculate permissions. Defaults + * to 'SiteTree::can_(permission)_multiple' */ - static function prepopuplate_permission_cache($permission = 'edit', $ids) { - $methodName = "can_{$permission}_multiple"; - if(is_callable(array('SiteTree', $methodName))) { - $permissionValues = call_user_func(array('SiteTree', $methodName), $ids, + static function prepopuplate_permission_cache($permission = 'CanEditType', $ids, $batchCallback = null) { + if(!$batchCallback) $batchCallback = "SiteTree::can_{$permission}_multiple"; + + if(is_callable($batchCallback)) { + $permissionValues = call_user_func($batchCallback, $ids, Member::currentUserID(), false); if(!isset(self::$cache_permissions[$permission])) { @@ -987,8 +993,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid + self::$cache_permissions[$permission]; } else { - user_error("SiteTree::prepopuplate_permission_cache passed bad permission '$permission'" - , E_USER_WARNING); + user_error("SiteTree::prepopuplate_permission_cache can't calculate '$permission' " + . "with callback '$batchCallback'", E_USER_WARNING); } }