General developer forum

Bulk Unenroll methods are slow and don't give options needed. SQL query?

 
Picture of Ron Griffith
Bulk Unenroll methods are slow and don't give options needed. SQL query?
 

Moodle 3.1.6 (Build: 20170508)
mysqlnd 5.0.11-dev - 20120503

Problem:

1000's of students enrolled in 100's of courses that they have never entered. 

Using the tools available in moodle:

Using the enrolled users screen to sort by "manual enrollment" method and role of "student" then clicking "Last Access to course" twice will bring the users that accessed the course to the top. This is great but the bad part is that after i scroll or next to the page that starts showing the users that have "never" accessed the course I have to click on each one individually (the ability to select all would help here) and then I select from the drop down "delete selected user enrollments" and on the next page confirm I want to delete them. Then wait minutes for it to perform the task after its complete then I have to individually check each user with "never" and repeat the process over and over until I have removed all the users. With over 5000 users to unenroll from 100's of courses this becomes much too time consuming. And this is for only one particular course. I will have to do this on over 300 courses. 

Can I use a SQL query to do the following? And if so I have no experience writing such a SQL query, does anyone have or can write a query like this?

What I would like to do:

Select all courses and unenroll all users that have never accessed the course. 

Please let me know if I need to post more information 

Moodle 3.1.6 (Build: 20170508)
mysqlnd 5.0.11-dev - 20120503

 
Average of ratings: -
Picture of Marcus Green
Re: Bulk Unenroll methods are slow and don't give options needed. SQL query?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers
You might find a way to use the Moosh utility that allows programmatic unenrolment

http://moosh-online.com/commands/

course-unenrol

Unerol user(s) from a course id provided. First argument is a course ID then list of users.

Example 1: Unenrol users with id 7, 9, 12 and 16 from course with id 2.

moosh course-unenrol 2 7 9 12 16

 
Average of ratings: -