From b0dc3e563db188e162ae6956808c67c23428e67a Mon Sep 17 00:00:00 2001 From: nfreear Date: Mon, 10 Dec 2007 10:26:47 +0000 Subject: [PATCH] Fixes bug MDL-2674, "backup always backsup/restores groups regardless of user settings" - restore group/grouping option. --- backup/restore_check.html | 3 ++ backup/restore_form.html | 31 ++++++++++++++ backup/restorelib.php | 65 ++++++++++++++++++++++++++--- lang/en_utf8/group.php | 5 ++- lang/en_utf8/help/grouprestore.html | 33 +++++++++++++++ lang/en_utf8/moodle.php | 3 +- mod/chat/restorelib.php | 3 +- mod/data/restorelib.php | 4 +- mod/forum/restorelib.php | 3 +- mod/wiki/restorelib.php | 3 +- 10 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 lang/en_utf8/help/grouprestore.html diff --git a/backup/restore_check.html b/backup/restore_check.html index ad699f6634..480f924e62 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -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; diff --git a/backup/restore_form.html b/backup/restore_form.html index 5ce61926cf..128321bb01 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -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 ""; + //Now print the Groups tr (assume there is no $info->backup_groups) + echo ""; + echo ""; + $helplink = helpbutton('grouprestore', get_string('groups'), '', true, false, '', true); + if (empty($CFG->enablegroupings)) { + echo get_string('groups').$helplink.":"; + echo ""; + $group_options[RESTORE_GROUPS_NONE] = get_string('no'); + $group_options[RESTORE_GROUPS_ONLY] = get_string('yes'); + } else { + echo get_string('groupsgroupings', 'group').$helplink.":"; + echo ""; + $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 ""; + }*/ + choose_from_menu($group_options, 'restore_groups', $restore_groups, ''); + echo ""; + //Now print the Logs tr echo ""; echo ""; diff --git a/backup/restorelib.php b/backup/restorelib.php index 4f20ed3198..91683ada9a 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1,6 +1,26 @@ Updating config for block ', $instance->id, '.

'; $tab[$elem][0] = "".get_string("users").":"; $tab[$elem][1] = get_string($info->backup_users); $elem++; + //Groups info + if (empty($CFG->enablegroupings)) { + $tab[$elem][0] = "".get_string('groups').":"; + } else { + $tab[$elem][0] = "".get_string('groupsgroupings','group').":"; + } + 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] = "".get_string("logs").":"; if ($info->backup_logs == "true") { @@ -1038,7 +1069,8 @@ echo '

Updating config for block ', $instance->id, '.

'; $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 '

Updating config for block ', $instance->id, '.

'; 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 '

Updating config for block ', $instance->id, '.

'; $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 '

Updating config for block ', $instance->id, '.

'; //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 "
  • ".get_string("creatinggroups"); } @@ -6940,7 +6993,7 @@ echo '

    Updating config for block ', $instance->id, '.

    '; } //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 "
  • ".get_string("creatinggroupings"); } @@ -6958,7 +7011,7 @@ echo '

    Updating config for block ', $instance->id, '.

    '; } //Now create groupingsgroups as needed - if ($status) { + if ($status and $restore->groups == RESTORE_GROUPS_GROUPINGS) { if (!defined('RESTORE_SILENTLY')) { echo "
  • ".get_string("creatinggroupingsgroups"); } @@ -7909,4 +7962,4 @@ echo '

    Updating config for block ', $instance->id, '.

    '; fclose($restorelog); } } -?> +?> \ No newline at end of file diff --git a/lang/en_utf8/group.php b/lang/en_utf8/group.php index cd547073ba..089fe2c1d7 100644 --- a/lang/en_utf8/group.php +++ b/lang/en_utf8/group.php @@ -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'; + +?> \ No newline at end of file diff --git a/lang/en_utf8/help/grouprestore.html b/lang/en_utf8/help/grouprestore.html new file mode 100644 index 0000000000..dca2d62721 --- /dev/null +++ b/lang/en_utf8/help/grouprestore.html @@ -0,0 +1,33 @@ +

    Restoring Groups

    + +

    You can now choose whether you want to restore groupsenablegroupings)) { + echo '. '; +} else { + echo ', and groupings. '; +} +?> +The options are:

    + +
    +enablegroupings)) { ?> +
    No
    +
    Do not restore groups.
    +
    Yes
    +
    Restore groups.
    + +
    None
    +
    Do not restore groups or groupings. The grouping for grouping activities is reset to 'None'.
    +
    Groupings only
    +
    Groupings are restored, empty. The grouping selected for grouping activities + is maintained, and groups are not restored.
    +
    Groups & groupings
    +
    Groups and groupings are restored, and all related settings are maintained.
    + +
    + +

    Group mode for course and activities

    +

    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. +

    diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 3a752077cd..2e4b88630a 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -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'; -?> +?> \ No newline at end of file diff --git a/mod/chat/restorelib.php b/mod/chat/restorelib.php index 67fe78451b..883ff4289b 100644 --- a/mod/chat/restorelib.php +++ b/mod/chat/restorelib.php @@ -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; } diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php index fcd95220ba..a0ae7dafd8 100644 --- a/mod/data/restorelib.php +++ b/mod/data/restorelib.php @@ -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; } -?> +?> \ No newline at end of file diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index 61101a3e7b..13f0bb5e5e 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -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; } diff --git a/mod/wiki/restorelib.php b/mod/wiki/restorelib.php index a696be04ac..c4b269e464 100644 --- a/mod/wiki/restorelib.php +++ b/mod/wiki/restorelib.php @@ -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; } -- 2.39.5