This commit is contained in:
Sara Arjona 2022-12-05 12:53:36 +01:00
commit 46114474e4

View File

@ -1811,10 +1811,9 @@ abstract class restore_dbops {
public static function calculate_course_names($courseid, $fullname, $shortname) {
global $CFG, $DB;
$currentfullname = '';
$currentshortname = '';
$counter = 0;
// Iteratere while the name exists
// Iterate while fullname or shortname exist.
do {
if ($counter) {
$suffixfull = ' ' . get_string('copyasnoun') . ' ' . $counter;
@ -1823,8 +1822,11 @@ abstract class restore_dbops {
$suffixfull = '';
$suffixshort = '';
}
$currentfullname = $fullname.$suffixfull;
$currentshortname = substr($shortname, 0, 100 - strlen($suffixshort)).$suffixshort; // < 100cc
// Ensure we don't overflow maximum length of name fields, in multi-byte safe manner.
$currentfullname = core_text::substr($fullname, 0, 254 - strlen($suffixfull)) . $suffixfull;
$currentshortname = core_text::substr($shortname, 0, 100 - strlen($suffixshort)) . $suffixshort;
$coursefull = $DB->get_record_select('course', 'fullname = ? AND id != ?',
array($currentfullname, $courseid), '*', IGNORE_MULTIPLE);
$courseshort = $DB->get_record_select('course', 'shortname = ? AND id != ?', array($currentshortname, $courseid));