I am with a Moodle Partner using version 2.8.6. I am investigating a situation for a client where after a course restore random questions are referencing different question categories.
The basic step up is that there are template courses. Each of the quizzes in the course contain random questions which are retrieving questions from question categories in the system context. The template course is backed up and restored to a new course.
I set up a simplified scenario in a sandbox environment. I created a question category in the system context and two sub-categories within that. I added four questions to each category. In my template course I created a quiz with one random question, set to retrieve questions from one of the system-level question categories. I backed up the template course and then restored it into a new course. Examining the database, I observed that the mdl_quiz_slots record for the quiz in both the template course and the new course reference the same mdl_question record.
By comparison, I backed up a template course in the client's production environment and restored it to a new course in production. I then used this query to compare the data on all the questions between the source and destination courses.
SELECT SC.quiz, SC.slot, SC.questionid, SC.category, SC.CategoryName, DT.questionid, DT.category, DT.categoryName FROM
(select z.name as Quiz, s.slot, s.questionid, q.qtype, q.name as Question,
q.questiontext as IncludeSubcategories, q.category, qc.name as CategoryName, qc.parent,
qc.stamp as CategoryStamp, q.stamp as QuestionStamp, q.version as QuestionVersion,
from_unixtime(q.timemodified) tm, q.modifiedby from mdl_course_modules cm
inner join mdl_quiz z on z.id = cm.instance
inner join mdl_quiz_slots s on s.quizid = z.id
inner join mdl_question q on q.id = s.questionid
inner join mdl_question_categories qc on qc.id = q.category
where cm.course = 136 and cm.module = 14
order by z.name, s.slot) SC
INNER JOIN
(select z.name as Quiz, s.slot, s.questionid, q.qtype, q.name as Question,
q.questiontext as IncludeSubcategories, q.category, qc.name as CategoryName, qc.parent,
qc.stamp as CategoryStamp, q.stamp as QuestionStamp, q.version as QuestionVersion,
from_unixtime(q.timemodified) tm, q.modifiedby from mdl_course_modules cm
inner join mdl_quiz z on z.id = cm.instance
inner join mdl_quiz_slots s on s.quizid = z.id
inner join mdl_question q on q.id = s.questionid
inner join mdl_question_categories qc on qc.id = q.category
where cm.course = 272 and cm.module = 14
order by z.name, s.slot
) DT
ON SC.Quiz = DT.Quiz AND SC.slot = DT.slot
order by SC.quiz, SC.slot
Using various where clauses on the query I reached these numbers:
Total number of quiz slots: 342
Number of quiz slots pointed to same question record: 208
Number of quiz slots pointed to different question, but both questions point to the same question category: 0
Number of quiz slots pointed to different question which point to different question category: 134
Number of quiz slots pointed to different question where the name of question (displayed in the UI) does not accurately reflect the name of the question category to which it points: 112
I selected example questions for each of these scenarios and reviewed the mdl_quiz_slots, mdl_question, and mdl_question_categories records for the questions used in the source course and those used in the destination course. One interesting observation I found is that in the situation where the destination course is using a different mdl_question record the mdl_question.stamp and mdl_question.version values match on the question used by the source course and the question used by the destination course. Likewise, though the two questions point to different question categories, the mdl_question_categories.stamp value is the same for both categories.
However, looking at the mdl_question record for the example question that was used in both source and destination courses, I found 10 additional questions using the same stamp and version values. Likewise, there are 11 question categories using the same stamp value as the category to which this question points.
I still suspect the stamp and version values are somehow at play here based on this forum thread https://moodle.org/mod/forum/discuss.php?d=135496.
I am looking for more information about how the stamp and version values are created and used. Also, is the general expectation that during a backup and restore that all quiz slots in the destination course would point to the same mdl_question records as in the source course (presuming none of the questions were modified in between time of backup and time of restore)?
Thank you for any advice or guidance on this issue.