From d737b9ad075a2c0fbaf46188265ee3a7410c9dda Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Sun, 7 Sep 2025 18:44:02 +0200 Subject: [PATCH] MDL-86574 tool_cohortroles: format cohort data during privacy export. --- .../cohortroles/classes/privacy/provider.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/admin/tool/cohortroles/classes/privacy/provider.php b/admin/tool/cohortroles/classes/privacy/provider.php index 9896a620610..e55794c7555 100644 --- a/admin/tool/cohortroles/classes/privacy/provider.php +++ b/admin/tool/cohortroles/classes/privacy/provider.php @@ -166,10 +166,12 @@ class provider implements // Retrieve the tool_cohortroles records created for the user. $sql = "SELECT cr.id as cohortroleid, + cr.cohortid, c.name as cohortname, c.idnumber as cohortidnumber, - c.description as cohortdescription, - c.contextid as contextid, + c.description, + c.descriptionformat, + c.contextid, r.shortname as roleshortname, cr.userid as userid, cr.timecreated as timecreated, @@ -185,27 +187,39 @@ class provider implements $cohortroles = $DB->get_records_sql($sql, $params); foreach ($cohortroles as $cohortrole) { + $context = \context::instance_by_id($cohortrole->contextid); + // The tool_cohortroles data export is organised in: // {User Context}/Cohort roles management/{cohort name}/{role shortname}/data.json. $subcontext = [ get_string('pluginname', 'tool_cohortroles'), - $cohortrole->cohortname, + format_string($cohortrole->cohortname, options: ['context' => $context]), $cohortrole->roleshortname ]; $data = (object) [ - 'cohortname' => $cohortrole->cohortname, + 'cohortname' => format_string($cohortrole->cohortname, options: ['context' => $context]), 'cohortidnumber' => $cohortrole->cohortidnumber, - 'cohortdescription' => $cohortrole->cohortdescription, + 'cohortdescription' => format_text( + writer::with_context($context)->rewrite_pluginfile_urls( + $subcontext, + 'cohort', + 'description', + $cohortrole->cohortid, + $cohortrole->description, + ), + $cohortrole->descriptionformat, + ['context' => $context], + ), 'roleshortname' => $cohortrole->roleshortname, 'userid' => transform::user($cohortrole->userid), 'timecreated' => transform::datetime($cohortrole->timecreated), 'timemodified' => transform::datetime($cohortrole->timemodified) ]; - $context = \context::instance_by_id($cohortrole->contextid); - - writer::with_context($context)->export_data($subcontext, $data); + writer::with_context($context) + ->export_area_files($subcontext, 'cohort', 'description', $cohortrole->cohortid) + ->export_data($subcontext, $data); } }