diff --git a/.upgradenotes/MDL-72050-2025021912300902.yml b/.upgradenotes/MDL-72050-2025021912300902.yml new file mode 100644 index 00000000000..d2f0a1d5fcf --- /dev/null +++ b/.upgradenotes/MDL-72050-2025021912300902.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-72050 +notes: + core_files: + - message: >- + A new function `file_clear_draft_area()` has been added to delete the + files in a draft area. + type: improved diff --git a/lib/filelib.php b/lib/filelib.php index 68f662f5a4f..0b3b4b7f74a 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -1313,6 +1313,19 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea } } +/** + * Clear a draft area. + * + * @param int $draftitemid Id of the draft area to clear. + * @return boolean success + */ +function file_clear_draft_area(int $draftitemid): bool { + global $USER; + $fs = get_file_storage(); + $usercontext = context_user::instance($USER->id); + return $fs->delete_area_files($usercontext->id, 'user', 'draft', $draftitemid); +} + /** * Convert the draft file area URLs in some content to @@PLUGINFILE@@ tokens * ready to be saved in the database. Normally, this is done automatically by