Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -
Number of replies: 11

Hello,

Recently we've noticed that one of our courses had two sets of users enrolled from external databases in a course. One group for this year and a group from last year. We currently have no way to remove the group from last year since the group no longer exists in the external database but for some reason that never synced across to remove them from the course.

Any idea why this is happening and how we can make it realise they need to be unenrolled? We're not able to unenroll them manually because of it being an external enrolment method.

We're running Moodle 3.0 but this would have been happening back in Moodle 2.9 as we only just upgraded recently.



Average of ratings: -
In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Are you running the database sync?  I believe it has to be run manually.  

In reply to Emma Richardson

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -

I'm pretty sure it runs automatically, this is only happening for one course out of many on our site. Usually there is a sync over night and students are added or removed based on the external database. This is still happening fine to all other courses.

This is the only case too where we're seeing external databases in our course's enrolment methods page.

.

In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Have you tried just recreating the group in the database (with no users in it) and see if that will fix the issue.

In reply to Emma Richardson

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -

I don't have access to the external database but got those who could to do it. They tried recreating the class in the external database adding users. But those test users were enrolled in the course through the group of enrolments that include the currently active class also. The weird group is still unchanged.

Not sure what's going on here.  I might need to try and get permission to play with the external database myself. Is there anything I can do on the moodle end and try a few different things.

Doing something crazy like disabling/removing the LDAP plugin in moodle and then re-enabling so that all enrolments were removed and have to be re-enrolled next sync would not be a good idea would it? 

In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Oh, this is LDAP enrollment?  Disabling the plugin will have no effect.  However, you could go into the Moodle database and try removing the enrolments there.  I suspect that there is a group id being used somewhere that is not lining up with the new group that was created.   

In reply to Emma Richardson

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -

Oops sorry, mixed up my words!
I still meant the External Database.

In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

'This is the only case too where we're seeing external databases in our course's enrolment methods page.'

I believe you should be seeing the External Database enrolment method on all the courses where it is used - I can on my site (Moodle2.9) - But only one instance of it! The fact that you have two in that screenshot makes it look as if you have a clone of the external database plugin running somewhere and that clone has the setting about removing users when unenrolled from the external database set to keep them enrolled.

You could try unenrolling them from the database (look for an enrol = database and courseid = x), that should remove any existing enrolments and if they are not in the database to be readded that should be fine - but it would still be worth finding out why you have two 'external database' methods in that course.

In reply to Richard Oelmann

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -
I just double checked our plugins list and we only have one version of the external database plugin installed from what I can tell. 


I'm not able to really mess with the moodle database at the moment and it's not causing any troubles at the moment so I might leave it for now but be on the lookout for it happening again. I'll keep an eye out in these forums and the bug tracker too to see if anyone experiences a similar issue.

In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Marinda Faasen -

I have exactly the same problem, but in more than one course. I have no idea how two instances of the external database appeared in these courses. I cannot find a pattern.


I really need to fix this problem. 

I'm a bit apprehensive about deleting these instances directly in the tables. As far as I understand I can delete the double instance in the mdl_enrol table and then I also have to delete the enrolments from the mdl_user_enrolments table and the assignments from the mdl_role_assignments. I think that is it


But how do I prevent this from happening again?


In reply to Marinda Faasen

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Rob P -

Hi Marinda,

I should have posted how we dealt with this in the end.

The people that manage our database ended up writing a script that updated the records in the database to merge the two instances into the active one and then deleting the now empty one. The next external database sync then removed the enrolments that shouldn't have been there properly.

We're still not sure what caused it but it hasn't seemed to return since we ran the script.

In reply to Rob P

Re: Moodle Users Enrolled from External Database When They're Not Enrolled In The Database Anymore

by Marinda Faasen -

Hi Robert

Thank you for the reply. I will try to do something similar.

Regards

Marinda