From 74fbce756071676e4d458c6166aa64a9159f24bd Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Fri, 1 Jun 2018 10:53:06 +0100 Subject: [PATCH] MDL-49025 assign: Submissions of an empty directory should not save 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php index 2a02a855fcb..3b1959bf7f3 100644 --- a/mod/assign/submission/file/locallib.php +++ b/mod/assign/submission/file/locallib.php @@ -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; } /**