From 8ca8c92f3cc4b10e20855167e803785a1ca69a4b Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 8 Aug 2023 16:24:08 +0100 Subject: [PATCH] MDL-78397 course: update module name using API after duplicating. This ensures that various ancillary tasks are also performed (such as ensuring the gradebook item name matches). --- course/lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/course/lib.php b/course/lib.php index 2fe83a0eaf2..3503809430e 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3564,10 +3564,9 @@ function duplicate_module($course, $cm, int $sectionid = null, bool $changename // triggering a lot of create/update duplicated events. $newcm = get_coursemodule_from_id($cm->modname, $newcmid, $cm->course); if ($changename) { - // Add ' (copy)' to duplicates. Note we don't cleanup or validate lengths here. It comes - // from original name that was valid, so the copy should be too. + // Add ' (copy)' language string postfix to duplicated module. $newname = get_string('duplicatedmodule', 'moodle', $newcm->name); - $DB->set_field($cm->modname, 'name', $newname, ['id' => $newcm->instance]); + set_coursemodule_name($newcm->id, $newname); } $section = $DB->get_record('course_sections', ['id' => $sectionid ?? $cm->section, 'course' => $cm->course]);