diff --git a/backup/restore_form.html b/backup/restore_form.html index 742e30aa062..59299a47376 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -479,6 +479,7 @@ $info = restore_read_xml_info($xml_file); // fix for MDL-9068, front page course is just a normal course $siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "shortname"); $siterolesnamearray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "name"); +$allroles = get_records('role'); echo ('
| '.get_string('sourcerole').' | '.get_string('targetrole').' |
| '); echo $role->name." (".($role->shortname).")"; echo (' | '); - - // see if any short name match - $matchrole = 0; - foreach ($siterolesarray as $siteroleid=>$siteroleshortname) { - if ($siteroleshortname == $role->shortname) { - $matchrole = $siteroleid; - break; - } + + /// first, we see if any exact role definition is found + /// if found, that is the only option of restoring to + + if ($samerole = restore_samerole($roleid, $role)) { + $matchrole = $samerole->id; + // if an exact role is found, it does not matter whether this user can assign this role or not, + // this will be presented as a valid option regardless + $mappableroles[$samerole->id] = $allroles[$samerole->id]->name." (". $allroles[$samerole->id]->shortname.")"; + } else { + // no exact role found, let's try to match shortname + // this is useful in situations where basic roles differ slightly in definition + $matchrole = 0; + foreach ($siterolesarray as $siteroleid=>$siteroleshortname) { + if ($siteroleshortname == $role->shortname) { + $matchrole = $siteroleid; + break; + } + } } - - choose_from_menu ($siteroleschoicearray, "roles_".$roleid, $matchrole, 'new role', '', '0'); - echo (' |