MDL-69079 course: Handle missing guest when fetching recommended modules
authorMihail Geshoski <mihail@moodle.com>
Wed, 15 Jul 2020 15:54:00 +0000 (23:54 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 24 Jul 2020 02:33:50 +0000 (10:33 +0800)
course/classes/local/service/content_item_service.php

index b1dfddd..20209ae 100644 (file)
@@ -105,6 +105,11 @@ class content_item_service {
             return $favmods;
         }
 
+        // Make sure the guest user exists in the database.
+        if (!\core_user::get_user($CFG->siteguest)) {
+            throw new \coding_exception('The guest user does not exist in the database.');
+        }
+
         $favourites = $this->get_content_favourites(self::RECOMMENDATION_PREFIX, \context_user::instance($CFG->siteguest));
 
         $recommendationcache->set($CFG->siteguest, $favourites);