Skip to content

Commit

Permalink
MDL-2674 adding $cm->grouping reset if groupings not restored; remove…
Browse files Browse the repository at this point in the history
…d info about groups included in backup - they are always included, and there will not be any global groups/groupings; merged from MOODLE_19_STABLE
  • Loading branch information
skodak committed Mar 17, 2008
1 parent e807e47 commit 7f9b934
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backup/restore_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
$group_options[RESTORE_GROUPS_NONE] = get_string('no');
$group_options[RESTORE_GROUPS_ONLY] = get_string('yes');
} else {
echo '<label for="menurestore_groups">'.get_string ("groupsgroupings").'</label>'.$helplink;
echo '<label for="menurestore_groups">'.get_string ('groupsgroupings', 'group').'</label>'.$helplink;
echo "</b></td><td colspan=\"2\">";
$group_options[RESTORE_GROUPS_NONE] = get_string('none');
$group_options[RESTORE_GROUPS_ONLY] = get_string('groups');
Expand Down
29 changes: 16 additions & 13 deletions backup/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,6 @@ function restore_print_info ($info) {
$tab[$elem][0] = "<b>".get_string("users").":</b>";
$tab[$elem][1] = get_string($info->backup_users);
$elem++;
//Groups info
if (empty($CFG->enablegroupings)) {
$tab[$elem][0] = "<b>".get_string('groups').":</b>";
} else {
$tab[$elem][0] = "<b>".get_string('groupsgroupings','group').":</b>";
}
if (!isset($info->backup_groups)) { //Backwards compatibility.
$info->backup_groups = 'course';
}
$tab[$elem][1] = get_string($info->backup_groups);
$elem++;
//Logs info
$tab[$elem][0] = "<b>".get_string("logs").":</b>";
if ($info->backup_logs == "true") {
Expand Down Expand Up @@ -1083,7 +1072,7 @@ function restore_create_sections(&$restore, $xml_file) {
$course_module->indent = $mod->indent;
$course_module->visible = $mod->visible;
$course_module->groupmode = $mod->groupmode;
if ($mod->groupingid and $grouping = backup_getid($restore->backup_unique_code,"groupings",$mod->groupingid)) {
if ($mod->groupingid and $grouping = restore_grouping_getid($restore, $mod->groupingid)) {
$course_module->groupingid = $grouping->new_id;
} else {
$course_module->groupingid = 0;
Expand Down Expand Up @@ -3067,6 +3056,20 @@ function restore_group_getid($restore, $groupid) {
return $group;
}

/**
* Recode grouping ID field, and set grouping ID based on restore options.
* @return object Group object with new_id field.
*/
function restore_grouping_getid($restore, $groupingid) {
//We have to recode the groupid field
$grouping = backup_getid($restore->backup_unique_code, 'groupings', $groupingid);

if ($restore->groups == RESTORE_GROUPS_GROUPINGS or $restore->groups == RESTORE_GROUPINGS_ONLY) {
$grouping->new_id = 0;
}
return $grouping;
}

//This function creates all the groups
function restore_create_groups($restore,$xml_file) {

Expand Down Expand Up @@ -3280,7 +3283,7 @@ function restore_create_groupings($restore,$xml_file) {
// now fix the defaultgroupingid in course
$course = get_record('course', 'id', $restore->course_id);
if ($course->defaultgroupingid) {
if ($grouping = backup_getid($restore->backup_unique_code,"groupings",$course->defaultgroupingid)) {
if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) {
set_field('course', 'defaultgroupingid', $grouping->new_id, 'id', $course->id);
} else {
set_field('course', 'defaultgroupingid', 0, 'id', $course->id);
Expand Down

0 comments on commit 7f9b934

Please sign in to comment.