From 3b75d14315a4576cfb7c4bcfee0fd06ffbc588df Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 8 Aug 2019 09:08:08 +0100 Subject: [PATCH] MDL-66336 courses: Show an error when no course categories are visible --- course/management.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/course/management.php b/course/management.php index 27784d152af..492a9f10718 100644 --- a/course/management.php +++ b/course/management.php @@ -69,8 +69,11 @@ if ($courseid) { $course = null; $courseid = null; $topchildren = core_course_category::top()->get_children(); + if (empty($topchildren)) { + throw new moodle_exception('cannotviewcategory', 'error'); + } $category = reset($topchildren); - $categoryid = $category ? $category->id : 0; + $categoryid = $category->id; $context = context_coursecat::instance($category->id); $url->param('categoryid', $category->id); }