Skip to content

Commit

Permalink
MDL-64291 GDPR export: Context paths can be very long, not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Binh Thai authored and Kiet.Chan committed Jan 28, 2019
1 parent cc8d7ee commit be3cc9b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions privacy/classes/local/request/moodle_content_writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
* @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.
*/
Expand Down Expand Up @@ -254,15 +259,17 @@ public function export_user_preference(string $component, string $key, string $v
/**
* 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;
Expand Down

0 comments on commit be3cc9b

Please sign in to comment.