Unsupported contextlevel in category record!

Unsupported contextlevel in category record!

autor Brian Williams -
Počet odpovědí: 13
When clicking on the first quiz in my course, i get the error "Unsupported contextlevel in category record!" All of my other quizzes are working fine. I assume it has a problem with the contextID field of the category record for this quiz category, but i don't know exactly what it does or means. Can anybody help?
Průměr hodnocení: -
V odpovědi na Brian Williams

Re: Unsupported contextlevel in category record!

autor Tim Hunt -
Obrázek: Core developers Obrázek: Documentation writers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers
That is a "This should never happen" error. You are right, something has got stuffed up with the contexts in a way that should not be possible.

If you run:

SELECT *
FROM h_question_categories qc
JOIN h_context con ON qc.contextid = con.id
WHERE con.contextlevel NOT IN (10, 40, 50, 70)

Then that will list all the problem question categories that might trigger this error message.

Given that list, it might be possible to deduce what happened, and it may be possible to work out the correct context id for each category in the (hopefully short) list of problem categories.
V odpovědi na Tim Hunt

Re: Unsupported contextlevel in category record!

autor Brian Williams -
Tim,
Thanks for your reply. I ran the following and got nothing.

SQL query: SELECT *
FROM mdl_question_categories qc
JOIN mdl_context con ON qc.contextid = con.id
WHERE con.contextlevel NOT
IN ( 10, 40, 50, 70 )
LIMIT 0 , 30

MySQL returned an empty result set (i.e. zero rows). (Query took 0.0007 sec)

This may have been my fault. When I started working on this site, there were several quiz categories of questions that never show up in the question bank. I couldn't figure out what was going on, so i looked into the DB. The questions were there, and the categories were there, but the parent field was set to 0 for every category. I changed the parent manually so that the questions would show up in the question bank. I was also having problems with the first quiz before. It was always showing 1 question per page even questions per page was set to unlimited. If i changed other options as well, it would take, but then when i reset them back to the options i wanted, it would revert back. Eventually i decided to trash that quiz all together and rebuild a new one. This new quiz is the one that is causing the problems. I did a search for the questions that belong to that quiz, knowing they were in category 13. The questions were ID's 43-47, and none of them are even in the context table at all. I am guessing that is the problem, but i don't know what it happened or what should be done to fix it. Thanks for any suggestions you might have.

Brian
V odpovědi na Brian Williams

Re: Unsupported contextlevel in category record!

autor Tim Hunt -
Obrázek: Core developers Obrázek: Documentation writers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers
If the query I gave you returns no rows, the I don't understand why you are seeing the error that you are seeing.

Regarding what you say in the rest of the paragraph: Parent of 0 should not cause a problem, it means 'Top level'. And questions would never go in the contexts table. I don't understand what you mean there.
V odpovědi na Tim Hunt

Re: Unsupported contextlevel in category record!

autor Brian Williams -
Tim,
Thanks for your help. I didn't realize that the questions were not supposed to be in the contexts table, so obviously that isn't the problem. I am not sure what could be wrong. Should i try to delete this quiz all together and just recreate it again? Any other ideas or suggestions would be great. Thanks for your time.

Brian
V odpovědi na Brian Williams

Re: Unsupported contextlevel in category record!

autor André Gonzaga -

Brian,

It's a little bit later do aswer that but i solved it this week. I has same problem so I studied this part to understand it.

When I upgraded my moodle version to 1.9.8 some necessaries values was lost in table question_categories like contextid. So I ran a sql command to solve that. The command is:  UPDATE question_categories qc SET qc.contextid=( SELECT c.id FROM context c WHERE c.contextlevel=50 AND c.instanceid=qc.course )

V odpovědi na André Gonzaga

Re: Unsupported contextlevel in category record!

autor Freyr Gunnar Ólafsson -

I tried your suggestion (though I had to motify it a little) but it didn't work.

