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

Enrolment lib function enrol_course_delete bug is blocking course content deletion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Minor Minor
    • None
    • 3.8.6, 3.9.3, 3.10
    • Enrolments

      We came across this issue when trying to restore course A by overwriting existing course B. Course B had disabled guest enrollment method. Guest enrollment method is also disabled at site level. In such case, when doing restore we get error:

      PHP Notice: Undefined index: guest in /opt/.../lib/enrollib.php on line 1111
      Default exception handler: Exception - Call to a member function allow_unenrol() on null Debug: \nError code: generalexceptionmessage\n* line 1111 of /lib/enrollib.php: Error thrown\n* line ? of unknownfile: call to {closure}()\n* line 1113 of /lib/enrollib.php: call to array_filter()\n* line 5323 of /lib/moodlelib.php: call to enrol_course_delete()\n* line 1843 of /backup/util/dbops/restore_dbops.class.php: call to remove_course_contents()\n* line 366 of /backup/controller/restore_controller.class.php: call to restore_dbops::delete_course_content()\n* line 219 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()\n* line 143 of /backup/restore.php: call to restore_ui->execute()\n

      The error is caused by the bug in lib/enrollib.php:

      function enrol_course_delete($course, $userid = null) {
      global $DB;

      $context = context_course::instance($course->id);
      $instances = enrol_get_instances($course->id, false);
      $plugins = enrol_get_plugins(true);

      if ($userid) {
      // If the user id is present, include only course enrolment instances which allow manual unenrolment and // the given user have a capability to perform unenrolment. $instances = array_filter($instances, function($instance) use ($userid, $plugins, $context) {
      $unenrolcap = "enrol/{{color:#660000}$instance->enrol{color}}:unenrol";
      return $plugins[$instance->enrol]->allow_unenrol($instance) &&
      has_capability($unenrolcap, $context, $userid);
      });
      }

      $plugins uses only enabled plugins and $instances are using all enrollment methods (disabled also). This means disabled plugins in $instances array will throw error in return statement:
      return $plugins[$instance->enrol]->allow_unenrol($instance)

            Unassigned Unassigned
            andriusvegys Andrius Vegys
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

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