mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
59b7d14720
commit
f7e872a1c2
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user