Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-17651

create_context() failing

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.9.3
    • 1.9.4
    • Quiz
    • None
    • Any
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE

    Description

      I am using the latest Moodle from today (20081215). When I create a new quiz activity, add a question to it (any question type) and the click "Preview", I get this error:

      Error: could not insert new context level "70", instance "67".

      • line 2189 of lib/accesslib.php: call to debugging()
      • line 2465 of lib/accesslib.php: call to create_context()
      • line 831 of question/type/questiontype.php: call to get_context_instance()
      • line 1708 of lib/questionlib.php: call to default_questiontype->print_question()
      • line 495 of mod/quiz/attempt.php: call to print_question()

      That error appears for each question on the quiz. I have debugging set to ALL and display_debug turned on.

      The problem seems to be in the create_context() function in lib/accesslib.php, where the query is joining quiz.id with course_modules.id, rather than course_modules.instance.

      Here is a patch which fixes the problem for me:

      diff --git a/lib/accesslib.php b/lib/accesslib.php
      index 5f1fe50..5097feb 100755
      — a/lib/accesslib.php
      +++ b/lib/accesslib.php
      @@ -2123,7 +2123,7 @@ function create_context($contextlevel, $instanceid) {
      FROM {$CFG->prefix}context ctx
      JOIN {$CFG->prefix}course_modules cm
      ON (cm.course=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")

      • WHERE cm.id={$instanceid}";
        + WHERE cm.instance={$instanceid}";
        if ($p = get_record_sql($sql)) {
        $basepath = $p->path;
        $basedepth = $p->depth;

      Can anyone verify this? It looks to me like the SQL join is incorrect - the course module ID is not meant to match the ID of the module instance.

      Cheers
      Ashley

      Attachments

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              ashleyholman Ashley Holman
              Tim Hunt, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                28/Jan/09