moodle-logstore_xapi
moodle-logstore_xapi copied to clipboard
Transforming event having userid=0 creates exception
Description
- The transformer generates exceptions if the userid = 0 ( \core\event\course_viewed and \core\event\user_created). More generally the user ( guest? ) is not in the database, so every transformer that uses it fails.
Version
- https://github.com/xAPI-vle/moodle-logstore_xapi/releases/download/v4.2.5/xapi.zip
Steps to reproduce the bug
- I am using Moodle, and I am unsure of how it is generating the event as guest, at the moment. This feature is not checked.
Expected behaviour
- events having userid=0 should be transformed because they exist.
Actual behaviour
- events having userid=0 create exception.
Server information
- Moodle+mysql.
Client information
- OS: linux
- Browser: chrome 78.0.3904.70 (Official Build) (64-bit)
Thank you.
@Callustian - which version of the plugin are you using?
@davidpesce Thank you for your reply.
I am using v4.2.5.
@Callustian @davidpesce @gordonmacqueen-lp @Patches- @lzabo Suggested code change in these methods:
// Get a valid user for guest.
$guest = false;
if ($event->userid == 0) {
$guest = true;
if (isset($CFG->siteguest)) {
$event->userid = $CFG->siteguest;
}
}
$user = $repo->read_record_by_id('user', $event->userid);
// Reset userid so it is the same as in logstore_standard_log.
if ($guest == true) {
$event->userid = 0;
}
Would it be possible to create a branch and put this in for code review in the following files: course_viewed.php user_created.php