Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transforming event having userid=0 creates exception #606

Open
Callustian opened this issue Oct 30, 2019 · 3 comments
Open

Transforming event having userid=0 creates exception #606

Callustian opened this issue Oct 30, 2019 · 3 comments

Comments

@Callustian
Copy link

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

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.

@davidpesce
Copy link
Collaborator

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

@Callustian
Copy link
Author

@davidpesce Thank you for your reply.

I am using v4.2.5.

@mlynn-lp
Copy link
Contributor

mlynn-lp commented Jun 4, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants