MDL-62666 course: Only set the groups setting to true when necessary
authorJun Pataleta <jun@moodle.com>
Mon, 21 Jan 2019 05:56:23 +0000 (13:56 +0800)
committerJun Pataleta <jun@moodle.com>
Mon, 21 Jan 2019 05:56:23 +0000 (13:56 +0800)
* Plus update the comment to be more descriptive.

course/lib.php

index 6ad7429..d0cb0b3 100644 (file)
@@ -3420,10 +3420,12 @@ function duplicate_module($course, $cm) {
     $rc = new restore_controller($backupid, $course->id,
             backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
 
-    // Configure the plan.
+    // Make sure that the restore_general_groups setting is always enabled when duplicating an activity.
     $plan = $rc->get_plan();
     $groupsetting = $plan->get_setting('groups');
-    $groupsetting->set_value(true);
+    if (empty($groupsetting->get_value())) {
+        $groupsetting->set_value(true);
+    }
 
     $cmcontext = context_module::instance($cm->id);
     if (!$rc->execute_precheck()) {