MDL-64291 GDPR export: Context paths can be very long, not unique

This commit is contained in:
Binh Thai 2019-01-17 09:18:20 +07:00 committed by Kiet.Chan
parent 0e1e1e5586
commit 658bf9d554

View File

@ -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;