diff --git a/lang/en/repository.php b/lang/en/repository.php index 7ed41e6ffff5b..78a323404b7d6 100644 --- a/lang/en/repository.php +++ b/lang/en/repository.php @@ -99,8 +99,6 @@ $string['download'] = 'Download'; $string['downloadallfiles'] = 'Download all files'; $string['downloadfolder'] = 'Download all'; -$string['downloadselected'] = 'Download selected files'; -$string['deleteselected'] = 'Delete selected'; $string['downloadsucc'] = 'The file has been downloaded successfully'; $string['draftareanofiles'] = 'Cannot be downloaded because there is no files attached'; $string['editrepositoryinstance'] = 'Edit repository instance'; diff --git a/lib/templates/filemanager_page_generallayout.mustache b/lib/templates/filemanager_page_generallayout.mustache index 7300170a584d6..8d6a6154f4a15 100644 --- a/lib/templates/filemanager_page_generallayout.mustache +++ b/lib/templates/filemanager_page_generallayout.mustache @@ -45,12 +45,12 @@
diff --git a/repository/draftfiles_ajax.php b/repository/draftfiles_ajax.php index 328f2d230d61f..d00d068a75a4f 100644 --- a/repository/draftfiles_ajax.php +++ b/repository/draftfiles_ajax.php @@ -175,6 +175,13 @@ case 'downloadselected': $selected = required_param('selected', PARAM_RAW); $selectedfiles = json_decode($selected); + if (!count($selectedfiles)) { + $filepath = required_param('filepath', PARAM_PATH); + $selectedfiles = [(object)[ + 'filename' => '', + 'filepath' => $filepath + ]]; + } $return = repository_download_selected_files($usercontext, 'user', 'draft', $draftid, $selectedfiles); echo (json_encode($return)); die; diff --git a/repository/lib.php b/repository/lib.php index b5296d6ce9855..dd3fa48a73872 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -3272,7 +3272,7 @@ function repository_download_selected_files($context, string $component, string $filestoarchive = []; foreach ($files as $selectedfile) { - $filename = clean_filename($selectedfile->filename); // Default to '.' for root. + $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); @@ -3284,7 +3284,9 @@ function repository_download_selected_files($context, string $component, string // If it is empty we are downloading a directory. $archivefile = $storedfile->get_filename(); if (!$filename || $filename == '.' ) { - $archivefile = $filepath; + $foldername = explode('/', trim($filepath, '/')); + $folder = trim(array_pop($foldername), '/'); + $archivefile = $folder ?? '/'; } $filestoarchive[$archivefile] = $storedfile; diff --git a/repository/tests/behat/delete_files.feature b/repository/tests/behat/delete_files.feature index 7cbedaea09db1..d4ed7517c20ee 100644 --- a/repository/tests/behat/delete_files.feature +++ b/repository/tests/behat/delete_files.feature @@ -30,7 +30,7 @@ Feature: Delete files and folders from the file manager And I follow "Manage private files" And I click on "Display folder with file details" "link" And I set the field "Select file 'empty.txt'" to "1" - When I click on "Delete selected" "link" + When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 1 file(s)?" When I click on "OK" "button" in the "Confirm" "dialogue" Then I should not see "empty.txt" @@ -40,7 +40,7 @@ Feature: Delete files and folders from the file manager Then I should not see "empty.txt" But I should see "Delete me later" And I set the field "Select file 'Delete me later'" to "1" - And I click on "Delete selected" "link" + And I click on "Delete" "link" And I click on "OK" "button" in the "Confirm" "dialogue" Then I should not see "Delete me later" When I press "Save changes" @@ -58,7 +58,7 @@ Feature: Delete files and folders from the file manager And I click on "Display folder with file details" "link" And I set the field "Select file 'empty.txt'" to "1" And I set the field "Select file 'Delete me'" to "1" - When I click on "Delete selected" "link" + When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 2 file(s)?" When I click on "OK" "button" in the "Confirm" "dialogue" Then I should not see "Delete me" @@ -84,7 +84,7 @@ Feature: Delete files and folders from the file manager | Select file 'empty.txt' | 1 | | Select file 'Delete me' | 1 | | Select file 'Delete me too' | 1 | - When I click on "Delete selected" "link" + When I click on "Delete" "link" Then I should see "Are you sure you want to delete the selected 3 file(s)?" When I click on "OK" "button" in the "Confirm" "dialogue" Then I should not see "Delete me"