MDL-54035 accesslib: only modify role_capabilities in accesslib

Whenever the role_capabilities table is changed, we need to remember
to clear the cache for the role(s) being modified. This is far simpler
when all of those changes happen in a single file, i.e. accesslib.php,
allowing other parts of the application to use the public functions
without requiring knowledge of the cache internals.
This commit is contained in:
Jonathan Champ
2018-09-21 09:17:43 -04:00
parent b2f349a433
commit 34dd57053d
4 changed files with 16 additions and 27 deletions
+11 -3
View File
@@ -5156,15 +5156,23 @@ abstract class context extends stdClass implements IteratorAggregate {
require_once($CFG->dirroot.'/grade/grading/lib.php');
grading_manager::delete_all_for_context($this->_id);
$ids = $DB->get_fieldset_select('role_capabilities', 'DISTINCT roleid', 'contextid = ?', array($this->_id));
// now delete stuff from role related tables, role_unassign_all
// and unenrol should be called earlier to do proper cleanup
$DB->delete_records('role_assignments', array('contextid'=>$this->_id));
$DB->delete_records('role_capabilities', array('contextid'=>$this->_id));
$DB->delete_records('role_names', array('contextid'=>$this->_id));
$this->delete_capabilities();
}
/**
* Unassign all capabilities from a context.
*/
public function delete_capabilities() {
global $DB;
$ids = $DB->get_fieldset_select('role_capabilities', 'DISTINCT roleid', 'contextid = ?', array($this->_id));
if ($ids) {
$DB->delete_records('role_capabilities', array('contextid' => $this->_id));
// Reset any cache of these roles, including MUC.
accesslib_clear_role_cache($ids);
}