From 809072d1bf6e1ee956b5bd8764bdfdc1d165a6bd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 14 Apr 2010 03:57:21 +0000 Subject: [PATCH] API CHANGE: Let sitetree extensions prepopulate permisson cache for their own permissions. (from r98650) (from r99063) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102831 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 f71d38dce..f1523cdd8 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -992,11 +992,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])) { @@ -1007,8 +1013,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); } }