From bef201c7e047450a3cb36025517ed7192ecd4812 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 22 Jun 2017 11:20:16 +0100 Subject: [PATCH] MDL-58712 core_user: Do not count the root directory --- lib/filelib.php | 9 +++------ lib/tests/filelib_test.php | 6 +++--- lib/upgrade.txt | 1 + user/tests/externallib_test.php | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/filelib.php b/lib/filelib.php index 08123829a38..28faa7eaae8 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -524,7 +524,7 @@ function file_get_draft_area_info($draftitemid, $filepath = '/') { * 'filesize_without_references' => total size of the area excluding file references. * @since Moodle 3.4 */ -function file_get_file_area_info($contextid, $component, $filearea, $itemid = false, $filepath = '/') { +function file_get_file_area_info($contextid, $component, $filearea, $itemid = 0, $filepath = '/') { $fs = get_file_storage(); @@ -535,11 +535,8 @@ function file_get_file_area_info($contextid, $component, $filearea, $itemid = fa 'filesize_without_references' => 0 ); - if ($filepath != '/') { - $draftfiles = $fs->get_directory_files($contextid, $component, $filearea, $itemid, $filepath, true, true); - } else { - $draftfiles = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'id', true); - } + $draftfiles = $fs->get_directory_files($contextid, $component, $filearea, $itemid, $filepath, true, true); + foreach ($draftfiles as $file) { if ($file->is_directory()) { $results['foldercount'] += 1; diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php index a367aaaeaa1..87a37bd0fe2 100644 --- a/lib/tests/filelib_test.php +++ b/lib/tests/filelib_test.php @@ -1269,7 +1269,7 @@ EOF; $fileinfo = file_get_draft_area_info($draftitemid); $this->assertEquals(3, $fileinfo['filecount']); $this->assertEquals($size, $fileinfo['filesize']); - $this->assertEquals(2, $fileinfo['foldercount']); // Base and directory created. + $this->assertEquals(1, $fileinfo['foldercount']); // Directory created. $this->assertEquals($size, $fileinfo['filesize_without_references']); // Now get files from just one folder. @@ -1283,7 +1283,7 @@ EOF; $fileinfo = file_get_file_area_info($usercontext->id, 'user', 'draft', $draftitemid); $this->assertEquals(3, $fileinfo['filecount']); $this->assertEquals($size, $fileinfo['filesize']); - $this->assertEquals(2, $fileinfo['foldercount']); // Base and directory created. + $this->assertEquals(1, $fileinfo['foldercount']); // Directory created. $this->assertEquals($size, $fileinfo['filesize_without_references']); } @@ -1330,7 +1330,7 @@ EOF; $fileinfo = file_get_file_area_info($usercontext->id, 'user', 'private'); $this->assertEquals(3, $fileinfo['filecount']); $this->assertEquals($size, $fileinfo['filesize']); - $this->assertEquals(2, $fileinfo['foldercount']); // Base and directory created. + $this->assertEquals(1, $fileinfo['foldercount']); // Directory created. $this->assertEquals($size, $fileinfo['filesize_without_references']); // Now get files from just one folder. diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 0044bd34e54..fce1d3ae0b7 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -12,6 +12,7 @@ information provided here is intended especially for developers. * Role definitions are no longer cached in user session (MDL-49398). * External function core_group_external::get_activity_allowed_groups now returns an additional field: canaccessallgroups. It indicates whether the user will be able to access all the activity groups. +* file_get_draft_area_info does not sum the root folder anymore when calculating the foldercount. === 3.3.1 === diff --git a/user/tests/externallib_test.php b/user/tests/externallib_test.php index bf9edd81fdc..cf04d56f3f5 100644 --- a/user/tests/externallib_test.php +++ b/user/tests/externallib_test.php @@ -1177,7 +1177,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { $result = external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result); $this->assertEquals(1, $result['filecount']); $this->assertEquals($file->get_filesize(), $result['filesize']); - $this->assertEquals(1, $result['foldercount']); // Base directory. + $this->assertEquals(0, $result['foldercount']); $this->assertEquals($file->get_filesize(), $result['filesizewithoutreferences']); // As admin, get user information. @@ -1186,7 +1186,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { $result = external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result); $this->assertEquals(1, $result['filecount']); $this->assertEquals($file->get_filesize(), $result['filesize']); - $this->assertEquals(1, $result['foldercount']); // Base directory. + $this->assertEquals(0, $result['foldercount']); $this->assertEquals($file->get_filesize(), $result['filesizewithoutreferences']); }