MDL-58712 core_user: Do not count the root directory

This commit is contained in:
Juan Leyva
2017-06-22 16:09:58 +02:00
committed by Eloy Lafuente (stronk7)
parent 828540b557
commit bef201c7e0
4 changed files with 9 additions and 11 deletions
+3 -6
View File
@@ -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;
+3 -3
View File
@@ -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.
+1
View File
@@ -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 ===
+2 -2
View File
@@ -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']);
}