$restore_metacourse = required_param('restore_metacourse');
//restore_users
$restore_users = required_param('restore_users');
+
+ $restore_groups = required_param('restore_groups');
//restore_logs
$restore_logs = required_param('restore_logs');
//restore_user_files
$restore->restoreto=$restore_restoreto;
$restore->metacourse=$restore_metacourse;
$restore->users=$restore_users;
+ $restore->groups=$restore_groups;
$restore->logs=$restore_logs;
$restore->user_files=$restore_user_files;
$restore->course_files=$restore_course_files;
$restore_users = 1;
}
+ if (!isset($restore_groups)) {
+ if (empty($CFG->enablegroupings)) {
+ $restore_groups = RESTORE_GROUPS_ONLY;
+ } else {
+ $restore_groups = RESTORE_GROUPS_GROUPINGS;
+ }
+ }
+
if (!isset($restore_logs)) {
$restore_logs = 1;
}
}
echo "</td></tr>";
+ //Now print the Groups tr (assume there is no $info->backup_groups)
+ echo "<tr>";
+ echo "<td align=\"right\" colspan=\"2\"><b>";
+ $helplink = helpbutton('grouprestore', get_string('groups'), '', true, false, '', true);
+ if (empty($CFG->enablegroupings)) {
+ echo get_string('groups').$helplink.":";
+ echo "</b></td><td colspan=\"2\">";
+ $group_options[RESTORE_GROUPS_NONE] = get_string('no');
+ $group_options[RESTORE_GROUPS_ONLY] = get_string('yes');
+ } else {
+ echo get_string('groupsgroupings', 'group').$helplink.":";
+ echo "</b></td><td colspan=\"2\">";
+ $group_options[RESTORE_GROUPS_NONE] = get_string('none');
+ $group_options[RESTORE_GROUPINGS_ONLY] = get_string('groupingsonly', 'group');
+ $group_options[RESTORE_GROUPS_GROUPINGS] = get_string('groupsgroupings', 'group'); //all.
+
+ } /*else {
+ echo get_string('none');
+ echo "<input type=\"hidden\" name=\"restore_groups\" value=\"2\" />";
+ }*/
+ choose_from_menu($group_options, 'restore_groups', $restore_groups, '');
+ echo "</td></tr>";
+
//Now print the Logs tr
echo "<tr>";
echo "<td align=\"right\" colspan=\"2\"><b>";
<?php //$Id$
//Functions used in restore
+/**
+ * Group backup/restore constants, 0.
+ */
+define('RESTORE_GROUPS_NONE', 0);
+
+/**
+ * Group backup/restore constants, 1.
+ */
+define('RESTORE_GROUPS_ONLY', 1);
+
+/**
+ * Group backup/restore constants, 2.
+ */
+define('RESTORE_GROUPINGS_ONLY', 2);
+
+/**
+ * Group backup/restore constants, course/all.
+ */
+define('RESTORE_GROUPS_GROUPINGS', 3);
+
//This function unzips a zip file in the same directory that it is
//It automatically uses pclzip or command line unzip
function restore_unzip ($file) {
$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") {
$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( ($restore->groups == RESTORE_GROUPINGS_ONLY or $restore->groups == RESTORE_GROUPS_GROUPINGS)
+ and $mod->groupingid and $grouping = backup_getid($restore->backup_unique_code,"groupings",$mod->groupingid) ) {
$course_module->groupingid = $grouping->new_id;
} else {
$course_module->groupingid = 0;
return $status;
}
+ /**
+ * Recode group ID field, and set group ID based on restore options.
+ * @return object Group object with new_id field.
+ */
+ function restore_group_getid($restore, $groupid) {
+ //We have to recode the groupid field
+ $group = backup_getid($restore->backup_unique_code, 'groups', $groupid);
+
+ if ($restore->groups == RESTORE_GROUPS_NONE or $restore->groups == RESTORE_GROUPINGS_ONLY) {
+ $group->new_id = 0;
+ }
+ return $group;
+ }
+
//This function creates all the groups
function restore_create_groups($restore,$xml_file) {
$gro = new Object();
///$gro->id = backup_todb($info['GROUPING']['#']['ID']['0']['#']);
$gro->courseid = $restore->course_id;
- $gro->name = backup_todb($info['GROUPING']['#']['NAME']['0']['#']);
+ $oldname = backup_todb($info['GROUPING']['#']['NAME']['0']['#']);
+ $oldshortname = $restore->course_shortname;
+ if (false===strpos($oldname, $oldshortname)) {
+ $gro->name = $oldname;
+ }
+ elseif ($shortname = get_field('course', 'shortname', 'id', $restore->course_id)) {
+ $gro->name = preg_replace("/$oldshortname/", $shortname, $oldname);
+ }
$gro->description = backup_todb($info['GROUPING']['#']['DESCRIPTION']['0']['#']);
$gro->configdata = backup_todb($info['GROUPING']['#']['CONFIGDATA']['0']['#']);
$gro->timecreated = backup_todb($info['GROUPING']['#']['TIMECREATED']['0']['#']);
//Now create groups as needed
- if ($status) {
+ if ($status and ($restore->groups == RESTORE_GROUPS_ONLY or $restore->groups == RESTORE_GROUPS_GROUPINGS)) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("creatinggroups");
}
}
//Now create groupings as needed
- if ($status) {
+ if ($status and ($restore->groups == RESTORE_GROUPINGS_ONLY or $restore->groups == RESTORE_GROUPS_GROUPINGS)) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("creatinggroupings");
}
}
//Now create groupingsgroups as needed
- if ($status) {
+ if ($status and $restore->groups == RESTORE_GROUPS_GROUPINGS) {
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("creatinggroupingsgroups");
}
fclose($restorelog);
}
}
-?>
+?>
\ No newline at end of file
$string['deleteallgroups'] = 'Delete all groups';
$string['deleteallgroupings'] = 'Delete all groupings';
-?>
+$string['groupsgroupings'] = 'Groups & groupings';
+$string['groupingsonly'] = 'Groupings only';
+
+?>
\ No newline at end of file
--- /dev/null
+<h1>Restoring Groups</h1>
+
+<p>You can now choose whether you want to restore groups<?php
+global $CFG;
+if (empty($CFG->enablegroupings)) {
+ echo '. ';
+} else {
+ echo ', and groupings. ';
+}
+?>
+The options are:</p>
+
+<dl>
+<?php if (empty($CFG->enablegroupings)) { ?>
+ <dt>No</dt>
+ <dd>Do not restore groups.</dd>
+ <dt>Yes</dt>
+ <dd>Restore groups.</dd>
+<?php } else { ?>
+ <dt>None</dt>
+ <dd>Do not restore groups or groupings. The grouping for grouping activities is reset to 'None'.</dd>
+ <dt>Groupings only</dt>
+ <dd>Groupings are restored, empty. The grouping selected for grouping activities
+ is maintained, and groups are not restored.</dd>
+ <dt>Groups & groupings</dt>
+ <dd>Groups and groupings are restored, and all related settings are maintained.</dd>
+<?php } ?>
+</dl>
+
+<h2>Group mode for course and activities</h2>
+<p>Whichever option is chosen the separate or visible groups setting for the course and activities is maintained.
+ We hope this is useful for users who wish to recreate groups after restoring a course.
+</p>
$string['writinggradebookinfo'] = 'Writing gradebook info';
$string['writinggroupsinfo'] = 'Writing groups info';
$string['writinggroupingsinfo'] = 'Writing groupings info';
+$string['writinggroupingsgroupsinfo'] = 'Writing groupings-groups info';
$string['writingheader'] = 'Writing header';
$string['writingloginfo'] = 'Writing logs info';
$string['writingmessagesinfo'] = 'Writing messages info';
$string['authenticationplugins'] = 'Authentication Plugins';
$string['chooseauthmethod'] = 'Choose authentication plugin';
-?>
+?>
\ No newline at end of file
$olduserid = backup_todb($mes_info['#']['USERID']['0']['#']);
//Now, build the CHAT_MESSAGES record structure
+ $message = new object();
$message->chatid = $new_chat_id;
$message->userid = backup_todb($mes_info['#']['USERID']['0']['#']);
$message->groupid = backup_todb($mes_info['#']['GROUPID']['0']['#']);
}
//We have to recode the groupid field
- $group = backup_getid($restore->backup_unique_code, 'groups', $message->groupid);
+ $group = restore_group_getid($restore, $message->groupid);
if ($group) {
$message->groupid = $group->new_id;
}
$record -> timemodified = backup_todb($rec_info['#']['TIMEMODIFIED']['0']['#']);
$record -> approved = backup_todb($rec_info['#']['APPROVED']['0']['#']);
$user = backup_getid($restore->backup_unique_code,"user",$record->userid);
- $group= backup_getid($restore->backup_unique_code,"groups",$record->groupid);
+ $group= restore_group_getid($restore, $record->groupid);
if ($user) {
$record->userid = $user->new_id;
return $status;
}
-?>
+?>
\ No newline at end of file
$olduserid = backup_todb($dis_info['#']['USERID']['0']['#']);
//Now, build the FORUM_DISCUSSIONS record structure
+ $discussion = new object();
$discussion->forum = $forum_id;
$discussion->course = $restore->course_id;
$discussion->name = backup_todb($dis_info['#']['NAME']['0']['#']);
}
//We have to recode the groupid field
- $group = backup_getid($restore->backup_unique_code, 'groups', $discussion->groupid);
+ $group = restore_group_getid($restore, $discussion->groupid);
if ($group) {
$discussion->groupid = $group->new_id;
}
$oldid = backup_todb($ent_info['#']['ID']['0']['#']);
//Now, build the wiki_ENTRIES record structure
+ $entry = new object();
$entry->wikiid = $new_wiki_id;
$entry->course = $restore->course_id;
$entry->userid = backup_todb($ent_info['#']['USERID']['0']['#']);
$entry->userid = $user->new_id;
}
//We have to recode the groupid field
- $group = backup_getid($restore->backup_unique_code, 'groups', $entry->groupid);
+ $group = restore_group_getid($restore, $entry->groupid);
if ($group) {
$entry->groupid = $group->new_id;
}