This is an unknown context () in get_parent_contexts!

This is an unknown context () in get_parent_contexts!

by Yitex Mesh -
Number of replies: 1
Hi
I am new to moodle and i am facing a problem.
We are using Moodle in the intranet of our trainig centre and moodle was functioning normally until recently where the following sentence appears after the creation of a course : "Sorry, but that course is not a valid context". I can see the course is created but can not access it.

Another problem i can no longer see all the courses that were created before in the front page after signing on as an administrator but rather see only the name of the course and this error sentence : "This is an unknown context () in get_parent_contexts"!

Thanks for any help that i may get.
Yitex
Average of ratings: -
In reply to Yitex Mesh

Re: This is an unknown context () in get_parent_contexts!

by Richard Enison -
YM,

The two errors are related. I haven't fully researched the second one, but I've got a pretty good idea about the first. I think it has to do with the database.

Here's the story. The error msg. occurs in only one place in Moodle, and that is course/view.php (no surprise there!). In what follows I will assume you accepted the default table prefix (mdl_); if not, just replace mdl_ with your prefix.

For every course there should be a row (record) in the mdl_course table. If you look in that table, for any particular course, you should be able to find the id number for that course in the id field (column; its the first). There should also be a row in mdl_context in which the contextlevel column is 50 and the instanceid column matches the id column in the mdl_course table. The script view.php looks for that row and if it doesn't find it, creates it. Either way, you shouldn't get that error. But if it can't create it, you get another error msg. if you have debug set to at least DEBUG_NORMAL (see http://docs.moodle.org/en/Debugging). So I would suggest you do that and see what happens. You might also want to look in the mdl_course and mdl_context tables and see if anything is missing.

In the course of trying to create the row in mdl_context, it looks into the category for the course as the parent of the course, for which there should be a row in the mdl_course_categories table (the second column, category, of the mdl_course table should match the first column, id, of that table) as well as a row in mdl_context in which the contextlevel column is 40 and instanceid matches the id from the mdl_course_categories table. Which is why I said the second error msg. mentioned in your post is related.

RLE