From d347f30474bea6ae64f79d67e42aaf1091bcd623 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 19 Sep 2012 16:50:18 +0800 Subject: [PATCH] MDL-8307 Course: Requests without a category fallback on the default one --- course/lib.php | 6 +++--- course/pending.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/course/lib.php b/course/lib.php index c4233f4c3bf..f8288e1cabd 100644 --- a/course/lib.php +++ b/course/lib.php @@ -4144,7 +4144,7 @@ class course_request { global $USER, $DB, $CFG; $data->requester = $USER->id; - // Setting the default category is none set. + // Setting the default category if none set. if (empty($data->category) || empty($CFG->requestcategoryselection)) { $data->category = $CFG->defaultrequestcategory; } @@ -4306,10 +4306,10 @@ class course_request { unset($data->reason); unset($data->requester); - // If the current user does not have the rights to change the category, or if the + // If the category is not set, if the current user does not have the rights to change the category, or if the // category does not exist, we set the default category to the course to be approved. // The system level is used because the capability moodle/site:approvecourse is based on a system level. - if (!has_capability('moodle/course:changecategory', context_system::instance()) || + if (empty($data->category) || !has_capability('moodle/course:changecategory', context_system::instance()) || (!$category = get_course_category($data->category))) { $category = get_course_category($CFG->defaultrequestcategory); } diff --git a/course/pending.php b/course/pending.php index 8ac583261f6..3d6cb18c716 100644 --- a/course/pending.php +++ b/course/pending.php @@ -111,11 +111,12 @@ if (empty($pending)) { $course->check_shortname_collision(); // Retreiving category name. - // If the user does not have the capability to change the category, we fallback on the default one. + // If the category was not set (can happen after upgrade) or if the user does not have the capability + // to change the category, we fallback on the default one. // Else, the category proposed is fetched, but we fallback on the default one if we can't find it. // It is just a matter of displaying the right information because the logic when approving the category // proceeds the same way. The system context level is used as moodle/site:approvecourse uses it. - if (!has_capability('moodle/course:changecategory', context_system::instance()) || + if (empty($course->category) || !has_capability('moodle/course:changecategory', context_system::instance()) || (!$category = get_course_category($course->category))) { $category = get_course_category($CFG->defaultrequestcategory); }