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:
+11
-3
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user