From 7289f5c0c1912c370486cbf6ac485b869cb6a3a4 Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Tue, 18 Dec 2018 11:16:03 +0000 Subject: [PATCH] MDL-64427 category: Stop error when another user deleting courses If you try to visit a category where another user is deleting a course the coursecat cache may not be fresh. This is because there is a breif time where the course record will have been deleted, while it is deleting other course information, before the event that triggers the coursecat cache to be purged is fired. --- course/classes/category.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/course/classes/category.php b/course/classes/category.php index 5812abdf133..15eb32a60d8 100644 --- a/course/classes/category.php +++ b/course/classes/category.php @@ -1582,7 +1582,10 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr } // Prepare the list of core_course_list_element objects. foreach ($ids as $id) { - $courses[$id] = new core_course_list_element($records[$id]); + // If a course is deleted after we got the cache entry it may not exist in the database anymore. + if (!empty($records[$id])) { + $courses[$id] = new core_course_list_element($records[$id]); + } } } return $courses; @@ -1792,7 +1795,10 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr } // Prepare the list of core_course_list_element objects. foreach ($ids as $id) { - $courses[$id] = new core_course_list_element($records[$id]); + // If a course is deleted after we got the cache entry it may not exist in the database anymore. + if (!empty($records[$id])) { + $courses[$id] = new core_course_list_element($records[$id]); + } } } return $courses;