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

$event->id does not exist in multiple places.

Open caperneoignis opened this issue 6 years ago • 5 comments

Description When going through a quiz, with the logstore app set to real time transmission to the LRS. I get the following in several places.

Notice: Undefined property: stdClass::$id in {web_directory}\moodle\admin\tool\log\store\xapi\src\transformer\events\mod_quiz\attempt_viewed.php on line 37

And again at transformer\handler.php line 37

$eventobj->id is undefined. Version

  • master, version 2018073005

Steps to reproduce the bug

  1. Have debugging turned on for moodle. Go and take a quiz, and look at the bottom, you will see several undefined warnings.

Expected behaviour

  • No warnings, because the id has either been set, or there is a check to replace the value with the expected value, or ignore the value all together.

Actual behaviour

  • The id is not being set in the stdClass causing errors and in some cases bad values/no event sent.

caperneoignis avatar Aug 22 '18 12:08 caperneoignis

We can not assume event will have an id, we need to handle this/assign this appropriately.

caperneoignis avatar Aug 22 '18 12:08 caperneoignis

Yeah I'd recommend checking if it's there and setting it to null if not.

ryasmi avatar Aug 22 '18 13:08 ryasmi

Any opposition to using a ternary expression in those spots? And to use zero instead of null since null can put us back into the undefined boat depending on where that element ends up?

caperneoignis avatar Aug 22 '18 17:08 caperneoignis

I can see four uses of the event's id.

  1. /src/transformer/events/mod_quiz/attempt_viewed.php#L37
  2. /src/loader/lrs.php#L70
  3. /src/transformer/handler.php#L46
  4. /classes/task/emit_task.php#L46

Let me know if there are any other uses. I think the first usage is actually meant to be $event->objectid rather than the $event->id. If that's the case, we should probably just avoid using the event id, except where it's absolutely needed like the 4th usage where the id will have to exist.

ryasmi avatar Aug 23 '18 09:08 ryasmi

That's agreeable.

caperneoignis avatar Aug 24 '18 14:08 caperneoignis