From 89dc9538c013b3f22cf48422a1c600bca9eb2537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Trouv=C3=A9?= Date: Fri, 20 Oct 2023 09:41:53 +0200 Subject: [PATCH] Prevent export crash due to missing user context After user data removal by tool_dataprivacy `tool_dataprivacy\task\expired_retention_period` is used to remove user contexts When exporting appointments with custom profile field selected this lead to a crash. This is due to profile field visibility check using `profile_field_base::is_visible()` which is calling `context_user::instance()` with default strictness (`MUST_EXIST`)...leading to an exception when the context is removed. --- exportlib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exportlib.php b/exportlib.php index 3bc98af1..0a2b3341 100644 --- a/exportlib.php +++ b/exportlib.php @@ -659,7 +659,8 @@ public function get_header(scheduler $scheduler) { * @return string the value of this field for the given data */ public function get_value(slot $slot, $appointment) { - if (!$appointment instanceof appointment || $appointment->studentid == 0) { + if (!$appointment instanceof appointment || $appointment->studentid == 0 + || !context_user::instance($appointment->studentid, IGNORE_MISSING)) { return ''; } $this->field->set_userid($appointment->studentid);