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) (from r99063)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102831 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a5c2a3e564
commit
809072d1bf
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user