From 01a80f51e542c4472c9f7808675412fa200ca652 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 6 Nov 2008 07:34:01 +0000 Subject: [PATCH] role assign: MDL-8312 Restrict which roles can be assigned at which contextlevels. * New table role_context_levels * Populate table with defaults on install * Populate table on upgrade with the same defaults, plus any additional ones needed to ensure all the role assignments already in the database are allowed. * Change get_assignable_roles to respect these settings. * UI for these settings on the add/edit role form. * Save these settings when a role definition is saved. * If in a context, there are no roles you can assign, display a polite message. * Back up these settings. * Restore these settings. When resotring a <=1.9.x backup file, any newly imported roles are set to be assignable at all contextlevels. Restore not tested because it is broken in HEAD. --- admin/roles/assign.php | 8 ++- admin/roles/manage.html | 25 ++++++--- admin/roles/manage.php | 46 +++++++++++++++- admin/roles/override.php | 4 ++ admin/roles/tabs.php | 37 ++----------- backup/backuplib.php | 9 +++- backup/restorelib.php | 28 ++++++++-- lang/en_utf8/role.php | 3 ++ lib/accesslib.php | 112 ++++++++++++++++++++++++++++++++------- lib/db/install.xml | 18 +++++-- lib/db/upgrade.php | 75 ++++++++++++++++++++++++++ version.php | 2 +- 12 files changed, 297 insertions(+), 70 deletions(-) diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 5b02a8f884..33e12c63d5 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -60,8 +60,8 @@ /// Make sure this user can assign this role if ($roleid && !isset($assignableroles[$roleid])) { - $a = stdClass; - $a->role = $roleid; + $a = new stdClass; + $a->roleid = $roleid; $a->context = $contextname; print_error('cannotassignrolehere', '', get_context_url($context), $a); } @@ -346,6 +346,10 @@ echo '

' . get_string('backtoallroles', 'role') . '

