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

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

    XMLWordPrintable

    Details

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                marxjohnson Mark Johnson
                Reporter:
                marxjohnson Mark Johnson
                Peer reviewer:
                Sam Marshall
                Integrator:
                Jun Pataleta
                Tester:
                Janelle Barcega
                Participants:
                Component watchers:
                Amaia Anabitarte, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón, Amaia Anabitarte, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  9/Sep/19

                  Time Tracking

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