Health and "Question categories should belong to a valid context" with Moodle 2.7

Health and "Question categories should belong to a valid context" with Moodle 2.7

by Séverin Terrier -
Number of replies: 8
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hello,

More than 2 years ago, i asked question about health.php in Moodle 1.9, and "Question categories should belong to a valid context" error. Finally, i hadn't corrected everything sad

We installed in june 2013 a new Moodle 2.4 platform, but taken backups from our old 1.9 Moodle (started with Moodle 1.4 or 1.5, and upgraded with 1.6 and 1.8). Last year, we upgraded to 2.7. So, i'm now on Moodle 2.7.4, and i still have these problems.

When i run moodle/admin/tool/health on one of my Moodle instances, i have 1 category (id=87) without a valid context, that contains 4 questions.

To have details, i've run :

SELECT id, category, qtype, from_unixtime(timecreated) AS created, createdby, from_unixtime(timemodified) AS modified, modifiedby, name, questiontext FROM mdl_question WHERE category IN (87);

It shows me these questions : 516,517,518,519

I've run these commands, to check :

SELECT COUNT(1) FROM mdl_question_answers WHERE question IN (516,517,518,519);
SELECT COUNT(1) FROM mdl_question_attempts WHERE questionid IN (516,517,518,519);

It returns nothing, so i think i can modify the category, to point to a new dedicated (temporary) course, and then delete these questions.

Are my requests Ok? Do i have to check other tables (before deleting things)?

Don't hesitate to provide more details and/or tools that could help me to correct problems in my Moodle DB.

Thanks in advance,

Séverin

Average of ratings: -
In reply to Séverin Terrier

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That all sounds correct.

(Please proceed carefully, and have backups.)

In reply to Tim Hunt

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Thanks Tim for the confirmation.

I've also run:

SELECT COUNT(1) FROM mdl_quiz_slots WHERE questionid IN (516,517,518,519);

With 0 results, good ! So, i'll soon delete unwanted questions...


When searching for information, i've found this doc page :

https://docs.moodle.org/dev/Question_bank_consistency_check

It seems to be 1.9 related (and from 2008/2009). Are some/all information here still actual and usable for Moodle 2.7?

In reply to Séverin Terrier

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think all those checks are still valid.

Scary how little has changed wink but also, in a way good, that Moodle is quite a stable platform.

If any of those checks do not fully work, it is probalby just something trivial like a column that has been renamed.

In reply to Tim Hunt

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

I'll try the other requests in some days.

To correct my problem, i use a specific course (id=2), and search the corresponding context :

SELECT id FROM mdl_context WHERE contextlevel = 50 AND instanceid = 2;

The context is : 18

I so update the concerned question category (id=87), to attach it to my course :

UPDATE mdl_question_categories SET contextid=18 WHERE id = 87;

Now, i can find in my course (id=2), the question category (and included questions), to remove them all sourire

After that, i've no more this error in moodle/admin/tool/health sourire

Séverin
In reply to Séverin Terrier

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

On another platform, i've got the same problem, with more categories (6) and questions (20).

I've run the same check requests, and only the one on mdl_question_answers return results.

Am i right to suppose answers are part of the questions, and that's not a problem, because they will be deleted if/when i'll delete question via Moodle web interface?

Séverin

In reply to Séverin Terrier

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That sounds correct, yes.

In reply to Tim Hunt

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

After making all the necessary, and deleting the questions, the related lines have been deleted in mdl_question_answers smile

In reply to Tim Hunt

Re: Health and "Question categories should belong to a valid context" with Moodle 2.7

by Patrick Lemaire -
Picture of Particularly helpful Moodlers Picture of Testers
Hello there,

Has someone any idea on what happens in database about questions ?

I'd made the same checks and found the same problems (differents ID of course). I think they may come from imported courses but I'm not sure. How could this happen ?

Thanks.
Patrick