Received this error when trying to review an attempt on a quiz. Using Moodle 2.4.4. Any help in solving the issue is appreciated greatly. Below is the debugging info:
Tim States
Anderson University
Hey Tim, Did you ever figure this out?
HI currently researhing this same problem on our moodle instance
Did anyone figure this out?
cheers,
Ben
ok i know what is causing this issue for us
here is my debugging for future moodlers:
line 1375 is where a context is searched for, line 872 gives the item which context id will be searched for (question_has_capability_on)
select * from mdl_question_categories qc
left join mdl_context mc on qc.contextid = mc.id
where contextid = {id here}; --in my case it was id 1426139
select * from mdl_question_categories qc
left join mdl_context mc on qc.contextid = mc.id
where mc.id is null
select * from mdl_question where category = {ghost category id}; --in my case 139055
SELECT
distinct
qa.questionid,*
FROM mdl_question_usages quba
LEFT JOIN mdl_question_attempts qa ON qa.questionusageid = quba.id
LEFT JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id
LEFT JOIN mdl_question_attempt_step_data qasd ON qasd.attemptstepid = qas.id
LEFT JOIN mdl_quiz_attempts quiza on quiza.uniqueid = quba.id
WHERE 1=1
and quiza.id = '1474741' -- attempt# from url
and qa.questionid in (select id from mdl_question where category = 139055) --filter by broken category for brevity
UPDATE mdl_question_categories
SET contextid= 110527 -- I chose this context from the same subjects questionbank
WHERE id = 139055 --this is the broken question category id
Are you reading the other similar thread: https://moodle.org/mod/forum/discuss.php?d=263041
Your analysis looks right. The only thing that might not work are images, are there is a hint in the other thread about how to fix them too.
thanks tim,
no i hadn't seen that thread in spite of my attempts at searching and scanning!
In case it helps anyone, I found that changing the category on the question wasn't enough on its own, I also had to purge the cache otherwise the questions still had the old category.
After upgrading to 2.8 from 2.5, we ran into this. We came up with this query to identify all question categories with a context that is broken and needs fixing - we just had two.
<code>
SELECT
mdl_quiz.id,
mdl_quiz.course,
mdl_quiz.name,
mdl_question.id,
mdl_question.category,
mdl_question.parent,
mdl_question.name,
mdl_question_categories.contextid AS catcontextidbroken,
mdl_question_categories.id AS questinocategoryid,
mdl_question_categories.name AS catname,
mdl_context.id AS contextidtoset
FROM
mdl_quiz_slots
INNER JOIN
mdl_quiz
ON
(
mdl_quiz_slots.quizid = mdl_quiz.id)
INNER JOIN
mdl_question
ON
(
mdl_quiz_slots.questionid = mdl_question.id)
INNER JOIN
mdl_question_categories
ON
(
mdl_question.category = mdl_question_categories.id)
INNER JOIN
mdl_context
ON
(
mdl_quiz.course = mdl_context.instanceid)
left join mdl_context mc on mdl_question_categories.contextid = mc.id
WHERE mc.id is null AND
mdl_context.id <>
mdl_question_categories.contextid
AND mdl_context.contextlevel = 50 ;
</code>
after this, we would have the informatino to do the
update mdl_question_categories set contextid = XXX where id = YYY;