Skip to content

Commit

Permalink
MDL-69751 course: Handle missing guest user context
Browse files Browse the repository at this point in the history
Makes sure the guest user context exists when fetching
the recommended modules. If the context does not exist
an exception is being thrown describing the problem.
  • Loading branch information
Mihail Geshoski committed Oct 20, 2020
1 parent 149fdcf commit 2939eff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion course/classes/local/service/content_item_service.php
Expand Up @@ -110,7 +110,12 @@ private function get_recommendations(): array {
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));
// Make sure the guest user context exists.
if (!$guestusercontext = \context_user::instance($CFG->siteguest, false)) {
throw new \coding_exception('The guest user context does not exist.');
}

$favourites = $this->get_content_favourites(self::RECOMMENDATION_PREFIX, $guestusercontext);

$recommendationcache->set($CFG->siteguest, $favourites);
return $favourites;
Expand Down

0 comments on commit 2939eff

Please sign in to comment.