Questions about events and messages

Questions about events and messages

by Tim Hunt -
Number of replies: 1
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In the past it used to be impossible to send messages through the messaging API in the middle of a database transaction. Is that sill the case?

It looks like that got solved in Moodle 2.8: MDL-45941

Currently (since it had to work before Moodle 2.8 was released) the quiz handles this be subscribing to its own events like \mod_quiz\event\attempt_submitted with a funciton like quiz_attempt_submitted_handler, and sends the messages in the event handler.

I need to change things so that the quiz is more intelligent about which messages is sends (MDL-47691). As part of this I need more data in the event handler. In particular I need the $attemptobj instance of the quiz_attempt class (which contains a question_usage_by_activity object). Am allowed to pass a big complex object through $event->add_record_snapshot()? I believe the answer is no, but woudl appreciate confirmation.


Does anyone have a view about the best way to handle this. Perhaps now that MDL-45941 is fixed, the  best thing would be to take event handlers out of the equation here, and just send the messages?

Thanks for any help you can offer.

Average of ratings: -
In reply to Tim Hunt

Re: Questions about events and messages

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Answering my own question, since I tried to code this to see how it worked out.

Removing the use of the event handler simplified the code considerably (and the resulting code worked!) so that seems to be the way to go.

Average of ratings: Useful (1)