moodle-logstore_xapi icon indicating copy to clipboard operation
moodle-logstore_xapi copied to clipboard

Transforming event having userid=0 creates exception

Open Callustian opened this issue 6 years ago • 3 comments

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

  1. 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 avatar Oct 30 '19 15:10 Callustian

@Callustian - which version of the plugin are you using?

davidpesce avatar Jan 30 '20 18:01 davidpesce

@davidpesce Thank you for your reply.

I am using v4.2.5.

Callustian avatar Jan 31 '20 13:01 Callustian

@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

mlynn-lp avatar Jun 04 '20 09:06 mlynn-lp