From 7d00d01b663b5e61b280eb6a11ef2a6e8cb7ae3c Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Wed, 19 Feb 2025 14:24:43 +0100 Subject: [PATCH] MDL-72050 filelib: Add function for deleting draftarea --- lib/filelib.php | 13 +++++++++++++ lib/upgrade.txt | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/filelib.php b/lib/filelib.php index b2e63548725..d38dc38f9d4 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 diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 7eb4f38d3ca..1a0999b2957 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -25,6 +25,9 @@ completed modules to the DBMS improving the performance of the method. user has been redirected to the expected location. e.g. `And the url should match "/mod/forum/view\.php\?id=[0-9]+"` +* A new function `file_clear_draft_area()` has been added to delete the files in a draft area. + For more information see [MDL-72050](https://tracker.moodle.org/browse/MDL-72050) + === 4.4.5 === * All uses of the following PHPUnit methods have been removed as these methods are deprecated upstream without direct replacement: