MDL-49025 assign: Submissions of an empty directory should not save
authorNeill Magill <neill.magill@nottingham.ac.uk>
Fri, 1 Jun 2018 09:53:06 +0000 (10:53 +0100)
committerNeill Magill <neill.magill@nottingham.ac.uk>
Fri, 13 Jul 2018 13:03:42 +0000 (14:03 +0100)
Before this change if only a folder was submitted the submission_is_empty
check would return true. This meant that the draft area would be saved.
The is_empty check would then be called which would return false. This
caused the submission form to indicate to the user that the submission
had failed.

Now is_empty and submission_is_empty should both return false if only
folders are submitted.

mod/assign/submission/file/locallib.php

index 2a02a85..3b1959b 100644 (file)
@@ -513,8 +513,16 @@ class assign_submission_file extends assign_submission_plugin {
      * @return bool
      */
     public function submission_is_empty(stdClass $data) {
-        $files = file_get_drafarea_files($data->files_filemanager);
-        return count($files->list) == 0;
+        global $USER;
+        $fs = get_file_storage();
+        // Get a count of all the draft files, excluding any directories.
+        $files = $fs->get_area_files(context_user::instance($USER->id)->id,
+                                     'user',
+                                     'draft',
+                                     $data->files_filemanager,
+                                     'id',
+                                     false);
+        return count($files) == 0;
     }
 
     /**