MDL-62240 privacy: Avoid error when path is higher than allowed

A new method shorten_filenames has been added to moodlelib.
This commit is contained in:
Sara Arjona
2018-05-03 09:17:56 +02:00
parent 61140b097b
commit 9543ced2b4
4 changed files with 299 additions and 1 deletions
+19
View File
@@ -8286,6 +8286,25 @@ function shorten_filename($filename, $length = MAX_FILENAME_SIZE, $includehash =
return $shortened;
}
/**
* Shortens a given array of filenames by removing characters positioned after the ideal string length.
*
* @param array $path The paths to reduce the length.
* @param int $length Ideal string length
* @param bool $includehash Whether to include a file hash in the shortened version. This ensures uniqueness.
* @return array $result Shortened paths in array.
*/
function shorten_filenames(array $path, $length = MAX_FILENAME_SIZE, $includehash = false) {
$result = null;
$result = array_reduce($path, function($carry, $singlepath) use ($length, $includehash) {
$carry[] = shorten_filename($singlepath, $length, $includehash);
return $carry;
}, []);
return $result;
}
/**
* Given dates in seconds, how many weeks is the date from startdate
* The first week is 1, the second 2 etc ...