'; echo ''; + } else if (empty($assignableroles)) { + /// Print a message that there are no roles that can me assigned here. + print_heading(get_string('notabletoassignroleshere', 'role'), 'center', 3); + } else { /// Show UI for choosing a role to assign. diff --git a/admin/roles/manage.html b/admin/roles/manage.html index 4618a8275e..cfec37f847 100755 --- a/admin/roles/manage.html +++ b/admin/roles/manage.html @@ -23,19 +23,19 @@ - + - + - + - + + + + +
: name)); ?>
: shortname); ?>
: description, FORMAT_HTML)); $usehtmleditor = false; ?>
: legacytype)) { @@ -84,6 +84,21 @@
$clname) { + $extraarguments = $disabled; + if (in_array($cl, $rolecontextlevels)) { + $extraarguments .= 'checked="checked"'; + } + echo ' '; + echo '
\n"; + } + ?> +
permission = $role->{$capability->name}; } - $disabled = ($action != 'edit' and $action != 'add') ? ' disabled="disabled" ' : ''; - $riskinfo = ''; $rowclasses = ''; if (RISK_MANAGETRUST & (int)$capability->riskbitmask) { diff --git a/admin/roles/manage.php b/admin/roles/manage.php index 1c823e7e51..b3f007e374 100755 --- a/admin/roles/manage.php +++ b/admin/roles/manage.php @@ -28,6 +28,15 @@ $roles = get_all_roles(); $rolescount = count($roles); + $allcontextlevels = array( + CONTEXT_SYSTEM => get_string('coresystem'), + CONTEXT_USER => get_string('user'), + CONTEXT_COURSECAT => get_string('category'), + CONTEXT_COURSE => get_string('course'), + CONTEXT_MODULE => get_string('activitymodule'), + CONTEXT_BLOCK => get_string('block') + ); + /// fix sort order if needed $rolesort = array(); $i = 0; @@ -93,6 +102,16 @@ $newrole->legacytype = $legacytype; } + $newcontextlevels = array(); + foreach (array_keys($allcontextlevels) as $cl) { + if (optional_param('contextlevel' . $cl, false, PARAM_BOOL)) { + $newcontextlevels[$cl] = $cl; + } + } + if (empty($errors)) { + set_role_contextlevels($newroleid, $newcontextlevels); + } + $allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT); $capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context @@ -167,6 +186,16 @@ $newrole->legacytype = $legacytype; } + $newcontextlevels = array(); + foreach (array_keys($allcontextlevels) as $cl) { + if (optional_param('contextlevel' . $cl, false, PARAM_BOOL)) { + $newcontextlevels[$cl] = $cl; + } + } + if (empty($errors)) { + set_role_contextlevels($roleid, $newcontextlevels); + } + $allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT); $capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context @@ -365,6 +394,8 @@ // dupilcate all the capabilities role_cap_duplicate($sourcerole, $newrole); + set_role_contextlevels($newrole, get_role_contextlevels($roleid)); + // dup'ed a role sitewide... mark_context_dirty($sitecontext->path); @@ -380,6 +411,8 @@ } if ($confirm and data_submitted() and confirm_sesskey()) { + set_role_contextlevels($roleid, get_default_contextlevels(get_legacy_type($roleid))); + reset_role_capabilities($roleid); // reset a role sitewide... @@ -434,16 +467,21 @@ $role->shortname = ''; $role->description = ''; $role->legacytype = ''; + $rolecontextlevels = array(); } else { $role = $newrole; + $rolecontextlevels = $newcontextlevels; } } else if ($action == 'edit' and !empty($errors) and !empty($newrole)) { - $role = $newrole; + $role = $newrole; + $rolecontextlevels = $newcontextlevels; + } else { if(!$role = $DB->get_record('role', array('id'=>$roleid))) { print_error('wrongroleid', 'error'); } $role->legacytype = get_legacy_type($role->id); + $rolecontextlevels = get_role_contextlevels($roleid); } foreach ($roles as $rolex) { @@ -497,6 +535,12 @@ $lang = str_replace('_utf8', '', current_language()); + if ($action == 'edit' || $action == 'add') { + $disabled = ''; + } else { + $disabled = 'disabled="disabled" '; + } + print_simple_box_start('center'); include_once('manage.html'); print_simple_box_end(); diff --git a/admin/roles/override.php b/admin/roles/override.php index 5cef6e4b4c..e14cbe9f48 100755 --- a/admin/roles/override.php +++ b/admin/roles/override.php @@ -319,6 +319,10 @@ echo '

' . get_string('backtoallroles', 'role') . '

'; echo ''; + } else if (empty($overridableroles)) { + /// Print a message that there are no roles that can me assigned here. + print_heading(get_string('notabletooverrideroleshere', 'role'), 'center', 3); + } else { /// Show UI for choosing a role to assign. diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index 893763f583..0362c576ac 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -66,49 +66,20 @@ if ($currenttab != 'update') { break; case CONTEXT_MODULE: - // get module type? - if (!$cm = $DB->get_record('course_modules', array('id'=>$context->instanceid))) { + if (!$cm = get_coursemodule_from_id('', $context->instanceid)) { print_error('invalidcoursemodule', 'error'); } - if (!$module = $DB->get_record('modules', array('id'=>$cm->module))) { //$module->name; - print_error('invalidmodule', 'error'); - } - if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { + if (!$course = $DB->get_record('course', array('id' => $cm->course))) { print_error('invalidcourse'); } - if (!$instance = $DB->get_record($module->name, array('id'=>$cm->instance))) { - print_error('moduledoesnotexist', 'error'); - } require_login($course); - - $fullmodulename = get_string("modulename", $module->name); - $strmodulenameplural = get_string("modulenameplural", $module->name); - - if ($module->name == "label") { - $focuscursor = ""; - } else { - $focuscursor = "form.name"; - } - - $navlinks[] = array('name' => $strmodulenameplural, - 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", - 'type' => 'misc'); - - $navlinks[] = array('name' => $instance->name, - 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", - 'type' => 'misc'); - - $navlinks[] = array('name' => $streditinga, - 'link' => "$CFG->wwwroot/course/mod.php?update=$cm->id&sesskey=".sesskey(), - 'type' => 'misc'); - - $navigation = build_navigation($navlinks); + $navigation = build_navigation(get_string('roles'), $cm); if (empty($title)) { $title = get_string("editinga", "moodle", $fullmodulename); } - print_header_simple($title, '', $navigation, $focuscursor, "", false); + print_header_simple($title, '', $navigation, '', '', false); break; diff --git a/backup/backuplib.php b/backup/backuplib.php index 18cded66b6..d82e8f5e70 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -611,7 +611,14 @@ if ($nameincourse != $role->name) { fwrite ($bf,full_tag('NAMEINCOURSE', 3, false, $nameincourse)); } - // find and write all default capabilities + /// List of context level where this role can be assigned. + fwrite ($bf,start_tag('CONTEXTLEVELS',3,true)); + $contextlevels = get_role_contextlevels($role->id); + foreach ($contextlevels as $cl) { + fwrite ($bf,full_tag('CONTEXTLEVEL', 4, false, $cl)); + } + fwrite ($bf,end_tag('CONTEXTLEVELS',3,true)); + /// find and write all default capabilities fwrite ($bf,start_tag('CAPABILITIES',3,true)); // pull out all default (site context) capabilities if ($capabilities = role_context_capabilities($role->id, $sitecontext)) { diff --git a/backup/restorelib.php b/backup/restorelib.php index 030c170d93..1a422ffa4c 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -5047,13 +5047,20 @@ define('RESTORE_GROUPS_GROUPINGS', 3); $this->info->roles[$this->info->tempid]->id = $this->info->tempid; break; case "NAME": - $this->info->roles[$this->info->tempid]->name = $this->getContents();; + $this->info->roles[$this->info->tempid]->name = $this->getContents(); break; case "SHORTNAME": - $this->info->roles[$this->info->tempid]->shortname = $this->getContents();; + $this->info->roles[$this->info->tempid]->shortname = $this->getContents(); break; case "NAMEINCOURSE": // custom name of the role in course - $this->info->roles[$this->info->tempid]->nameincourse = $this->getContents();; + $this->info->roles[$this->info->tempid]->nameincourse = $this->getContents(); + break; + } + } + if ($this->level == 5) { + switch ($tagName) { + case "CONTEXTLEVEL": + $this->info->roles[$this->info->tempid]->contextlevels[] = $this->getContents(); break; } } @@ -8435,6 +8442,21 @@ define('RESTORE_GROUPS_GROUPINGS', 3); $newroleid = create_role($roledata->name, $roledata->shortname, ''); $status = backup_putid($restore->backup_unique_code,"role",$oldroleid, $newroleid); // adding a new id + + /// Restore the role contextlevels. + if (isset($roledata->contextlevels)) { + set_role_contextlevels($newroleid, $roledata->contextlevels); + } else { + // Data was not in the backup file (must be a pre-2.0 backup). + // Allow this role to be assigned at all levels, which is + // Which is what would have been possible where the backup + // was made. + set_role_contextlevels($newroleid, array(CONTEXT_SYSTEM, + CONTEXT_USER, CONTEXT_COURSECAT, CONTEXT_COURSE, + CONTEXT_MODULE, CONTEXT_BLOCK)); + } + + /// Restore all the role capabiltites. foreach ($roledata->capabilities as $capability) { $roleinfo = new object(); diff --git a/lang/en_utf8/role.php b/lang/en_utf8/role.php index 97209746e2..6b8782b74f 100644 --- a/lang/en_utf8/role.php +++ b/lang/en_utf8/role.php @@ -110,12 +110,15 @@ $string['legacytype'] = 'Legacy role type'; $string['listallroles'] = 'List all roles'; $string['localroles'] = 'Locally assigned roles'; $string['manageroles'] = 'Manage roles'; +$string['maybeassignedin'] = 'Context types where this role may be assigned'; $string['metaassignerror'] = 'Can not assign this role to user \"$a\" because Manage metacourse capability is needed.'; $string['metaunassignerror'] = 'Role of user \"$a\" was automatically reassigned, please unassign the role in child courses instead.'; $string['morethan'] = 'More than $a'; $string['multipleroles'] = 'Multiple roles'; $string['my:manageblocks'] = 'Manage myMoodle page blocks'; $string['nocapabilitiesincontext'] = 'No capabilities available in this context'; +$string['notabletoassignroleshere'] = 'You are not able to assign any roles here'; +$string['notabletooverrideroleshere'] = 'You are not able to override the permissions on any roles here'; $string['notset'] = 'Not set'; $string['overrideanotherrole'] = 'Override another role'; $string['overridecontext'] = 'Override context'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 42c7246da1..f37ab6b4c3 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1825,6 +1825,14 @@ function moodle_install_roles() { //allow_override($editteacherrole, $studentrole); //allow_override($editteacherrole, $guestrole); +/// Set up the context levels where you can assign each role. + set_role_contextlevels($adminrole->id, get_default_contextlevels('admin')); + set_role_contextlevels($coursecreatorrole->id, get_default_contextlevels('coursecreator')); + set_role_contextlevels($editteacherrole->id, get_default_contextlevels('editingteacher')); + set_role_contextlevels($noneditteacherrole->id, get_default_contextlevels('teacher')); + set_role_contextlevels($studentrole->id, get_default_contextlevels('student')); + set_role_contextlevels($guestrole->id, get_default_contextlevels('guest')); + set_role_contextlevels($userrole->id, get_default_contextlevels('user')); } /** @@ -1922,6 +1930,7 @@ function is_safe_capability($capability) { return (RISK_DATALOSS | RISK_MANAGETRUST | RISK_CONFIG | RISK_XSS | RISK_PERSONAL) & $capability->riskbitmask; } + /********************************** * Context Manipulation functions * **********************************/ @@ -2593,6 +2602,7 @@ function delete_role($roleid) { $DB->delete_records('role_allow_override', array('roleid'=>$roleid)); $DB->delete_records('role_allow_override', array('allowoverride'=>$roleid)); $DB->delete_records('role_names', array('roleid'=>$roleid)); + $DB->delete_records('role_context_levels', array('roleid'=>$roleid)); } // finally delete the role itself @@ -3345,12 +3355,12 @@ function print_context_name($context, $withprefix = true, $short = false) { if ($cm = $DB->get_record_sql('SELECT cm.*, md.name AS modname FROM {course_modules} cm ' . 'JOIN {modules} md ON md.id = cm.module WHERE cm.id = ?', array($context->instanceid))) { if ($mod = $DB->get_record($cm->modname, array('id' => $cm->instance))) { - if ($withprefix){ + if ($withprefix){ $name = get_string('modulename', $cm->modname).': '; + } + $name .= $mod->name; } - $name .= $mod->name; } - } break; case CONTEXT_BLOCK: // not necessarily 1 to 1 to course @@ -4148,7 +4158,11 @@ function get_assignable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $with global $USER, $DB; if (!has_capability('moodle/role:assign', $context)) { - return array(); + if ($withusercounts) { + return array(array(), array(), array()); + } else { + return array(); + } } $parents = get_parent_contexts($context); @@ -4170,18 +4184,21 @@ function get_assignable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $with } $params['userid'] = $USER->id; + $params['contextlevel'] = $context->contextlevel; if (!$roles = $DB->get_records_sql(" - SELECT ro.id, ro.name$extrafields - FROM {role} ro + SELECT ro.id, ro.name$extrafields + FROM {role} ro JOIN (SELECT DISTINCT r.id - FROM {role} r, - {role_assignments} ra, - {role_allow_assign} raa - WHERE ra.userid = :userid AND ra.contextid IN ($contexts) - AND raa.roleid = ra.roleid AND r.id = raa.allowassign - ) inline_view ON ro.id = inline_view.id - ORDER BY ro.sortorder ASC", $params)) { - return array(); + FROM {role} r, + {role_assignments} ra, + {role_allow_assign} raa + WHERE ra.userid = :userid AND ra.contextid IN ($contexts) + AND raa.roleid = ra.roleid AND r.id = raa.allowassign + ) inline_view ON ro.id = inline_view.id + JOIN {role_context_levels} rcl ON ro.id = rcl.roleid + WHERE rcl.contextlevel = :contextlevel + ORDER BY ro.sortorder ASC", $params)) { + $roles = array(); } $rolenames = array(); @@ -4189,7 +4206,7 @@ function get_assignable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $with $rolenames[$role->id] = $role->name; if ($rolenamedisplay == ROLENAME_ORIGINALANDSHORT) { $rolenames[$role->id] .= ' (' . $role->shortname . ')'; - } + } } if ($rolenamedisplay != ROLENAME_ORIGINALANDSHORT) { $rolenames = role_fix_names($rolenames, $context, $rolenamedisplay); @@ -4265,7 +4282,11 @@ function get_overridable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $wit global $USER, $DB; if (!has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override'), $context)) { - return array(); + if ($withcounts) { + return array(array(), array(), array()); + } else { + return array(); + } } $parents = get_parent_contexts($context); @@ -4289,14 +4310,14 @@ function get_overridable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $wit SELECT ro.id, ro.name$extrafields FROM {role} ro JOIN ( - SELECT DISTINCT r.id + SELECT DISTINCT r.id FROM {role} r JOIN {role_allow_override} rao ON r.id = rao.allowoverride JOIN {role_assignments} ra ON rao.roleid = ra.roleid - WHERE ra.userid = :userid AND ra.contextid IN ($contexts) + WHERE ra.userid = :userid AND ra.contextid IN ($contexts) ) inline_view ON ro.id = inline_view.id ORDER BY ro.sortorder ASC", $params)) { - return array(); + $roles = array(); } $rolenames = array(); @@ -4312,7 +4333,7 @@ function get_overridable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $wit if (!$withcounts) { return $rolenames; - } +} $rolecounts = array(); $nameswithcounts = array(); @@ -4323,6 +4344,57 @@ function get_overridable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $wit return array($rolenames, $rolecounts, $nameswithcounts); } +/** + * @param integer $roleid the id of a role. + * @return array list of the context levels at which this role may be assigned. + */ +function get_role_contextlevels($roleid) { + global $DB; + return $DB->get_records_menu('role_context_levels', array('roleid' => $roleid), + 'contextlevel', 'id,contextlevel'); +} + +/** + * @param string $roleid one of the legacy role types - that is, one of the keys + * from the array returned by get_legacy_roles(); + * @return array list of the context levels at which this type of role may be assigned by default. + */ +function get_default_contextlevels($roletype) { + static $defaults = array( + 'admin' => array(CONTEXT_SYSTEM), + 'coursecreator' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT), + 'editingteacher' => array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE), + 'teacher' => array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE), + 'student' => array(CONTEXT_COURSE, CONTEXT_MODULE), + 'guest' => array(), + 'user' => array() + ); + + return $defaults[$roletype]; +} + +/** + * Set the context levels at which a particular role can be assigned. + * Throws exceptions in case of error. + * + * @param integer $roleid the id of a role. + * @param array $contextlevels the context levels at which this role should be assignable. + */ +function set_role_contextlevels($roleid, array $contextlevels) { + global $DB; + if (!$DB->delete_records('role_context_levels', array('roleid' => $roleid))) { + throw new moodle_exception('couldnotdeleterolecontextlevels', '', '', $roleid); + } + $rcl = new stdClass; + $rcl->roleid = $roleid; + foreach ($contextlevels as $level) { + $rcl->contextlevel = $level; + if (!$DB->insert_record('role_context_levels', $rcl, false, true)) { + throw new moodle_exception('couldnotdeleterolecontextlevels', '', '', $rcl); + } + } +} + /** * Returns a role object that is the default role for new enrolments * in a given course diff --git a/lib/db/install.xml b/lib/db/install.xml index 6cd878eeca..ba48f95967 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -881,7 +881,7 @@ - +
@@ -899,7 +899,19 @@
- +
+ + + + + + + + + + +
+ diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index fd5a0ebf3a..d529515505 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -873,6 +873,81 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint($result, 2008101300); } + /// New table for storing which roles can be assigned in which contexts. + if ($result && $oldversion < 2008110601) { + + /// Define table role_context_levels to be created + $table = new xmldb_table('role_context_levels'); + + /// Adding fields to table role_context_levels + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table role_context_levels + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); + $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); + + /// Conditionally launch create table for role_context_levels + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008110601); + } + + /// Now populate the role_context_levels table with the defaults that match + /// moodle_install_roles, and any other combinations that exist in this system. + if ($result && $oldversion < 2008110602) { + $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id'); + + /// Defaults, should match moodle_install_roles. + $rolecontextlevels = array(); + if (isset($roleids['admin'])) { + $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin'); + } + if (isset($roleids['coursecreator'])) { + $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator'); + } + if (isset($roleids['editingteacher'])) { + $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher'); + } + if (isset($roleids['teacher'])) { + $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher'); + } + if (isset($roleids['student'])) { + $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student'); + } + if (isset($roleids['guest'])) { + $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest'); + } + if (isset($roleids['user'])) { + $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user'); + } + + /// See what other role assignments are in this database, extend the allowed + /// lists to allow them too. + $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM + {role_assignments} ra JOIN {context} con ON ra.contextid = con.id'); + foreach ($existingrolecontextlevels as $rcl) { + if (!isset($rolecontextlevels[$rcl->roleid])) { + $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel); + } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) { + $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; + } + } + + /// Put the data into the database. + foreach ($rolecontextlevels as $roleid => $contextlevels) { + set_role_contextlevels($roleid, $contextlevels); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2008110602); + } + return $result; } diff --git a/version.php b/version.php index 5595602018..1610a47408 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008101300; // YYYYMMDD = date of the last version bump + $version = 2008110602; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20081106)'; // Human-friendly version name -- 2.39.5