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

Invalid creatornewroleid config causes exceptions during course creation

XMLWordPrintable

    • MOODLE_400_STABLE
    • MOODLE_400_STABLE, MOODLE_401_STABLE
    • MDL-76536-401
    • Hide

      Note: testing is easier when performing on a brand new site

      Prior to checking out the fix

      1. Add the following to site config.php:

        $CFG->creatornewroleid = 123;
        

      2. Log in as admin
      3. Create a new course (via Courses > Add a new course in site administration)
      4. You'll get an exception (expected)
      5. Manually navigate to the course
      6. Visit Participants
      7. Assign Admin User the Non-editing teacher role and save
      8. Execute the following SQL query in database terminal:

        SELECT * FROM moodle.m_role_assignments;
        

      9. Note there are two rows returned, one with roleid=123 and the other with roleid=4

      After checking out fixed branch

      1. Run upgrade step when prompted
      2. Re-execute the previous SQL query
      3. Confirm the row with roleid=123 has been deleted
      4. Confirm the row with roleid=4 is still present
      5. Create a new course (via Courses > Add a new course in site administration)
      6. Confirm the course is created without exceptions
      7. Remove the following from site config.php:

        $CFG->creatornewroleid = 123;
        

      8. Create a new course (via Courses > Add a new course in site administration)
      9. Navigate to course participants
      10. Confirm Admin User was enrolled with role Teacher
      Show
      Note: testing is easier when performing on a brand new site Prior to checking out the fix Add the following to site config.php : $CFG->creatornewroleid = 123; Log in as admin Create a new course (via Courses > Add a new course in site administration) You'll get an exception (expected) Manually navigate to the course Visit Participants Assign Admin User the Non-editing teacher role and save Execute the following SQL query in database terminal: SELECT * FROM moodle.m_role_assignments; Note there are two rows returned, one with roleid=123 and the other with roleid=4 After checking out fixed branch Run upgrade step when prompted Re-execute the previous SQL query Confirm the row with roleid=123 has been deleted Confirm the row with roleid=4 is still present Create a new course (via Courses > Add a new course in site administration) Confirm the course is created without exceptions Remove the following from site config.php : $CFG->creatornewroleid = 123; Create a new course (via Courses > Add a new course in site administration) Navigate to course participants Confirm Admin User was enrolled with role Teacher
    • HQ Sprint 1.2 Moppies

      As discovered in this forum thread

      Having an invalid value for $CFG->creatornewroleid, either because it was configured for a role which was subsequently deleted, or if manually set in config.php (easiest way to reproduce), causes the following errors during course creation:

      Warning

      Warning: Undefined array key 123 in /var/www/html/lib/classes/event/role_assigned.php
      on line 108
       
      Warning: Undefined array key 123 in /var/www/html/lib/accesslib.php on line 4611
      

      Exception

      Exception - role_get_name(): Argument #1 ($role) must be of type stdClass, null given, called in [dirroot]/lib/accesslib.php on line 4630
       
      More information about this error
      Debug info:
      Error code: generalexceptionmessage
      Stack trace:
       
          line 4464 of /lib/accesslib.php: TypeError thrown
          line 4630 of /lib/accesslib.php: call to role_get_name()
          line 109 of /lib/classes/event/role_assigned.php: call to role_fix_names()
          line 813 of /lib/classes/event/base.php: call to core\event\role_assigned->get_legacy_logdata()
          line 1629 of /lib/accesslib.php: call to core\event\base->trigger()
          line 2118 of /lib/enrollib.php: call to role_assign()
          line 1216 of /lib/enrollib.php: call to enrol_plugin->enrol_user()
          line 184 of /course/edit.php: call to enrol_try_internal_enrol()
      

      Subsequently accessing the course via "Manage course categories and courses" in site administration produces the following warning:

      Warning: Undefined array key 123 in /var/www/html/course/classes/management/helper.php on line 120
       
      Warning: Attempt to read property "localname" on null in /var/www/html/course/classes/management/helper.php on line 120
      

      We need to

      1. Prevent this happening again;
      2. Clean up invalid role assignment records (because despite the exception, the invalid role assignment record was created)

        1. (I) 10 Passed -- (400)MDL-76536.png
          78 kB
          Kim Jared Lucas
        2. (I) 10 Passed -- (401)MDL-76536.png
          78 kB
          Kim Jared Lucas
        3. (I) 10 Passed -- (Master)MDL-76536.png
          84 kB
          Kim Jared Lucas
        4. (I) 3,4 Passed -- (400)MDL-76536.png
          26 kB
          Kim Jared Lucas
        5. (I) 3,4 Passed -- (401)MDL-76536.png
          14 kB
          Kim Jared Lucas
        6. (I) 3,4 Passed -- (Master)MDL-76536.PNG
          17 kB
          Kim Jared Lucas
        7. (I) 6 Passed -- (400)MDL-76536.png
          41 kB
          Kim Jared Lucas
        8. (I) 6 Passed -- (401)MDL-76536.png
          46 kB
          Kim Jared Lucas
        9. (I) 6 Passed -- (Master)MDL-76536.PNG
          50 kB
          Kim Jared Lucas

            pholden Paul Holden
            pholden Paul Holden
            Carlos Escobedo Carlos Escobedo
            Huong Nguyen Huong Nguyen
            Kim Jared Lucas Kim Jared Lucas
            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 - 5 hours
                5h

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