From 385ce8a5e11c34c2e5a4e5eb22a396aa52f760a2 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 12 Apr 2021 20:30:43 +0100 Subject: [PATCH] MDL-71313 repositories: warn if get_instances context is wrong type --- repository/lib.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/repository/lib.php b/repository/lib.php index 08f3c250d01..44f4432c79e 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1012,10 +1012,17 @@ abstract class repository implements cacheable_object { global $DB, $CFG, $USER; // Fill $args attributes with default values unless specified - if (!isset($args['currentcontext']) || !($args['currentcontext'] instanceof context)) { - $current_context = context_system::instance(); + if (isset($args['currentcontext'])) { + if ($args['currentcontext'] instanceof context) { + $current_context = $args['currentcontext']; + } else { + debugging('currentcontext passed to repository::get_instances was ' . + 'not a context object. Using system context instead, but ' . + 'you should probably fix your code.', DEBUG_DEVELOPER); + $current_context = context_system::instance(); + } } else { - $current_context = $args['currentcontext']; + $current_context = context_system::instance(); } $args['currentcontext'] = $current_context->id; $contextids = array();