]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes bug MDL-2674, "backup always backsup/restores groups regardless of user setting...
authornfreear <nfreear>
Mon, 10 Dec 2007 10:26:47 +0000 (10:26 +0000)
committernfreear <nfreear>
Mon, 10 Dec 2007 10:26:47 +0000 (10:26 +0000)
backup/restore_check.html
backup/restore_form.html
backup/restorelib.php
lang/en_utf8/group.php
lang/en_utf8/help/grouprestore.html [new file with mode: 0644]
lang/en_utf8/moodle.php
mod/chat/restorelib.php
mod/data/restorelib.php
mod/forum/restorelib.php
mod/wiki/restorelib.php

index ad699f6634c16fb3bd2420fdcbfd23226d2c50a2..480f924e6294e6bab7989aea2554a6782d094a2e 100644 (file)
@@ -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
         $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;
index 5ce61926cf9481f414c011d7d47ed7d32e07b8ca..128321bb019bc0093e3c17b0c4a516deede3a86c 100644 (file)
         $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>";
index 4f20ed3198921f9d7363ff5b46ba55d5d0f36357..91683ada9a08ce74fcb2d4e1c59764465aef9c00 100644 (file)
@@ -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);
         }
     }
-?>
+?>
\ No newline at end of file
index cd547073badbd859da877f61c51b2c52ff02ec14..089fe2c1d7d56151904947ba4b63f7122198274d 100644 (file)
@@ -133,4 +133,7 @@ $string['removegroupingsmembers'] = 'Remove all groups from groupings';
 $string['deleteallgroups'] = 'Delete all groups';
 $string['deleteallgroupings'] = 'Delete all groupings';
 
-?>
+$string['groupsgroupings'] = 'Groups &amp; 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 (file)
index 0000000..dca2d62
--- /dev/null
@@ -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 &amp; 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>
index 3a752077cda9aa09e29973a22abfa4c4e37081a2..2e4b88630af3dc12212e2cfaafff1dfd82f0c095 100644 (file)
@@ -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
index 67fe78451b848cf6e085edb7cbb970b5dd0b4e67..883ff4289b9693d6cfb7e7d8f747b3d0ec7075f1 100644 (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;
             }
index fcd95220bac01dd4ac1c89695d8488a00268f1ef..a0ae7dafd8b79261e2e1fb59e8948dfada19ebf0 100644 (file)
@@ -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
index 61101a3e7b6808f89aedd84c749680d60763b02a..13f0bb5e5e12da319435bbfa6feb24df7d1e216b 100644 (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;
             }
index a696be04ac11ff239f2c2de733f9deea9cac65c0..c4b269e464002a94d089a2d3a84e8b1976957382 100644 (file)
             $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;
             }