// 'moodle/legacy:coursecreator'
// 'moodle/legacy:admin'
- if (!$roles = get_roles_with_capability('moodle/legacy:'.$type, CAP_ALLOW)) {
- return false;
- }
-
- foreach ($roles as $role) {
- // Assign a site level capability.
- if (!assign_capability($capability, $perm, $role->id, $systemcontext->id)) {
- return false;
+ if ($roles = get_roles_with_capability('moodle/legacy:'.$type, CAP_ALLOW)) {
+ foreach ($roles as $role) {
+ // Assign a site level capability.
+ if (!assign_capability($capability, $perm, $role->id, $systemcontext->id)) {
+ return false;
+ }
}
}
}
unassign_capability($capability, $roleid, $contextid);
}
- $existing = get_record('role_capabilities', 'contextid', $contextid, 'roleid', $capability, $capability);
+ $existing = get_record('role_capabilities', 'contextid', $contextid, 'roleid', $roleid, 'capability', $capability);
if ($existing and !$overwrite) { // We want to keep whatever is there already
return true;
// legacy capabilities moodle/legacy:* as well?
if (isset($capdef['legacy']) && is_array($capdef['legacy']) &&
!assign_legacy_capabilities($capname, $capdef['legacy'])) {
- error('Could not assign legacy capabilities');
- return false;
+ notify('Could not assign legacy capabilities for '.$capname);
}
}
// Are there any capabilities that have been removed from the file