When a course backup is taken from a course with an autogroup_set it may include groups for that group set. If the course backup is later restored onto a course without that group set the groups will be created in an orphaned state.
We either need to:
As we add a new autogroup set to a course, we should also remove any groups with an idnumber starting with "autogroup|" that are not linked to an autogroup set on the course.
Whenever a group is created, check whether it's idnumber matches the autogroup pattern and ensure it is valid. If not valid, delete.
When a course backup is taken from a course with an autogroup_set it may include groups for that group set. If the course backup is later restored onto a course without that group set the groups will be created in an orphaned state.
We either need to: