From f512681b3bd3a67efebccfc1478ee0b8b7273e38 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 22 Mar 2024 16:17:13 +0000 Subject: [PATCH] MDL-77838 repository: preserve empty dirs in download if selected. --- repository/lib.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/repository/lib.php b/repository/lib.php index f00d8fd472eb6..996aff8ae5104 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -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;