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

Coding error exception caused by hidden category with parent=0 when $CFG->navshowmycoursecategories is true

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 2.3.1
    • Navigation
    • MOODLE_23_STABLE

      If the setting $CFG->navshowmycoursecategories is turned on in Site Administration->Appearance->Navigation, and at least one of the course categories on the top level ($category->parent = 0), is set as hidden, attempting to load any page on the Moodle application will result in the following error message:

      "Coding error detected, it must be fixed by a programmer"

      Upon further investigation, I found that this error was being triggered on line 1134 of file navigationlib.php, in function initialise(). Since this library file is loaded on every request, this error gets triggered every time. Below is the segment of code where the error occurs:

      if (!$category->visible) 
      {
         if (!has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_COURSECAT, $category->parent))) {
             $addedcategories[$category->id]->display = false;
         } else {
             $addedcategories[$category->id]->hidden = true;
         }
      }

      The exact problem is that the following function call returns bool(false) if $category->parent is set as 0:

      get_context_instance(CONTEXT_COURSECAT, $category->parent)

      This triggers an exception in function has_capability because it expects its 2nd parameter to be of type "context"

            samhemelryk Sam Hemelryk
            rstewart78 Ron Stewart
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.