-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
4.4.1
Background
Creating/updating random questions used to be handled by calling qtype_random's save_question method. This in turn called save_question from the question type base class, which would fire the relevant events.
Creating a question
In 3.9 quiz_add_random_questions would call save_question (see here). However since 4.0 the slot_random class is used. Which does not call save_question. We get the slot created event but not the question created event.
Updating a question
In 3.9 mod/quiz/editrandom.php called save_question (see here). From 4.0 onwards, editrandom.php no longer calls save_question and the event is no longer fired.
Interesting observations
Changes to the base question type class
It appears that the question_type base class exclusively fires question_created events from 4.0 onwards too (this makes sense due to question versioning implying a new question every time a question is saved) - but random questions are different as they don't have versions. So it still makes sense that the question_updated event should fire in the case of a random question being updated.
Original code still exists
Weirdly, the original save_question code still exists: https://github.com/moodle/moodle/blob/2e1a632302c4d3a47b2dfc1c790d106d38a03c73/question/type/random/questiontype.php#L195
And even more weirdly, it's still got a unit test (which passes): https://github.com/moodle/moodle/blob/674497a12c200a7b2c7fdd559a5b692c26dc8be1/question/type/random/tests/question_type_test.php#L77
Solutions
It looks like there are two approaches here:
- Deprecate qtype_random's save_question and fire appropriate events in the relevant places as identified above.
- Rewrite save_question so it handles saving, updating, and firing appropriate events (I'm not sure if we should call parent::save_question - probably not?) and update other parts of the code to call save_question.
- is a regression caused by
-
MDL-71696 Add question versions
-
- Closed
-