From df536ab17d98c1d7662fc0653bed375d2bd528ef Mon Sep 17 00:00:00 2001 From: cescobedo Date: Sun, 29 Jul 2018 22:43:06 +0200 Subject: [PATCH] MDL-62065 core_access: First deprecation of get roles on exact context --- .../dataprivacy/classes/data_registry.php | 4 +- lib/accesslib.php | 41 ++++--------------- lib/deprecatedlib.php | 31 ++++++++++++++ lib/upgrade.txt | 3 ++ 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/admin/tool/dataprivacy/classes/data_registry.php b/admin/tool/dataprivacy/classes/data_registry.php index 1435fcddb62..dbc8f32e610 100644 --- a/admin/tool/dataprivacy/classes/data_registry.php +++ b/admin/tool/dataprivacy/classes/data_registry.php @@ -147,8 +147,8 @@ class data_registry { if ($contextcourse = $context->get_course_context(false)) { // Below course level we look at module or block level roles + course-assigned roles. - $courseroles = get_roles_with_assignment_on_context($contextcourse); - $roles = $courseroles + get_roles_with_assignment_on_context($context); + $courseroles = get_roles_used_in_context($contextcourse, false); + $roles = $courseroles + get_roles_used_in_context($context, false); } else { // We list category + system for others (we don't work with user instances so no need to work about them). $roles = get_roles_used_in_context($context); diff --git a/lib/accesslib.php b/lib/accesslib.php index 536504cf847..5172ef450b4 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2548,12 +2548,17 @@ function get_profile_roles(context $context) { * Gets the list of roles assigned to this context and up (parents) * * @param context $context + * @param boolean $includeparents, false means without parents. * @return array */ -function get_roles_used_in_context(context $context) { +function get_roles_used_in_context(context $context, $includeparents = true) { global $DB; - list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl'); + if ($includeparents === true) { + list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl'); + } else { + list($contextlist, $params) = $DB->get_in_or_equal($context->id, SQL_PARAMS_NAMED, 'cl'); + } if ($coursecontext = $context->get_course_context(false)) { $params['coursecontext'] = $coursecontext->id; @@ -3988,22 +3993,6 @@ function get_user_capability_course($capability, $userid = null, $doanything = t return empty($courses) ? false : $courses; } -/** - * This function finds the roles assigned directly to this context only - * i.e. no roles in parent contexts - * - * @param context $context - * @return array - */ -function get_roles_on_exact_context(context $context) { - global $DB; - - return $DB->get_records_sql("SELECT r.* - FROM {role_assignments} ra, {role} r - WHERE ra.roleid = r.id AND ra.contextid = ?", - array($context->id)); -} - /** * Switches the current user to another role for the current session and only * in the given context. @@ -4091,22 +4080,6 @@ function get_capabilities_from_role_on_context($role, context $context) { array($context->id, $role->id)); } -/** - * Find out which roles has assignment on this context - * - * @param context $context - * @return array - * - */ -function get_roles_with_assignment_on_context(context $context) { - global $DB; - - return $DB->get_records_sql("SELECT r.* - FROM {role_assignments} ra, {role} r - WHERE ra.roleid = r.id AND ra.contextid = ?", - array($context->id)); -} - /** * Find all user assignment of users for this role, on this context * diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index daf12c48e66..df8c6ad508d 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -6613,3 +6613,34 @@ function groups_get_all_groups_for_courses($courses) { return $groups; } + +/** + * This function finds the roles assigned directly to this context only + * i.e. no roles in parent contexts + * + * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context(). + * @todo final deprecation. To be removed in Moodle 4.0 + * @param context $context + * @return array + */ +function get_roles_on_exact_context(context $context) { + debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.', + DEBUG_DEVELOPER); + + return get_roles_used_in_context($context, false); +} + +/** + * Find out which roles has assignment on this context + * + * @deprecated since Moodle 3.6. Please use the get_roles_used_in_context(). + * @todo final deprecation. To be removed in Moodle 4.0 + * @param context $context + * @return array + */ +function get_roles_with_assignment_on_context(context $context) { + debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.', + DEBUG_DEVELOPER); + + return get_roles_used_in_context($context, false); +} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index f2e8d0b5243..1c59166cc2a 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -22,6 +22,9 @@ information provided here is intended especially for developers. - I set the field "" to multiline - I follow """ in the open menu * Removed the lib/password_compat/lib/password.php file. +* Following functions have been deprecated, please use get_roles_used_in_context. + - get_roles_on_exact_context() + - get_roles_with_assignment_on_context() === 3.5 ===