moodle-logstore_xapi
moodle-logstore_xapi copied to clipboard
$event->id does not exist in multiple places.
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
- 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.
We can not assume event will have an id, we need to handle this/assign this appropriately.
Yeah I'd recommend checking if it's there and setting it to null
if not.
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?
I can see four uses of the event's id.
- /src/transformer/events/mod_quiz/attempt_viewed.php#L37
- /src/loader/lrs.php#L70
- /src/transformer/handler.php#L46
- /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.
That's agreeable.