UPDATE mdl_question_categories qc SET qc.contextid=( SELECT c.id FROM mdl_context c WHERE c.contextlevel=50 AND c.instanceid=qc.course );
ERROR 1054 (42S22): Unknown column 'qc.course' in 'where clause'

Could someone please help me with this?

V odpovědi na Freyr Gunnar Ólafsson

Re: Unsupported contextlevel in category record!

autor Divya Bansal -

I am having the same problem. I am having the test site for the same. The data is just a month old on test site and test site is working fine, but seeing same error on the live site.

V odpovědi na Divya Bansal

Re: Unsupported contextlevel in category record!

autor Divya Bansal -

This might be helpful, my moodle version is 1.9.10

Stack trace:

  • line 1664 of lib\deprecatedlib.php: call to debugging()
  • line 2351 of lib\questionlib.php: call to error()
  • line 1513 of lib\questionlib.php: call to get_filesdir_from_context()
  • line 155 of question\type\truefalse\questiontype.php: call to get_question_image()
  • line 19 of question\type\question.html: call to question_truefalse_qtype -> print_question_formulation_and_controls()
  • line 894 of questions\type\questiontype.php: call to include()
  • line 1726 of lib\questionlib/php: call to question_truefalse_qtype -> print_question()
  • line 503 of mod\quiz\attempt.php: call to print_question()
V odpovědi na Divya Bansal

Re: Unsupported contextlevel in category record!

autor Tim Hunt -
Obrázek: Core developers Obrázek: Documentation writers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers

Can you track down which question this is?

Then look in the mdl_question table to get the category id.

Then look in the mdl_question_categories table to get the contextid.

Then look in the mdl_context table. I bet you will find that there is no context with that id.

V odpovědi na Tim Hunt

Re: Unsupported contextlevel in category record!

autor Divya Bansal -

Thanks Tim! You are absolutely right if what I am doing is correct procedure úsměv

I clicked on Edit tab on the same quiz page which was throwing error and looked for the first question. And once I got the question text this is what I did

  • SELECT * FROM moodle.mdl_question m where name like '%Do you wish to receive%';
  • SELECT * FROM moodle.mdl_question_categories m where id = '106';
  • SELECT * FROM moodle.mdl_context c where id='7294';

And the last statement returned nothing. I am wondering what would have happened on the live site which might have messed it up? As test site and live site are essentially same just data is about a month old. And on the live site, I am seeing this error for pretty much all the quiz I have tested so far.

If this information is any help, the category id for the same question on test site was different. Is the administrator using the wrong procedure to change the category for question? How do we change the category for question? Or it happened while upgrades of moodle versions?

What should I do now, to fix this issue?

V odpovědi na Divya Bansal

Re: Unsupported contextlevel in category record!

autor Tim Hunt -
Obrázek: Core developers Obrázek: Documentation writers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers

Not really sure what will have caused the ids to change on the live server. It is not necessarily a problem.

If you are careful (that is, take a backup first) you should be able to fix it by editing the values in the question_categories.contextid column to point at the right context.id.

Suppose the questions in the category with id 123 should be in course CF101. And suppose CF101 is the course with id 67.

Then SELECT * FROM mdl_context WHERE contextlevel = 50 AND instanceid = 67; will let you see the contextid for that course. Suppose it is 2345

Then, UPDATE mdl_question_categories SET contextid = 2345 WHERE id = 123;

Should get the questions back were they are supposed to be. You need to do this for each messed up category.

V odpovědi na Tim Hunt

Re: Unsupported contextlevel in category record!

autor Arturo Hale -

Hello,

I am having the same problem with quizzes that are a couple of months old.  I do not understand how to run the commands you have posted.  Could you post an explanation for dummies?

Message to Moodle developers:  COULD SOMEBODY JUST FIX THE PROBLEM?

I spend a lot of time developing quizzes and I plan on re-using them; my students need them to study for the final exam.  What's the point if all my work is lost after two months??