From e13a2ff5017e1add047e8a5c0ba4c15967b1358b Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 10 May 2023 17:16:18 +0200 Subject: [PATCH] MDL-78196 user: Fix files used space check --- user/externallib.php | 6 ++++-- user/tests/externallib_test.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/user/externallib.php b/user/externallib.php index 54dfb0e032e..a4933968f31 100644 --- a/user/externallib.php +++ b/user/externallib.php @@ -1212,8 +1212,10 @@ class core_user_external extends \core_external\external_api { $maxbytes = USER_CAN_IGNORE_FILE_SIZE_LIMITS; $maxareabytes = FILE_AREA_MAX_BYTES_UNLIMITED; } else { - // Get current used space for this user. - $usedspace = file_get_user_used_space(); + // Get current used space for this user (private files only). + $fileareainfo = file_get_file_area_info($context->id, 'user', 'private'); + $usedspace = $fileareainfo['filesize_without_references']; + // Get the total size of the new files we want to add to private files. $newfilesinfo = file_get_draft_area_info($params['draftid']); diff --git a/user/tests/externallib_test.php b/user/tests/externallib_test.php index db87ef6352c..3e1ddc64e1e 100644 --- a/user/tests/externallib_test.php +++ b/user/tests/externallib_test.php @@ -1079,7 +1079,8 @@ class externallib_test extends externallib_advanced_testcase { core_user_external::add_user_private_files($draftid); // Force the quota so we are sure it won't be space to add the new file. - $CFG->userquota = file_get_user_used_space() + 1; + $fileareainfo = file_get_file_area_info($contextid, 'user', 'private'); + $CFG->userquota = $fileareainfo['filesize_without_references'] + 1; // Generate a new draftitemid for the same testfile. $draftfile = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,