From bb19f80414b13a5935fcae33d94870e34fb1d0be Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 23 Feb 2017 17:06:44 +0800 Subject: [PATCH] MDL-57730 core_calendar: handle '0' as a courseid User overrides set the course id as 0 in the events table (Moodle can be stupid). We need to deal with this. Part of MDL-55611 epic. --- .../local/event/factories/event_abstract_factory.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/calendar/classes/local/event/factories/event_abstract_factory.php b/calendar/classes/local/event/factories/event_abstract_factory.php index 521bd4c084d..80bf4cf7e6a 100644 --- a/calendar/classes/local/event/factories/event_abstract_factory.php +++ b/calendar/classes/local/event/factories/event_abstract_factory.php @@ -87,12 +87,15 @@ abstract class event_abstract_factory implements event_factory_interface { $module = null; $subscription = null; - if ($dbrow->courseid) { - $course = new std_proxy($dbrow->courseid, function($id) use ($coursecache) { - return \core_calendar\api::get_course_cached($coursecache, $id); - }); + if ($dbrow->courseid == 0) { + $cm = get_coursemodule_from_instance($dbrow->modulename, $dbrow->instance); + $dbrow->courseid = get_course($cm->course)->id; } + $course = new std_proxy($dbrow->courseid, function($id) use ($coursecache) { + return \core_calendar\api::get_course_cached($coursecache, $id); + }); + if ($dbrow->groupid) { $group = new std_proxy($dbrow->groupid, function($id) { return \core_calendar\api::get_group_cached($id);