diff --git a/lib/datalib.php b/lib/datalib.php index ad752202203..cb3d92660df 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1039,11 +1039,20 @@ function fix_course_sortorder() { HAVING cc.coursecount <> COUNT(c.id)"; if ($updatecounts = $DB->get_records_sql($sql)) { + // categories with more courses than MAX_COURSES_IN_CATEGORY + $categories = array(); foreach ($updatecounts as $cat) { $cat->coursecount = $cat->newcount; + if ($cat->coursecount >= MAX_COURSES_IN_CATEGORY) { + $categories[] = $cat->id; + } unset($cat->newcount); $DB->update_record_raw('course_categories', $cat, true); } + if (!empty($categories)) { + $str = implode(', ', $categories); + debugging("The number of courses (category id: $str) has reached MAX_COURSES_IN_CATEGORY (" . MAX_COURSES_IN_CATEGORY . "), it will cause a sorting performance issue, please increase the value of MAX_COURSES_IN_CATEGORY in lib/datalib.php file. See tracker issue: MDL-25669", DEBUG_DEVELOPER); + } } // now make sure that sortorders in course table are withing the category sortorder ranges