From 762681f5c464acdc2115a5e783ad9f06b96f6f68 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Thu, 29 Aug 2024 07:36:03 +0200 Subject: [PATCH] MDL-82932 mod_data: Fix export with userdata of deleted users --- mod/data/classes/local/exporter/utils.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mod/data/classes/local/exporter/utils.php b/mod/data/classes/local/exporter/utils.php index d042c21722a3e..cde366a82714e 100644 --- a/mod/data/classes/local/exporter/utils.php +++ b/mod/data/classes/local/exporter/utils.php @@ -123,9 +123,10 @@ public static function data_exportdata(int $dataid, array $fields, array $select } if ($userdetails) { // Add user details to the export data. $userdata = get_complete_user_data('id', $record->userid); - $exporter->add_to_current_row(fullname($userdata)); - $exporter->add_to_current_row($userdata->username); - $exporter->add_to_current_row($userdata->email); + // In case of an already deleted user, we do not receive any userdata and export an empty string instead. + $exporter->add_to_current_row($userdata ? fullname($userdata) : ''); + $exporter->add_to_current_row($userdata ? $userdata->username : ''); + $exporter->add_to_current_row($userdata ? $userdata->email : ''); } if ($time) { // Add time added / modified. $exporter->add_to_current_row(userdate($record->timecreated));