diff --git a/course/lib.php b/course/lib.php index b7e153a76a38..a3747614cf57 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3251,6 +3251,14 @@ function duplicate_module($course, $cm, int $sectionid = null, bool $changename $DB->insert_record('role_capabilities', $override); } + // Copy locally assigned roles to new course module. + $overrides = $DB->get_records('role_assignments', ['contextid' => $cmcontext->id]); + foreach ($overrides as $override) { + $override->contextid = $newcmcontext->id; + unset($override->id); + $DB->insert_record('role_assignments', $override); + } + // Trigger course module created event. We can trigger the event only if we know the newcmid. $newcm = get_fast_modinfo($cm->course)->get_cm($newcmid); $event = \core\event\course_module_created::create_from_cm($newcm);