mod_studentquiz: Fix duplicated question categories in course backup #513
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I still need to work out how to reproduce the issue manually, without sharing any of our real course backups, but under certain conditions we have found that backups of courses containing mod_studentquiz instances will result in all question categories in the course being duplicated on restore (the duplicates can be seen in the .mbz file).
Debugging has shown that additional course contexts are being included during the calculation of question categories to be included in the backup, and these seem to be the contexts of courses that also include usages of some of the same questions used in the mod_studentquiz instance.
The only reliable way to prevent this seems to be to include the step
new backup_delete_temp_questions('clean_temp_questions')
in backup/moodle2/backup_studentquiz_activity_task.class.php, however it must be included before the stepnew backup_calculate_question_categories('activity_question_categories')
, unlike in the core mod_quiz activity where it comes after it.