Merge branch 'MDL-58220-master-fix2' of http://github.com/damyon/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Wed, 5 Apr 2017 06:43:13 +0000 (14:43 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 5 Apr 2017 06:43:13 +0000 (14:43 +0800)
17 files changed:
admin/auth_config.php
course/externallib.php
lib/classes/user.php
lib/externallib.php
lib/filestorage/stored_file.php
lib/tests/externallib_test.php
mod/book/lib.php
mod/folder/lib.php
mod/forum/externallib.php
mod/forum/lib.php
mod/forum/tests/externallib_test.php
mod/forum/upgrade.txt
mod/imscp/lib.php
mod/page/lib.php
mod/quiz/report/upgrade.txt
mod/resource/lib.php
mod/wiki/tests/externallib_test.php

index 0f9c7a0..6c3e315 100644 (file)
@@ -16,7 +16,7 @@ $err = array();
 
 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
 
-debugging("Use of config.html files in authentication plugins have been depreciated. " .
+debugging("Use of config.html files in authentication plugins have been deprecated. " .
           " Please migrate your plugin to use the admin settings API", DEBUG_DEVELOPER);
 
 // save configuration changes
@@ -107,7 +107,7 @@ exit;
  */
 function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
     global $DB, $OUTPUT;
-    debugging("The function 'print_auth_lock_options' has been depreciated, " .
+    debugging("The function 'print_auth_lock_options' has been deprecated, " .
               "Please migrate your code to use the admin settings API and use the function 'display_auth_lock_options' instead. ",
               DEBUG_DEVELOPER);
 
index 01deee9..5d9a7d1 100644 (file)
@@ -363,6 +363,11 @@ class core_course_external extends external_api {
                                                   'timecreated' => new external_value(PARAM_INT, 'Time created'),
                                                   'timemodified' => new external_value(PARAM_INT, 'Time modified'),
                                                   'sortorder' => new external_value(PARAM_INT, 'Content sort order'),
+                                                  'mimetype' => new external_value(PARAM_RAW, 'File mime type.', VALUE_OPTIONAL),
+                                                  'isexternalfile' => new external_value(PARAM_BOOL, 'Whether is an external file.',
+                                                    VALUE_OPTIONAL),
+                                                  'repositorytype' => new external_value(PARAM_PLUGIN, 'The repository type for external files.',
+                                                    VALUE_OPTIONAL),
 
                                                   // copyright related info
                                                   'userid' => new external_value(PARAM_INT, 'User who added this content to moodle'),
index 9c95cc2..4967229 100644 (file)
@@ -27,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
 /**
  * User class to access user details.
  *
- * @todo       move api's from user/lib.php and depreciate old ones.
+ * @todo       move api's from user/lib.php and deprecate old ones.
  * @package    core
  * @copyright  2013 Rajesh Taneja <rajesh@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
index 896a175..4114ad6 100644 (file)
@@ -1309,6 +1309,10 @@ class external_util {
                 $file['mimetype'] = $areafile->get_mimetype();
                 $file['filesize'] = $areafile->get_filesize();
                 $file['timemodified'] = $areafile->get_timemodified();
+                $file['isexternalfile'] = $areafile->is_external_file();
+                if ($file['isexternalfile']) {
+                    $file['repositorytype'] = $areafile->get_repository_type();
+                }
                 $fileitemid = $useitemidinurl ? $areafile->get_itemid() : null;
                 $file['fileurl'] = moodle_url::make_webservice_pluginfile_url($contextid, $component, $filearea,
                                     $fileitemid, $areafile->get_filepath(), $areafile->get_filename())->out(false);
@@ -1345,6 +1349,8 @@ class external_files extends external_multiple_structure {
                     'fileurl' => new external_value(PARAM_URL, 'Downloadable file url.', VALUE_OPTIONAL),
                     'timemodified' => new external_value(PARAM_INT, 'Time modified.', VALUE_OPTIONAL),
                     'mimetype' => new external_value(PARAM_RAW, 'File mime type.', VALUE_OPTIONAL),
+                    'isexternalfile' => new external_value(PARAM_BOOL, 'Whether is an external file.', VALUE_OPTIONAL),
+                    'repositorytype' => new external_value(PARAM_PLUGIN, 'The repository type for external files.', VALUE_OPTIONAL),
                 ),
                 'File.'
             ),
@@ -1397,6 +1403,18 @@ class external_files extends external_multiple_structure {
                 'optional' => true,
                 'null' => NULL_NOT_ALLOWED,
             ),
+            'isexternalfile' => array(
+                'type' => PARAM_BOOL,
+                'description' => 'Whether is an external file.',
+                'optional' => true,
+                'null' => NULL_NOT_ALLOWED,
+            ),
+            'repositorytype' => array(
+                'type' => PARAM_PLUGIN,
+                'description' => 'The repository type for the external files.',
+                'optional' => true,
+                'null' => NULL_ALLOWED,
+            ),
         ];
     }
 }
index 92478b6..8eadfbe 100644 (file)
@@ -815,6 +815,22 @@ class stored_file {
         }
     }
 
+    /**
+     * Returns repository type.
+     *
+     * @return mixed str|null the repository type or null if is not an external file
+     * @since  Moodle 3.3
+     */
+    public function get_repository_type() {
+
+        if (!empty($this->repository)) {
+            return $this->repository->get_typename();
+        } else {
+            return null;
+        }
+    }
+
+
     /**
      * get reference file id
      * @return int
index d6a922c..088e40a 100644 (file)
@@ -510,6 +510,7 @@ class core_externallib_testcase extends advanced_testcase {
             'timemodified' => $timemodified,
             'filesize' => $filesize,
             'mimetype' => 'text/plain',
+            'isexternalfile' => false,
         );
         // Get all the files for the area.
         $files = external_util::get_area_files($context, $component, $filearea, false);
@@ -529,7 +530,8 @@ class core_externallib_testcase extends advanced_testcase {
         $description = new external_files();
 
         // First check that the expected default values and keys are returned.
-        $expectedkeys = array_flip(array('filename', 'filepath', 'filesize', 'fileurl', 'timemodified', 'mimetype'));
+        $expectedkeys = array_flip(array('filename', 'filepath', 'filesize', 'fileurl', 'timemodified', 'mimetype',
+            'isexternalfile', 'repositorytype'));
         $returnedkeys = array_flip(array_keys($description->content->keys));
         $this->assertEquals($expectedkeys, $returnedkeys);
         $this->assertEquals('List of files.', $description->desc);
index 04b11c0..860db56 100644 (file)
@@ -595,6 +595,11 @@ function book_export_contents($cm, $baseurl) {
             $file['userid']       = $fileinfo->get_userid();
             $file['author']       = $fileinfo->get_author();
             $file['license']      = $fileinfo->get_license();
+            $file['mimetype']     = $fileinfo->get_mimetype();
+            $file['isexternalfile'] = $fileinfo->is_external_file();
+            if ($file['isexternalfile']) {
+                $file['repositorytype'] = $fileinfo->get_repository_type();
+            }
             $contents[] = $file;
         }
     }
index 161cd02..8c2b17b 100644 (file)
@@ -326,6 +326,11 @@ function folder_export_contents($cm, $baseurl) {
         $file['userid']       = $fileinfo->get_userid();
         $file['author']       = $fileinfo->get_author();
         $file['license']      = $fileinfo->get_license();
+        $file['mimetype']     = $fileinfo->get_mimetype();
+        $file['isexternalfile'] = $fileinfo->is_external_file();
+        if ($file['isexternalfile']) {
+            $file['repositorytype'] = $fileinfo->get_repository_type();
+        }
         $contents[] = $file;
     }
 
index 04cde18..a6745c2 100644 (file)
@@ -98,6 +98,9 @@ class mod_forum_external extends external_api {
                 $forum->cmid = $forum->coursemodule;
                 $forum->cancreatediscussions = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
                 $forum->istracked = forum_tp_is_tracked($forum);
+                if ($forum->istracked) {
+                    $forum->unreadpostscount = forum_tp_count_forum_unread_posts($cm, $course);
+                }
 
                 // Add the forum to the array to return.
                 $arrforums[$forum->id] = $forum;
@@ -146,6 +149,8 @@ class mod_forum_external extends external_api {
                     'cancreatediscussions' => new external_value(PARAM_BOOL, 'If the user can create discussions', VALUE_OPTIONAL),
                     'lockdiscussionafter' => new external_value(PARAM_INT, 'After what period a discussion is locked', VALUE_OPTIONAL),
                     'istracked' => new external_value(PARAM_BOOL, 'If the user is tracking the forum', VALUE_OPTIONAL),
+                    'unreadpostscount' => new external_value(PARAM_INT, 'The number of unread posts for tracked forums',
+                        VALUE_OPTIONAL),
                 ), 'forum'
             )
         );
index 8546c7f..b66923e 100644 (file)
@@ -6382,13 +6382,18 @@ function forum_tp_get_course_unread_posts($userid, $courseid) {
  * @global object
  * @param object $cm
  * @param object $course
+ * @param bool   $resetreadcache optional, true to reset the function static $readcache var
  * @return int
  */
-function forum_tp_count_forum_unread_posts($cm, $course) {
+function forum_tp_count_forum_unread_posts($cm, $course, $resetreadcache = false) {
     global $CFG, $USER, $DB;
 
     static $readcache = array();
 
+    if ($resetreadcache) {
+        $readcache = array();
+    }
+
     $forumid = $cm->instance;
 
     if (!isset($readcache[$course->id])) {
index ea1ca6d..e3ee2b6 100644 (file)
@@ -94,6 +94,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
         $forum1->numdiscussions = 1;
         $forum1->cancreatediscussions = true;
         $forum1->istracked = true;
+        $forum1->unreadpostscount = 0;
         $forum1->introfiles = [];
 
         $record = new stdClass();
@@ -215,6 +216,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
         $record = new stdClass();
         $record->course = $course1->id;
         $forum2 = self::getDataGenerator()->create_module('forum', $record);
+        $forum2cm = get_coursemodule_from_id('forum', $forum2->cmid);
         $forum2context = context_module::instance($forum2->cmid);
 
         // Add discussions to the forums.
@@ -323,6 +325,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
                                     $discussion1reply1->id, '/', $filename),
                     'timemodified' => $timepost,
                     'mimetype' => 'image/jpeg',
+                    'isexternalfile' => false,
                 )
             ),
             'totalscore' => $discussion1reply1->totalscore,
@@ -352,6 +355,16 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
         array_pop($posts['posts']);
         $this->assertEquals($expectedposts, $posts);
 
+        // Check we receive the unread count correctly on tracked forum.
+        forum_tp_count_forum_unread_posts($forum2cm, $course1, true);    // Reset static cache.
+        $result = mod_forum_external::get_forums_by_courses(array($course1->id));
+        $result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
+        foreach ($result as $f) {
+            if ($f['id'] == $forum2->id) {
+                $this->assertEquals(1, $f['unreadpostscount']);
+            }
+        }
+
         // Test discussion without additional posts. There should be only one post (the one created by the discussion).
         $posts = mod_forum_external::get_forum_discussion_posts($discussion2->id, 'modified', 'DESC');
         $posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
@@ -382,6 +395,16 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
         foreach ($posts['posts'] as $post) {
             $this->assertTrue($post['postread']);
         }
+
+        // Check we receive 0 unread posts.
+        forum_tp_count_forum_unread_posts($forum2cm, $course1, true);    // Reset static cache.
+        $result = mod_forum_external::get_forums_by_courses(array($course1->id));
+        $result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
+        foreach ($result as $f) {
+            if ($f['id'] == $forum2->id) {
+                $this->assertEquals(0, $f['unreadpostscount']);
+            }
+        }
     }
 
     /**
index 4b730e4..1645cf7 100644 (file)
@@ -97,7 +97,7 @@ information provided here is intended especially for developers.
 * The function forum_shorten_post() has been deprecated. It was doing a poor
   job of shortening forum post text and the shorten_text() function does a
   much better job.
-* The constant FORUM_TRACKING_ON has been depreciated and replaced by
+* The constant FORUM_TRACKING_ON has been deprecated and replaced by
   FORUM_TRACKING_FORCED. The value between them is maintained, so they are
   interchangeable, but code should migrate to the new name.
 
index cc0dbdc..d3c9e4e 100644 (file)
@@ -420,6 +420,11 @@ function imscp_export_contents($cm, $baseurl) {
         $file['userid']       = $fileinfo->get_userid();
         $file['author']       = $fileinfo->get_author();
         $file['license']      = $fileinfo->get_license();
+        $file['mimetype']     = $fileinfo->get_mimetype();
+        $file['isexternalfile'] = $fileinfo->is_external_file();
+        if ($file['isexternalfile']) {
+            $file['repositorytype'] = $fileinfo->get_repository_type();
+        }
         $contents[] = $file;
     }
 
index b1f5a84..ce8ba80 100644 (file)
@@ -424,6 +424,11 @@ function page_export_contents($cm, $baseurl) {
         $file['userid']       = $fileinfo->get_userid();
         $file['author']       = $fileinfo->get_author();
         $file['license']      = $fileinfo->get_license();
+        $file['mimetype']     = $fileinfo->get_mimetype();
+        $file['isexternalfile'] = $fileinfo->is_external_file();
+        if ($file['isexternalfile']) {
+            $file['repositorytype'] = $fileinfo->get_repository_type();
+        }
         $contents[] = $file;
     }
 
index 93da5f9..cbd4b93 100644 (file)
@@ -14,7 +14,7 @@ methods now includes '$studentsjoins', rather than '$students' and similar
 for '$groupstudentsjoins', '$allowedjoins' and '$usersjoins'. For clear
 examples of the use of these changes please see attemptsreport_table.php
 base_sql() or almost any function in overview/report.php. The protected
-function quiz_attempts_report::load_relevant_students is depreciated,
+function quiz_attempts_report::load_relevant_students is deprecated,
 please use quiz_attempts_report::get_students_joins() instead.
 
 === 2.6 ===
index da5f0fa..adbd744 100644 (file)
@@ -460,6 +460,11 @@ function resource_export_contents($cm, $baseurl) {
         $file['userid']       = $fileinfo->get_userid();
         $file['author']       = $fileinfo->get_author();
         $file['license']      = $fileinfo->get_license();
+        $file['mimetype']     = $fileinfo->get_mimetype();
+        $file['isexternalfile'] = $fileinfo->is_external_file();
+        if ($file['isexternalfile']) {
+            $file['repositorytype'] = $fileinfo->get_repository_type();
+        }
         $contents[] = $file;
     }
 
index cbe4967..3e3c9dc 100644 (file)
@@ -1074,6 +1074,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
             'filename' => $file['filename'],
             'filepath' => $file['filepath'],
             'mimetype' => 'image/jpeg',
+            'isexternalfile' => false,
             'filesize' => strlen($content),
             'timemodified' => $file['timemodified'],
             'fileurl' => moodle_url::make_webservice_pluginfile_url($file['contextid'], $file['component'],
@@ -1128,6 +1129,7 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
             'filename' => $file['filename'],
             'filepath' => $file['filepath'],
             'mimetype' => 'image/jpeg',
+            'isexternalfile' => false,
             'filesize' => strlen($content),
             'timemodified' => $file['timemodified'],
             'fileurl' => moodle_url::make_webservice_pluginfile_url($file['contextid'], $file['component'],