Unenroll Bulk user from external database

Unenroll Bulk user from external database

by Osama alhadidi -
Number of replies: 2

Hi all

I need to unenroll about 1000 user from multiple courses

 I use External database enrolment 

is there an idea ???? 

thanx all  

i use moodle 2.7 

Average of ratings: -
In reply to Osama alhadidi

Re: Unenroll Bulk user from external database

by Colin Fraser -
Picture of Documentation writers Picture of Testers

You are likely to have a csv file around with all these users and their details, well, you should have. In the mdl_user table there is a field called "deleted" so you can use your csv file to reset the deleted field to 1. I imagine it would look something like 

username,firstname,lastname,email,delete

ana,someone,ana.ana@theemail.com,1

boris,boris,yeltsin,boris.yeltsin@thisemail.com,1 

and so on. You can do this in Sheets or Excel, or some other tool that makes csv files. If you don't have one you can actually generate one in using your favourite database management tool like phpMyAdmin if using MySQL or MariaDB

Alternatively set up an SQL in a loop using a scripting language like PHP to access your database and reset the delete field to 1. IANAD, so all I can say is the script connects to the database, scans for the User table, and only enters 1 in the delete column where the names match in both input params and user email. I say email because that is the one element of a User Id that has to be unique. Any other detail can be the same, but not emails. 

In reply to Colin Fraser

Re: Unenroll Bulk user from external database

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Of course, the other side of that question, having re-read it, is how do I keep them in the Moodle but uneroll them from the courses they should not be in. There are two ways, first don't. As a course ends, and a backup of the course happens, get the Teacher to Reset the course. This removes all enrollees and you, as admin, don't have to do anything. Make it clear that the Teacher is responsible for their courses, not the Admins, not the Course Creators, not the Managers, the Teachers. How they divide this work up between them is entirely up to them. For example, 5 teachers teach one subject, they all share the same course, students are in groups, then one person, maybe the head of that faculty resets the course, removing all Groups and all Group enrollees. All done. 

The other way is to use a flat file, and follow the instructions given in the Moodle Docs. For that to work, I suggest you need to be on it all the time, setting up the flat file and modifying it whenever needed and not putting it off at any time. 

NOTE: You may want to look at your Moodle, v2.7. It is really outdated now, so suggest you update to v2.9, then to 3.1, then to v3.3, then to v3.5 before you get any further behind. Make sure to follow a path, jumping from v2.7 to v3.5 is going to create more problems than you want to know about. Take it one step at a time, you can jump even numbered versions, but not odd numbered versions, and make sure it works properly between each update.