General developer forum

Invalid enrol context

 
Picture of Zoran Jancic
Invalid enrol context
 

I found great little function for enrolling User to a course here: https://moodle.org/mod/forum/discuss.php?d=266496

The problem is, I'm keep getting "invalid enrol instance" error message at the following line:

$enrol->enrol_user($instance, $userid, $roleid);

Stack trace is the following:

invalid enrol instance!' in enrollib.php:1641
enrol_plugin->enrol_user(Object(stdClass), '192', '5')
check_enrol('TT001', '192', '5', 'manual')

Moodle version is 3.3

 
Average of ratings: -
Picture of Darko Miletić
Re: Invalid enrol context
Core developersParticularly helpful Moodlers

That error means that you tried to enrol user using one enrollment plugin with instance created by another enrollment plugin.


 
Average of ratings: -
Picture of ivan Rivas
Re: Invalid enrol context
 

How can I solve this error? I am using the function to register a student and I get the error

 
Average of ratings: -