From 7310dcff41a67c46bbe9e7988a07ef83ce09ad51 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 3 Feb 2015 21:53:11 +0100 Subject: [PATCH] MDL-30239 webservices: Return additional fields in ws get_files --- files/externallib.php | 19 +++++++++++++++++-- files/tests/externallib_test.php | 9 ++++++++- lib/upgrade.txt | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/files/externallib.php b/files/externallib.php index fdf63c548b1..19cba7ff110 100644 --- a/files/externallib.php +++ b/files/externallib.php @@ -74,6 +74,7 @@ class core_files_external extends external_api { * @param string $contextlevel The context level for the file location. * @param int $instanceid The instance id for where the file is located. * @return array + * @since Moodle 2.9 Returns additional fields (timecreated, filesize, author, license) * @since Moodle 2.2 */ public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null, @@ -139,6 +140,7 @@ class core_files_external extends external_api { $params = $child->get_params(); $timemodified = $child->get_timemodified(); + $timecreated = $child->get_timecreated(); if ($child->is_directory()) { if ((is_null($modified)) or ($modified < $timemodified)) { @@ -151,7 +153,11 @@ class core_files_external extends external_api { 'filename' => $child->get_visible_name(), 'url' => null, 'isdir' => true, - 'timemodified' => $timemodified + 'timemodified' => $timemodified, + 'timecreated' => $timecreated, + 'filesize' => 0, + 'author' => null, + 'license' => null ); $list[] = $node; } @@ -166,7 +172,11 @@ class core_files_external extends external_api { 'filename' => $child->get_visible_name(), 'url' => $child->get_url(), 'isdir' => false, - 'timemodified' => $timemodified + 'timemodified' => $timemodified, + 'timecreated' => $timecreated, + 'filesize' => $child->get_filesize(), + 'author' => $child->get_author(), + 'license' => $child->get_license() ); $list[] = $node; } @@ -181,6 +191,7 @@ class core_files_external extends external_api { * Returns description of get_files returns * * @return external_single_structure + * @since Moodle 2.9 Returns additional fields for files (timecreated, filesize, author, license) * @since Moodle 2.2 */ public static function get_files_returns() { @@ -210,6 +221,10 @@ class core_files_external extends external_api { 'isdir' => new external_value(PARAM_BOOL, ''), 'url' => new external_value(PARAM_TEXT, ''), 'timemodified' => new external_value(PARAM_INT, ''), + 'timecreated' => new external_value(PARAM_INT, 'Time created', VALUE_OPTIONAL), + 'filesize' => new external_value(PARAM_INT, 'File size', VALUE_OPTIONAL), + 'author' => new external_value(PARAM_TEXT, 'File owner', VALUE_OPTIONAL), + 'license' => new external_value(PARAM_TEXT, 'File license', VALUE_OPTIONAL), ) ) ) diff --git a/files/tests/externallib_test.php b/files/tests/externallib_test.php index 3922c6494b6..b49ff72f63d 100644 --- a/files/tests/externallib_test.php +++ b/files/tests/externallib_test.php @@ -244,6 +244,8 @@ class core_files_externallib_testcase extends advanced_testcase { // Create a file from the string that we made earlier. $file = $fs->create_file_from_string($filerecord, $filecontent); $timemodified = $file->get_timemodified(); + $timecreated = $file->get_timemodified(); + $filesize = $file->get_filesize(); // Use the web service function to return the information about the file that we just uploaded. // The first time is with a valid context ID. @@ -293,7 +295,12 @@ class core_files_externallib_testcase extends advanced_testcase { 'filename' => 'Simple4.txt', 'url' => 'http://www.example.com/moodle/pluginfile.php/'.$context->id.'/mod_data/content/'.$itemid.'/Simple4.txt', 'isdir' => false, - 'timemodified' => $timemodified); + 'timemodified' => $timemodified, + 'timecreated' => $timecreated, + 'filesize' => $filesize, + 'author' => null, + 'license' => null + ); // Make sure that they are the same. $this->assertEquals($testdata, $testfilelisting); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index e2451da6620..0d652cf8c94 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -15,6 +15,7 @@ information provided here is intended especially for developers. * For 3rd party plugin specific environment.xml files, it's now possible to specify version independent checks by using the tag instead of the version dependent one. If the PLUGIN tag is used any Moodle specific tags will be ignored. +* External function core_files_get_files returns additional fields (timecreated, filesize, author, license) === 2.8 ===