Fixes bug MDL-2674, "backup always backsup/restores groups regardless of user settings" - restore group/grouping option.
This commit is contained in:
@@ -84,6 +84,8 @@
|
||||
$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
|
||||
@@ -126,6 +128,7 @@
|
||||
$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;
|
||||
|
||||
@@ -77,6 +77,14 @@
|
||||
$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;
|
||||
}
|
||||
@@ -411,6 +419,29 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
|
||||
}
|
||||
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>";
|
||||
|
||||
+59
-6
@@ -1,6 +1,26 @@
|
||||
<?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) {
|
||||
@@ -459,6 +479,17 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
$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") {
|
||||
@@ -1038,7 +1069,8 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
$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;
|
||||
@@ -2839,6 +2871,20 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
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) {
|
||||
|
||||
@@ -3017,7 +3063,14 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
$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']['#']);
|
||||
@@ -6922,7 +6975,7 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
|
||||
|
||||
//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");
|
||||
}
|
||||
@@ -6940,7 +6993,7 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
}
|
||||
|
||||
//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");
|
||||
}
|
||||
@@ -6958,7 +7011,7 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
}
|
||||
|
||||
//Now create groupingsgroups as needed
|
||||
if ($status) {
|
||||
if ($status and $restore->groups == RESTORE_GROUPS_GROUPINGS) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo "<li>".get_string("creatinggroupingsgroups");
|
||||
}
|
||||
@@ -7909,4 +7962,4 @@ echo '<p>Updating config for block ', $instance->id, '.</p>';
|
||||
fclose($restorelog);
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@@ -133,4 +133,7 @@ $string['removegroupingsmembers'] = 'Remove all groups from groupings';
|
||||
$string['deleteallgroups'] = 'Delete all groups';
|
||||
$string['deleteallgroupings'] = 'Delete all groupings';
|
||||
|
||||
?>
|
||||
$string['groupsgroupings'] = 'Groups & groupings';
|
||||
$string['groupingsonly'] = 'Groupings only';
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<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>
|
||||
@@ -1603,6 +1603,7 @@ $string['writinggeneralinfo'] = 'Writing general info';
|
||||
$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';
|
||||
@@ -1625,4 +1626,4 @@ $string['zippingbackup'] = 'Zipping backup';
|
||||
|
||||
$string['authenticationplugins'] = 'Authentication Plugins';
|
||||
$string['chooseauthmethod'] = 'Choose authentication plugin';
|
||||
?>
|
||||
?>
|
||||
@@ -102,6 +102,7 @@
|
||||
$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']['#']);
|
||||
@@ -116,7 +117,7 @@
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ function data_records_restore_mods ($old_data_id, $new_data_id, $info, $restore)
|
||||
$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;
|
||||
@@ -725,4 +725,4 @@ function data_decode_content_links_caller($restore) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
@@ -272,6 +272,7 @@
|
||||
$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']['#']);
|
||||
@@ -293,7 +294,7 @@
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
$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']['#']);
|
||||
@@ -121,7 +122,7 @@
|
||||
$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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user