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

Error on /course/management.php when visible categories list is empty

XMLWordPrintable

    • MOODLE_37_STABLE
    • MOODLE_37_STABLE
    • MDL-66336_master
    • Hide
      1. Remove moodle/category:viewcourselist from the guest and authenticated user role
      2. Log in as a user with no additional roles in the system context.
      3. Go to "/course/management.php"
      4. You should see the error "There are no categories visible to you on this site."
      Show
      Remove moodle/category:viewcourselist from the guest and authenticated user role Log in as a user with no additional roles in the system context. Go to "/course/management.php" You should see the error "There are no categories visible to you on this site."

      Steps to reproduce:

      1. Remove moodle/category:viewcourselist from all roles
      2. Log in to Moodle
      3. Navigate to Site Administration > Courses > Manage courses and categories

      The error below is displayed:

      Notice: Trying to get property of non-object in /blah/course/management.php on line 74
       
      Can't find data record in database table course_categories.
      More information about this error
       
      Debug info: SELECT id,parent FROM {course_categories} WHERE id IS NULL
      [array (
      )]
      Error code: invalidrecord
       
      Stack trace:
       
      line 1546 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
      line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      line 6643 of /lib/accesslib.php: call to moodle_database->get_record()
      line 74 of /course/management.php: call to context_coursecat::instance()
      

      Without this permission, core_course_category::top()->get_children(); returns an empty array.

       69   $course = null;
       70   $courseid = null;
       71   $topchildren = core_course_category::top()->get_children();
       72   $category = reset($topchildren);
       73   $categoryid = $category ? $category->id : 0;
       74   $context = context_coursecat::instance($category->id);
       75   $url->param('categoryid', $category->id); 

      If line 71 returns an empty array, $category will be set to false on line 72. Line 74 uses $category->id, not $categoryid which has been set to 0 in this case. Since $category is false, $category->id does not exist.

            marxjohnson Mark Johnson
            marxjohnson Mark Johnson
            Sam Marshall Sam Marshall
            Jun Pataleta Jun Pataleta
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 51 minutes
                51m

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