Skip to content

Commit

Permalink
fix for unexpected cleanup of course fullname
Browse files Browse the repository at this point in the history
  • Loading branch information
semteacher committed Jul 15, 2024
1 parent d1991b5 commit a6797b2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions classes/local/connectedcourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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
Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit a6797b2

Please sign in to comment.