Skip to content
Browse files

MDL-39359 - mod/assign: Allow zipped folder to be uploaded for return…

…ing feedback files

The "Upload multiple feedback files in a zip" feature is convenient, but requires that
the files sit directly within the zip file. As the files will most likely be extracted
to a folder after downloading, it's quite reasonable to expect teachers to zip the
folder up rather than selecting all files and zipping them.  This patch allows for a
zipped folder to be uploaded; if the only file found after extracting is a directory,
the contents of the directory are used instead of the results of the extraction.
  • Loading branch information...
1 parent ffc3f53 commit 381e6d735954815ee8fa9b28b133a63d2ea02b00 @pauln pauln committed
Showing with 13 additions and 6 deletions.
  1. +13 −6 mod/assign/feedback/file/importziplib.php
View
19 mod/assign/feedback/file/importziplib.php
@@ -194,6 +194,17 @@ public function get_import_files($contextid) {
$USER->id,
'/import/');
+ $keys = array_keys($files);
+ if (count($files) == 1 && $files[$keys[0]]->is_directory()) {
+ // An entire folder was zipped, rather than its contents.
+ // We need to return the contents of the folder instead, so the import can continue.
+ $files = $fs->get_directory_files($contextid,
+ 'assignfeedback_file',
+ ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
+ $USER->id,
+ $files[$keys[0]]->get_filepath());
+ }
+
return $files;
}
@@ -205,7 +216,7 @@ public function get_import_files($contextid) {
* @return string - The html response
*/
public function import_zip_files($assignment, $fileplugin) {
- global $USER, $CFG, $PAGE, $DB;
+ global $CFG, $PAGE, $DB;
@set_time_limit(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME);
$packer = get_file_packer('application/zip');
@@ -216,11 +227,7 @@ public function import_zip_files($assignment, $fileplugin) {
$contextid = $assignment->get_context()->id;
$fs = get_file_storage();
- $files = $fs->get_directory_files($contextid,
- 'assignfeedback_file',
- ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
- $USER->id,
- '/import/');
+ $files = $this->get_import_files($contextid);
$currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
$allusers = $assignment->list_participants($currentgroup, false);

0 comments on commit 381e6d7

Please sign in to comment.
Something went wrong with that request. Please try again.