mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
fixing roles support for backup/restore
This commit is contained in:
parent
e0539647aa
commit
c0c98c7c78
2 changed files with 33 additions and 29 deletions
|
@ -422,7 +422,7 @@ $xml_file = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
|
||||||
|
|
||||||
$info = restore_read_xml_info($xml_file);
|
$info = restore_read_xml_info($xml_file);
|
||||||
|
|
||||||
$siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course_header->course_id), "shortname");
|
$siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "shortname");
|
||||||
|
|
||||||
echo ('<table width="100%" class="restore-form-instances">');
|
echo ('<table width="100%" class="restore-form-instances">');
|
||||||
echo ('<tr><td align="right"><b>'.get_string('sourcerole').'</b></td><td align="left"><b>'.get_string('targetrole').'</b></td></tr>');
|
echo ('<tr><td align="right"><b>'.get_string('sourcerole').'</b></td><td align="left"><b>'.get_string('targetrole').'</b></td></tr>');
|
||||||
|
@ -432,19 +432,19 @@ if ($info->backup_moodle_version < 2006092801) {
|
||||||
|
|
||||||
/// Editting teacher
|
/// Editting teacher
|
||||||
echo ('<tr><td align="right">');
|
echo ('<tr><td align="right">');
|
||||||
print_string('teacheredit');
|
print_string('defaultcourseteacher');
|
||||||
echo ('</td><td algin="left">');
|
echo ('</td><td algin="left">');
|
||||||
|
|
||||||
// get the first teacheredit legacy
|
// get the first teacheredit legacy
|
||||||
$roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID));
|
$roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||||
|
|
||||||
$editteacher = array_shift($roles);
|
$editteacher = array_shift($roles);
|
||||||
choose_from_menu ($siterolesarray, "defaultteacheredit", $editteacher->id);
|
choose_from_menu ($siterolesarray, "defaultteacheredit", $editteacher->id);
|
||||||
echo ('</td></tr>');
|
echo ('</td></tr>');
|
||||||
|
|
||||||
/// Non-editting teacher
|
/// Non-editting teacher
|
||||||
echo ('<tr><td align="right">');
|
echo ('<tr><td align="right">');
|
||||||
print_string('teacher');
|
print_string('noneditingteacher');
|
||||||
echo ('</td><td algin="left">');
|
echo ('</td><td algin="left">');
|
||||||
|
|
||||||
// get the first teacheredit legacy
|
// get the first teacheredit legacy
|
||||||
|
@ -457,7 +457,7 @@ if ($info->backup_moodle_version < 2006092801) {
|
||||||
|
|
||||||
/// Student
|
/// Student
|
||||||
echo ('<tr><td align="right">');
|
echo ('<tr><td align="right">');
|
||||||
print_string('student');
|
print_string('defaultcoursestudent');
|
||||||
echo ('</td><td algin="left">');
|
echo ('</td><td algin="left">');
|
||||||
|
|
||||||
// get the first teacheredit legacy
|
// get the first teacheredit legacy
|
||||||
|
@ -469,25 +469,26 @@ if ($info->backup_moodle_version < 2006092801) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 1.7 and above backup
|
// 1.7 and above backup
|
||||||
|
|
||||||
$roles = restore_read_xml_roles($xml_file);
|
$roles = restore_read_xml_roles($xml_file);
|
||||||
|
if (is_array($roles)) { // possible to have course with no roles
|
||||||
|
|
||||||
foreach ($roles->roles as $roleid=>$role) {
|
foreach ($roles->roles as $roleid=>$role) {
|
||||||
echo ('<tr><td align="right">');
|
echo ('<tr><td align="right">');
|
||||||
echo $role->shortname;
|
echo $role->shortname;
|
||||||
echo ('</td><td align="left">');
|
echo ('</td><td align="left">');
|
||||||
|
|
||||||
// see if any short name match
|
// see if any short name match
|
||||||
$matchrole = 0;
|
$matchrole = 0;
|
||||||
foreach ($siterolesarray as $siteroleid=>$siteroleshortname) {
|
foreach ($siterolesarray as $siteroleid=>$siteroleshortname) {
|
||||||
if ($siteroleshortname == $role->shortname) {
|
if ($siteroleshortname == $role->shortname) {
|
||||||
$matchrole = $siteroleid;
|
$matchrole = $siteroleid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
choose_from_menu ($siterolesarray, "roles_".$roleid, $matchrole, 'new role', '', '0');
|
||||||
|
echo ('</td></tr>');
|
||||||
}
|
}
|
||||||
|
|
||||||
choose_from_menu ($siterolesarray, "roles_".$roleid, $matchrole, 'new role', '', '0');
|
|
||||||
echo ('</td></tr>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end else
|
} // end else
|
||||||
|
|
|
@ -800,8 +800,10 @@
|
||||||
//Add this instance
|
//Add this instance
|
||||||
$instance->blockid = $blocks[$instance->name]->id;
|
$instance->blockid = $blocks[$instance->name]->id;
|
||||||
|
|
||||||
if($newid = insert_record('block_instance', $instance)) {
|
if ($newid = insert_record('block_instance', $instance)) {
|
||||||
backup_putid ($restore->backup_unique_code,"block_instance",$instance->id,$newid);
|
if (!empty($instance->id)) { // this will only be set if we come from 1.7 and above backups
|
||||||
|
backup_putid ($restore->backup_unique_code,"block_instance",$instance->id,$newid);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$status = false;
|
$status = false;
|
||||||
break;
|
break;
|
||||||
|
@ -907,7 +909,7 @@
|
||||||
$restore->mods[$mod->type]->granular = true;
|
$restore->mods[$mod->type]->granular = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$restore->mods[$mod->type]->granular // we don't care about per instance
|
if (empty($restore->mods[$mod->type]->granular) // we don't care about per instance
|
||||||
|| (array_key_exists($mod->instance,$restore->mods[$mod->type]->instances)
|
|| (array_key_exists($mod->instance,$restore->mods[$mod->type]->instances)
|
||||||
&& !empty($restore->mods[$mod->type]->instances[$mod->instance]->restore))) {
|
&& !empty($restore->mods[$mod->type]->instances[$mod->instance]->restore))) {
|
||||||
|
|
||||||
|
@ -929,6 +931,7 @@
|
||||||
// final step of the restore. We don't know it yet.
|
// final step of the restore. We don't know it yet.
|
||||||
//print_object($course_module); //Debug
|
//print_object($course_module); //Debug
|
||||||
//Save it to db
|
//Save it to db
|
||||||
|
|
||||||
$newidmod = insert_record("course_modules",$course_module);
|
$newidmod = insert_record("course_modules",$course_module);
|
||||||
if ($newidmod) {
|
if ($newidmod) {
|
||||||
//save old and new module id
|
//save old and new module id
|
||||||
|
@ -1564,6 +1567,7 @@
|
||||||
$user->roles['teacher']->timeend,
|
$user->roles['teacher']->timeend,
|
||||||
0,
|
0,
|
||||||
$user->roles['teacher']->enrol);
|
$user->roles['teacher']->enrol);
|
||||||
|
|
||||||
// editting teacher
|
// editting teacher
|
||||||
} else {
|
} else {
|
||||||
// non editting teacher
|
// non editting teacher
|
||||||
|
@ -2540,12 +2544,11 @@
|
||||||
}
|
}
|
||||||
//Iterate over each module
|
//Iterate over each module
|
||||||
foreach ($info as $mod) {
|
foreach ($info as $mod) {
|
||||||
if (!(isset($restore->mods[$mod->modtype]->granular) && $restore->mods[$mod->modtype]->granular) // We don't care about per instance, i.e. restore all instances.
|
if (empty($restore->mods[$mod->modtype]->granular) // We don't care about per instance, i.e. restore all instances.
|
||||||
|| (array_key_exists($mod->id,$restore->mods[$mod->modtype]->instances)
|
|| (array_key_exists($mod->id,$restore->mods[$mod->modtype]->instances)
|
||||||
&& !empty($restore->mods[$mod->modtype]->instances[$mod->id]->restore))) {
|
&& !empty($restore->mods[$mod->modtype]->instances[$mod->id]->restore))) {
|
||||||
$modrestore = $mod->modtype."_restore_mods";
|
$modrestore = $mod->modtype."_restore_mods";
|
||||||
if (function_exists($modrestore)) {
|
if (function_exists($modrestore)) { //Debug
|
||||||
//print_object ($mod); //Debug
|
|
||||||
$status = $status and $modrestore($mod,$restore); //bit operator & not reliable here!
|
$status = $status and $modrestore($mod,$restore); //bit operator & not reliable here!
|
||||||
} else {
|
} else {
|
||||||
//Something was wrong. Function should exist.
|
//Something was wrong. Function should exist.
|
||||||
|
@ -3992,7 +3995,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->tree[7] == "ROLES_ASSIGNMENTS") {
|
if (isset($this->tree[7]) && $this->tree[7] == "ROLES_ASSIGNMENTS") {
|
||||||
|
|
||||||
if ($this->level == 9) {
|
if ($this->level == 9) {
|
||||||
switch ($tagName) {
|
switch ($tagName) {
|
||||||
|
@ -4045,7 +4048,7 @@
|
||||||
}
|
}
|
||||||
} /// ends role_assignments
|
} /// ends role_assignments
|
||||||
|
|
||||||
if ($this->tree[7] == "ROLES_OVERRIDES") {
|
if (isset($this->tree[7]) && $this->tree[7] == "ROLES_OVERRIDES") {
|
||||||
if ($this->level == 9) {
|
if ($this->level == 9) {
|
||||||
switch ($tagName) {
|
switch ($tagName) {
|
||||||
case "NAME":
|
case "NAME":
|
||||||
|
@ -6104,7 +6107,7 @@
|
||||||
* Restoring from course level overrides *
|
* Restoring from course level overrides *
|
||||||
*****************************************************/
|
*****************************************************/
|
||||||
|
|
||||||
if (!empty($course->$course->roleoverrides)) {
|
if (!empty($course->roleoverrides)) {
|
||||||
$courseoverrides = $course->roleoverrides;
|
$courseoverrides = $course->roleoverrides;
|
||||||
$rolemappings = $restore->rolesmapping;
|
$rolemappings = $restore->rolesmapping;
|
||||||
foreach ($courseoverrides as $oldroleid => $courseoverride) {
|
foreach ($courseoverrides as $oldroleid => $courseoverride) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue