Skip to content

Commit

Permalink
MDL-78388 course: Copy locally assigned roles to new course module wh…
Browse files Browse the repository at this point in the history
…en duplicating
  • Loading branch information
djarran committed May 22, 2024
1 parent 5da5715 commit 35ade50
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 35ade50

Please sign in to comment.