From 160e77f9d0cefcf9728bc90aa26f2229b9850a52 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 9 Nov 2018 13:09:54 +0800 Subject: [PATCH 1/1] MDL-63716 course: less user_accesstime_log() calls We should only call this function when a user actually views a course. It is not called automatically when a course context is validated from a webservice. It is called directly from the core_course_view_course webservice. --- course/lib.php | 3 +++ lib/moodlelib.php | 10 ++++++++-- lib/upgrade.txt | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/course/lib.php b/course/lib.php index b4ed03b317b..a409cf1965e 100644 --- a/course/lib.php +++ b/course/lib.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir.'/completionlib.php'); require_once($CFG->libdir.'/filelib.php'); +require_once($CFG->libdir.'/datalib.php'); require_once($CFG->dirroot.'/course/format/lib.php'); define('COURSE_MAX_LOGS_PER_PAGE', 1000); // Records. @@ -3665,6 +3666,8 @@ function course_view($context, $sectionnumber = 0) { $event = \core\event\course_viewed::create($eventdata); $event->trigger(); + + user_accesstime_log($context->instanceid); } /** diff --git a/lib/moodlelib.php b/lib/moodlelib.php index faa458051e7..6d758b21b72 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2763,7 +2763,10 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ $PAGE->set_course($course); } // Set accesstime or the user will appear offline which messes up messaging. - user_accesstime_log($course->id); + // Do not update access time for webservice or ajax requests. + if (!WS_SERVER && !AJAX_SCRIPT) { + user_accesstime_log($course->id); + } return; } @@ -2972,7 +2975,10 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ } // Finally access granted, update lastaccess times. - user_accesstime_log($course->id); + // Do not update access time for webservice or ajax requests. + if (!WS_SERVER && !AJAX_SCRIPT) { + user_accesstime_log($course->id); + } } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 6bea9f1ab00..c0f18c8be0f 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -165,6 +165,7 @@ the groupid field. until all settings have been set. The additional parameters are used recursively and shouldn't be need to be explicitly passed in when calling the function from other parts of Moodle. The return value: $settingsoutput is an array of setting names and the values that were set by the function. +* Webservices no longer update the lastaccess time for a user in a course. Call core_course_view_course() manually if needed. === 3.5 === -- 2.43.0