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.
This commit is contained in:
Neill Magill
2020-05-20 08:27:52 +01:00
parent 236a52c4de
commit 7289f5c0c1
+8 -2
View File
@@ -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;