From 35ade507e965899bbedf7e2d16c6b5beaf269891 Mon Sep 17 00:00:00 2001 From: djarrancotleanu Date: Wed, 22 May 2024 10:37:12 +1000 Subject: [PATCH] MDL-78388 course: Copy locally assigned roles to new course module when duplicating --- course/lib.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/course/lib.php b/course/lib.php index b7e153a76a389..a3747614cf579 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);