Moodle
  1. Moodle
  2. MDL-12667

Quiz/question broken after changing categories

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not a bug
    • Affects Version/s: 1.9
    • Fix Version/s: None
    • Component/s: Questions
    • Labels:
      None
    • Environment:
      Linux plaza 2.4.33, apache 1.3.37, mysql 5.0.45, php 4.4.7
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_19_STABLE
    • Rank:
      9298

      Description

      After removing a category, so that all courses where moved to the top category, the quiz/question module was broken for those courses who had changed level from a sub category to the top level.

      When trying to add a new question(by clicking on question in the admin block in the course) we get the following message:

      "This is an unknown context () in print_context_name!"

      and are then being redirected to the frontpage.

      Making a backup of the course and restoring it to a new course solves the problem.

        Activity

        Hide
        Tim Hunt added a comment -

        Thanks for the report. I can't immediately think what the problem might be. Jamie, any thoughts?

        Show
        Tim Hunt added a comment - Thanks for the report. I can't immediately think what the problem might be. Jamie, any thoughts?
        Hide
        Madeleine Graley added a comment -

        This problem is also occurring when, from the mod/quiz/index page, I click on the course name and on 'edit questions.' Can't believe moodle is not flooded with this issue!

        Show
        Madeleine Graley added a comment - This problem is also occurring when, from the mod/quiz/index page, I click on the course name and on 'edit questions.' Can't believe moodle is not flooded with this issue!
        Hide
        Tim Hunt added a comment -

        I suspect that people only very rarely delete course categories, which is why no-one else has reported this. I have some thoughts about what might be going on (the question categories are probably still pointing at the deleted category context). Now I just need to work out how to fix it, and find the time to do so.

        Show
        Tim Hunt added a comment - I suspect that people only very rarely delete course categories, which is why no-one else has reported this. I have some thoughts about what might be going on (the question categories are probably still pointing at the deleted category context). Now I just need to work out how to fix it, and find the time to do so.
        Hide
        Madeleine Graley added a comment -

        I should clarify, Tim. I am building a course from scratch and this error message is appearing when I attempt to edit questions in a quiz. I haven't deleted any categories.
        Madeleine

        Show
        Madeleine Graley added a comment - I should clarify, Tim. I am building a course from scratch and this error message is appearing when I attempt to edit questions in a quiz. I haven't deleted any categories. Madeleine
        Hide
        Jeffery Watkins added a comment -

        I am having this problem now also. New course, create a new quiz, get that error. Just updated to MOODLE_19_WEEKLY today from 1.9+

        Jeff

        Show
        Jeffery Watkins added a comment - I am having this problem now also. New course, create a new quiz, get that error. Just updated to MOODLE_19_WEEKLY today from 1.9+ Jeff
        Hide
        Tim Hunt added a comment -

        It would be helpful if you could run some consistency checks on your database, they re documented here http://docs.moodle.org/en/Development:Question_bank_consistency_check, and the relevant ones are "Question categories should all belong to a valid context" and "Question categories should belong to the same context as their parent".

        Also, it would be useful to find out exactly where that error message is being triggered. If you could go to Admin -> Server -> Debugging, and set Debug messages to DEVELOPER, and turn on Display debug messages. Then along with the error message, you should get a stack trace. It would be helpful if you could copy and paste that here.

        Show
        Tim Hunt added a comment - It would be helpful if you could run some consistency checks on your database, they re documented here http://docs.moodle.org/en/Development:Question_bank_consistency_check , and the relevant ones are "Question categories should all belong to a valid context" and "Question categories should belong to the same context as their parent". Also, it would be useful to find out exactly where that error message is being triggered. If you could go to Admin -> Server -> Debugging, and set Debug messages to DEVELOPER, and turn on Display debug messages. Then along with the error message, you should get a stack trace. It would be helpful if you could copy and paste that here.
        Hide
        Tim Hunt added a comment -

        Well, I am definitely not seeing this. I have just checked. I updated to the latest 1.9 version, created a new course, added a new quiz, the tried adding a new question to the quiz, and it all worked.

        So, why is it not working for some people?

        Show
        Tim Hunt added a comment - Well, I am definitely not seeing this. I have just checked. I updated to the latest 1.9 version, created a new course, added a new quiz, the tried adding a new question to the quiz, and it all worked. So, why is it not working for some people?
        Hide
        Jeffery Watkins added a comment -

        Tim,

        The docs link was to an empty page. But, here is the debug info from my site:

        Incorrect context specified

        • line 350 of lib/accesslib.php: call to debugging()
        • line 746 of question/editlib.php: call to has_capability()
        • line 783 of question/editlib.php: call to question_edit_contexts->having_cap()
        • line 794 of question/editlib.php: call to question_edit_contexts->have_cap()
        • line 808 of question/editlib.php: call to question_edit_contexts->have_one_cap()
        • line 837 of question/editlib.php: call to question_edit_contexts->have_one_edit_tab_cap()
        • line 618 of question/editlib.php: call to question_edit_contexts->require_one_edit_tab_cap()
        • line 88 of mod/quiz/edit.php: call to question_edit_setup()

        This is an unknown context () in print_context_name!
        Stack trace:

        • line 1651 of lib/deprecatedlib.php: call to debugging()
        • line 3366 of lib/accesslib.php: call to error()
        • line 1892 of lib/questionlib.php: call to print_context_name()
        • line 667 of question/editlib.php: call to question_make_default_categories()
        • line 88 of mod/quiz/edit.php: call to question_edit_setup()
        Show
        Jeffery Watkins added a comment - Tim, The docs link was to an empty page. But, here is the debug info from my site: Incorrect context specified line 350 of lib/accesslib.php: call to debugging() line 746 of question/editlib.php: call to has_capability() line 783 of question/editlib.php: call to question_edit_contexts->having_cap() line 794 of question/editlib.php: call to question_edit_contexts->have_cap() line 808 of question/editlib.php: call to question_edit_contexts->have_one_cap() line 837 of question/editlib.php: call to question_edit_contexts->have_one_edit_tab_cap() line 618 of question/editlib.php: call to question_edit_contexts->require_one_edit_tab_cap() line 88 of mod/quiz/edit.php: call to question_edit_setup() This is an unknown context () in print_context_name! Stack trace: line 1651 of lib/deprecatedlib.php: call to debugging() line 3366 of lib/accesslib.php: call to error() line 1892 of lib/questionlib.php: call to print_context_name() line 667 of question/editlib.php: call to question_make_default_categories() line 88 of mod/quiz/edit.php: call to question_edit_setup()
        Hide
        Tim Hunt added a comment -

        The problem with the link is that JIRA includes the following comma in the link. Must be a minor bug in JIRA's autolinking.

        Anyway, something seems to be wrong with the contexts. Can you look in the mdl_context table, and see whether all the rows have path and depth set properly. Path should look like /1/..., and depth should be a number greater than or equal to 1. Also, every number mentioned in a path should be a valid contextid.

        Show
        Tim Hunt added a comment - The problem with the link is that JIRA includes the following comma in the link. Must be a minor bug in JIRA's autolinking. Anyway, something seems to be wrong with the contexts. Can you look in the mdl_context table, and see whether all the rows have path and depth set properly. Path should look like /1/..., and depth should be a number greater than or equal to 1. Also, every number mentioned in a path should be a valid contextid.
        Hide
        Jeffery Watkins added a comment -

        Tim,

        I ran the two queries from above. The ...valid context one returned 9 results. The other returned no results.

        I also looked at the table as you suggested and it looked ok, but I am unsure how to easily check id every number in the path is valid... Can you advise?

        Thanks,

        Jeff

        Show
        Jeffery Watkins added a comment - Tim, I ran the two queries from above. The ...valid context one returned 9 results. The other returned no results. I also looked at the table as you suggested and it looked ok, but I am unsure how to easily check id every number in the path is valid... Can you advise? Thanks, Jeff
        Hide
        Tim Hunt added a comment -

        If you look at the link to the quiz in the course, it will have a URL of the form .../mod/quiz/view.php?id=12345

        If you then do

        SELECT * FROM mdl_context WHERE contextlevel = 70 and instanceid = 12345

        where 12345 is the id from the URL, then that will give you the context of the quiz that is giving problems. Can you just check the few other contexts in its path by hand?

        Show
        Tim Hunt added a comment - If you look at the link to the quiz in the course, it will have a URL of the form .../mod/quiz/view.php?id=12345 If you then do SELECT * FROM mdl_context WHERE contextlevel = 70 and instanceid = 12345 where 12345 is the id from the URL, then that will give you the context of the quiz that is giving problems. Can you just check the few other contexts in its path by hand?
        Hide
        Jeffery Watkins added a comment -

        Tim,

        Did as you asked and it returned: /1/437/538/60/708

        Contextid 437 does not exist in the database...

        Jeff

        Show
        Jeffery Watkins added a comment - Tim, Did as you asked and it returned: /1/437/538/60/708 Contextid 437 does not exist in the database... Jeff
        Hide
        Tim Hunt added a comment -

        Right, so that will be the root of the problem. And actually that means it is a roles system problem. It would be good if Tormod and Madeleine are able to determine whether their problem comes from the same underlying cause.

        There is a way to sort out all the context paths if they get screwed up. You write a script that says

        <?php
        require_once('config.php');
        require_login();
        require_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM));
        build_context_path(true, true);
        echo 'Done';
        ?>

        call it something like fixpaths.php

        then go to http://example.com/moodle/fixpaths.php to execute it.

        Show
        Tim Hunt added a comment - Right, so that will be the root of the problem. And actually that means it is a roles system problem. It would be good if Tormod and Madeleine are able to determine whether their problem comes from the same underlying cause. There is a way to sort out all the context paths if they get screwed up. You write a script that says <?php require_once('config.php'); require_login(); require_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM)); build_context_path(true, true); echo 'Done'; ?> call it something like fixpaths.php then go to http://example.com/moodle/fixpaths.php to execute it.
        Hide
        Jeffery Watkins added a comment -

        That did the trick for me Tim.

        Thanks for all your help.

        Jeff

        Show
        Jeffery Watkins added a comment - That did the trick for me Tim. Thanks for all your help. Jeff
        Hide
        Madeleine Graley added a comment -

        I don't have the tech skills to do the diagnostics but I tried the 'fixpaths' . This resolved to the login page,. I get the same error whether I click on 'questions' or 'edit questions' in quizzes.
        Madeleine

        Show
        Madeleine Graley added a comment - I don't have the tech skills to do the diagnostics but I tried the 'fixpaths' . This resolved to the login page,. I get the same error whether I click on 'questions' or 'edit questions' in quizzes. Madeleine
        Hide
        Tim Hunt added a comment -

        Do you have access to any technical support that could perform these checks for you? It is hard for me to do anything about this bug without more information.

        Show
        Tim Hunt added a comment - Do you have access to any technical support that could perform these checks for you? It is hard for me to do anything about this bug without more information.
        Hide
        Madeleine Graley added a comment -

        Ah, Tim, no. I'm stuck with no money. In fact I looked in detail at three or four other open source learning systems today but they had equivalent levels of major problems as Moodle. So I have reluctantly decided to abandon my project (online education for people with bipolar disorder, their partners and their doctors) because I can't find a system I can operate.

        Good luck with this good work and thanks for the assistance.

        Show
        Madeleine Graley added a comment - Ah, Tim, no. I'm stuck with no money. In fact I looked in detail at three or four other open source learning systems today but they had equivalent levels of major problems as Moodle. So I have reluctantly decided to abandon my project (online education for people with bipolar disorder, their partners and their doctors) because I can't find a system I can operate. Good luck with this good work and thanks for the assistance.
        Hide
        Jairo Serrano added a comment -

        Thanks Tim Hunt,

        Works for me on weekly moodle 1.9.2+

        Show
        Jairo Serrano added a comment - Thanks Tim Hunt, Works for me on weekly moodle 1.9.2+
        Hide
        Jamie Pratt added a comment -

        "I don't have the tech skills to do the diagnostics but I tried the 'fixpaths' . This resolved to the login page,. I get the same error whether I click on 'questions' or 'edit questions' in quizzes.
        Madeleine"

        Hi Madeleine,

        I think that the script above has not executed properly because you operated it without logging in.

        require_login();

        Would send you to the login page.

        So login and try the script again.

        Hope you have not given up already.

        Jamie

        Show
        Jamie Pratt added a comment - "I don't have the tech skills to do the diagnostics but I tried the 'fixpaths' . This resolved to the login page,. I get the same error whether I click on 'questions' or 'edit questions' in quizzes. Madeleine" Hi Madeleine, I think that the script above has not executed properly because you operated it without logging in. require_login(); Would send you to the login page. So login and try the script again. Hope you have not given up already. Jamie
        Hide
        scott hallman added a comment -

        We too are experiencing a similar bug where we can't create new questions without going back to the course page and then back into quix or question bank. Also we can't create any new questions in a new category we create and have to move them after into the category instead. This is very time consuming so we are not able do training on quizzes at the moment. we move from 1.8 to 1.9.2 and are on a windows server using my sql.

        Show
        scott hallman added a comment - We too are experiencing a similar bug where we can't create new questions without going back to the course page and then back into quix or question bank. Also we can't create any new questions in a new category we create and have to move them after into the category instead. This is very time consuming so we are not able do training on quizzes at the moment. we move from 1.8 to 1.9.2 and are on a windows server using my sql.
        Hide
        Tim Hunt added a comment -

        Scott, have you checked your mysql database for corruption? http://docs.moodle.org/en/Administration_FAQ#How_do_I_repair_a_corrupted_Moodle_database.3F.

        Also, have you checked your upgrade logs to make sure there were no errors during the upgrade? (They are in $CFG->dataroot/upgradelogs.

        Show
        Tim Hunt added a comment - Scott, have you checked your mysql database for corruption? http://docs.moodle.org/en/Administration_FAQ#How_do_I_repair_a_corrupted_Moodle_database.3F . Also, have you checked your upgrade logs to make sure there were no errors during the upgrade? (They are in $CFG->dataroot/upgradelogs.
        Hide
        Tim Hunt added a comment -

        From what is said here, and from other instances that have come up in the quiz forum, it seems that this is always an issue with corrupted context paths. It is just that the quiz UI is one of the few places that triggers an error message as the result of broken context paths. The solution is to make a scrip that call the build_context_paths function to force a rebuild of all context paths.

        So, not actually a quiz bug.

        Show
        Tim Hunt added a comment - From what is said here, and from other instances that have come up in the quiz forum, it seems that this is always an issue with corrupted context paths. It is just that the quiz UI is one of the few places that triggers an error message as the result of broken context paths. The solution is to make a scrip that call the build_context_paths function to force a rebuild of all context paths. So, not actually a quiz bug.
        Hide
        miki Alliel added a comment -

        Hey Tim
        I have Moodle 1.9.9 and suddenly
        I have the same problem - after I changed some categories and moved some courses to different categories - the quizzes started to behave strange they corrupt when clicking "edit" tab and when clicking on course "questions" - I had this error too..

        I tried your fixpaths.php and it fixed everything.

        But I don't get it how come it is not a bug?
        Is that going to happen me again ? if I'm going to changes course categories again?

        Show
        miki Alliel added a comment - Hey Tim I have Moodle 1.9.9 and suddenly I have the same problem - after I changed some categories and moved some courses to different categories - the quizzes started to behave strange they corrupt when clicking "edit" tab and when clicking on course "questions" - I had this error too.. I tried your fixpaths.php and it fixed everything. But I don't get it how come it is not a bug? Is that going to happen me again ? if I'm going to changes course categories again?
        Hide
        miki Alliel added a comment -

        After doing this

        I'm getting errors in the participants page of a course:

        Notice: Undefined index: in /var/www/html/moodle/lib/datalib.php on line 1008 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1008 Notice: Undefined index: 136 in /var/www/html/moodle/lib/datalib.php on line 1024 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1024
        Incorrect context specified

        line 376 of lib/accesslib.php: call to debugging()
        line 1025 of lib/datalib.php: call to has_capability()
        line 200 of user/index.php: call to get_my_courses()

        Notice: Undefined index: 143 in /var/www/html/moodle/lib/datalib.php on line 1024 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1024
        Incorrect context specified

        line 376 of lib/accesslib.php: call to debugging()
        line 1025 of lib/datalib.php: call to has_capability()
        line 200 of user/index.php: call to get_my_courses

        why? and how can I fix it?

        Thank you

        Show
        miki Alliel added a comment - After doing this I'm getting errors in the participants page of a course: Notice: Undefined index: in /var/www/html/moodle/lib/datalib.php on line 1008 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1008 Notice: Undefined index: 136 in /var/www/html/moodle/lib/datalib.php on line 1024 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1024 Incorrect context specified line 376 of lib/accesslib.php: call to debugging() line 1025 of lib/datalib.php: call to has_capability() line 200 of user/index.php: call to get_my_courses() Notice: Undefined index: 143 in /var/www/html/moodle/lib/datalib.php on line 1024 Notice: Trying to get property of non-object in /var/www/html/moodle/lib/datalib.php on line 1024 Incorrect context specified line 376 of lib/accesslib.php: call to debugging() line 1025 of lib/datalib.php: call to has_capability() line 200 of user/index.php: call to get_my_courses why? and how can I fix it? Thank you

          People

          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: