Details
Description
Currently the role_unassign function does some cleanup of group memberships and lastaccess dates. This means when a student is unenrolled then re-enrolled they lose their group memberships. This is contrary to most other features of Moodle such as assignment submissions, forum posts etc which will re-appear when the student gets their access back.
This is especially problematic when using external systems for enrolments, because every time something goes wrong with the system and roles get unassigned, group memberships have to be recovered from a backed up copy of the database. The group memberships / lastaccess are the only parts that get lost upon dropping and regaining a role - everything else returns as if the access was never lost.
The cleanup is based on the 'moodle/course:view' capability, so even if the students role changes from 'student' to 'withdrawnstudent' (a role without moodle/course:view capability), the group memberships / access dates are lost.
Simply commenting out the cleanup code might not be a suitable solution since lots of code relies on the groups_members table being current. What about having a groups_members_archive table which can be used to reassign group memberships? Perhaps this might be an optional feature since some people might not want group memberships restored.
I see this as a critical feature for institutions who rely on third party systems for enrolments - we have been hit by this problem repeatedly for different clients. Whenever there is a hiccup in enrolments (whether it be caused by an administrative error or a software bug), we have to go to backups to recover the lost groups memberships.
Thanks
Sorry, we do have to cleanup data after unenroling. The reason is code complexity and performance. We will also need to fix user deleting and finally allow full data purging if requested.
I think proper solution is to completely redesign enrolments and prevent both software bugs and administration errors.