MDL-77838 repository: preserve empty dirs in download if selected.

This commit is contained in:
Paul Holden
2024-03-22 16:23:08 +00:00
parent 23b110b28b
commit f512681b3b
+5 -9
View File
@@ -3267,7 +3267,7 @@ function repository_delete_selected_files($context, string $component, string $f
* @param string $filearea filearea
* @param int $itemid the item id
* @param array $files Array of files object with each item having filename/filepath as values
* @return array $return Array of strings matching up to the parent directory of the deleted files
* @return false|stdClass $return Object containing URL of zip archive and a file path
* @throws coding_exception
*/
function repository_download_selected_files($context, string $component, string $filearea, $itemid, array $files) {
@@ -3284,10 +3284,6 @@ function repository_download_selected_files($context, string $component, string
$filename = $selectedfile->filename ? clean_filename($selectedfile->filename) : '.'; // Default to '.' for root.
$filepath = clean_param($selectedfile->filepath, PARAM_PATH); // Default to '/' for downloadall.
$filepath = file_correct_filepath($filepath);
$area = file_get_draft_area_info($itemid, $filepath);
if ($area['filecount'] == 0 && $area['foldercount'] == 0) {
continue;
}
$storedfile = $fs->get_file($context->id, $component, $filearea, $itemid, $filepath, $filename);
// If it is empty we are downloading a directory.
@@ -3301,16 +3297,16 @@ function repository_download_selected_files($context, string $component, string
$filestoarchive[$archivefile] = $storedfile;
}
$zippedfile = get_string('files') . '.zip';
if ($newfile =
$zipper->archive_to_storage(
if ($zipper->archive_to_storage(
$filestoarchive,
$context->id,
$component,
$filearea,
$newdraftitemid,
"/",
$zippedfile, $USER->id)
) {
$zippedfile,
$USER->id,
)) {
$return = new stdClass();
$return->fileurl = moodle_url::make_draftfile_url($newdraftitemid, '/', $zippedfile)->out();
$return->filepath = $filepath;