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
This commit is contained in:
Ingo Schommer 2010-02-16 01:17:41 +00:00 committed by Sam Minnee
parent 59b7d14720
commit f7e872a1c2

View File

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