if ($status) {
// Install the roles system.
moodle_install_roles();
- if (!update_capabilities()) {
- error('Had trouble installing the core capabilities for the Roles System');
- }
set_config('statsrolesupgraded',time());
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
if (empty($CFG->rolesactive)) {
// Upgrade to the roles system.
moodle_install_roles();
- }
- if (!update_capabilities()) {
- error('Had trouble upgrading the core capabilities for the Roles System');
- } else {
set_config('rolesactive', 1);
+ } else if (!update_capabilities()) {
+ error('Had trouble upgrading the core capabilities for the Roles System');
}
require_once($CFG->libdir.'/statslib.php');
if (!stats_upgrade_for_roles_wrapper()) {
$studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
$guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest');
+ // now is the correct moment to install capabilitites - after creation of legacy roles, but before assigning of roles
+ if (!update_capabilities()) {
+ error('Had trouble upgrading the core capabilities for the Roles System');
+ }
// Look inside user_admin, user_creator, user_teachers, user_students and
// assign above new roles. If a user has both teacher and student role,