-
Bug
-
Resolution: Cannot Reproduce
-
Minor
-
None
-
3.8.6, 3.9.3, 3.10
-
MOODLE_310_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
-
MDL-70563_enrol_course_delete_bug -
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)