MDL-58712 core_user: Do not count the root directory
authorJuan Leyva <juanleyvadelgado@gmail.com>
Thu, 22 Jun 2017 10:20:16 +0000 (11:20 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 22 Jun 2017 14:09:58 +0000 (16:09 +0200)
lib/filelib.php
lib/tests/filelib_test.php
lib/upgrade.txt
user/tests/externallib_test.php

index 0812382..28faa7e 100644 (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
  */
  *      '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();
 
 
     $fs = get_file_storage();
 
@@ -535,11 +535,8 @@ function file_get_file_area_info($contextid, $component, $filearea, $itemid = fa
         'filesize_without_references' => 0
     );
 
         '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;
     foreach ($draftfiles as $file) {
         if ($file->is_directory()) {
             $results['foldercount'] += 1;
index a367aaa..87a37bd 100644 (file)
@@ -1269,7 +1269,7 @@ EOF;
         $fileinfo = file_get_draft_area_info($draftitemid);
         $this->assertEquals(3, $fileinfo['filecount']);
         $this->assertEquals($size, $fileinfo['filesize']);
         $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.
         $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']);
         $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']);
     }
 
         $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']);
         $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.
         $this->assertEquals($size, $fileinfo['filesize_without_references']);
 
         // Now get files from just one folder.
index 0044bd3..fce1d3a 100644 (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.
 * 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 ===
 
 
 === 3.3.1 ===
 
index bf9edd8..cf04d56 100644 (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']);
         $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.
         $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']);
         $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']);
     }
 
         $this->assertEquals($file->get_filesize(), $result['filesizewithoutreferences']);
     }