From a6797b21d1e8ed9b66fb87156ea86c6a9cd68c84 Mon Sep 17 00:00:00 2001 From: Andrii Semenets Date: Mon, 15 Jul 2024 11:32:45 +0300 Subject: [PATCH] fix for unexpected cleanup of course fullname --- classes/local/connectedcourse.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/classes/local/connectedcourse.php b/classes/local/connectedcourse.php index ccc9f1546..9517873b3 100644 --- a/classes/local/connectedcourse.php +++ b/classes/local/connectedcourse.php @@ -65,13 +65,14 @@ public static function create_course_from_template_course(stdClass &$newoption, $fullnamewithprefix .= $formdata->titleprefix . ' - '; } - $fullname = $settings->text ?? $fullnamewithprefix; + // phpcs:ignore + //$fullname = $settings->text ?? $fullnamewithprefix; // Preserved upon decision. - $fullnamewithprefix .= self::clean_text($formdata->text); + $fullnamewithprefix .= trim($formdata->text); // Courses need to have unique shortnames. $i = 1; - $shortname = !empty($fullnamewithprefix) ? $fullnamewithprefix : 'newshortname'; + $shortname = !empty(self::clean_text($fullnamewithprefix)) ? self::clean_text($fullnamewithprefix) : 'newshortname'; while ($DB->get_record('course', ['shortname' => $shortname])) { $shortname = $fullnamewithprefix . '_' . $i; $i++; @@ -81,7 +82,7 @@ public static function create_course_from_template_course(stdClass &$newoption, $courseinfo = core_course_external::duplicate_course( $origincourseid, - $fullname, + $fullnamewithprefix, $shortname, $categoryid, 1 @@ -204,11 +205,11 @@ private static function create_new_course_in_category(stdClass &$newoption, stdC if (!empty($formdata->titleprefix)) { $fullnamewithprefix .= $formdata->titleprefix . ' - '; } - $fullnamewithprefix .= self::clean_text($formdata->text); + $fullnamewithprefix .= trim($formdata->text); // Courses need to have unique shortnames. $i = 1; - $shortname = !empty($fullnamewithprefix) ? $fullnamewithprefix : 'newshortname'; + $shortname = !empty(self::clean_text($fullnamewithprefix)) ? self::clean_text($fullnamewithprefix) : 'newshortname'; while ($DB->get_record('course', ['shortname' => $shortname])) { $shortname = $fullnamewithprefix . '_' . $i; $i++;