From c0d4b3ba08eabfb08f79357e6aa1cd785707bf74 Mon Sep 17 00:00:00 2001 From: Binh Thai Date: Thu, 17 Jan 2019 09:18:20 +0700 Subject: [PATCH] MDL-64291 GDPR export: Context paths can be very long, not unique --- .../local/request/moodle_content_writer.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/privacy/classes/local/request/moodle_content_writer.php b/privacy/classes/local/request/moodle_content_writer.php index 637c0bbf495..ab0588d1773 100644 --- a/privacy/classes/local/request/moodle_content_writer.php +++ b/privacy/classes/local/request/moodle_content_writer.php @@ -37,6 +37,11 @@ defined('MOODLE_INTERNAL') || die(); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class moodle_content_writer implements content_writer { + /** + * Maximum context name char size. + */ + const MAX_CONTEXT_NAME_LENGTH = 32; + /** * @var string The base path on disk for this instance. */ @@ -254,15 +259,17 @@ class moodle_content_writer implements content_writer { /** * Determine the path for the current context. * - * @return array The context path. + * @return array The context path. + * @throws \coding_exception */ - protected function get_context_path() : Array { + protected function get_context_path() : array { $path = []; $contexts = array_reverse($this->context->get_parent_contexts(true)); foreach ($contexts as $context) { $name = $context->get_context_name(); - $id = '_.' . $context->id; - $path[] = shorten_filename(clean_param("{$name} {$id}", PARAM_FILE), MAX_FILENAME_SIZE, true); + $id = ' _.' . $context->id; + $path[] = shorten_text(clean_param($name, PARAM_FILE), + self::MAX_CONTEXT_NAME_LENGTH, true, json_decode('"' . '\u2026' . '"')) . $id; } return $path;