Details
Description
All backups will include group info. the group members info included is repeated too many times making the moodle.xml file too large to restore in extreme cases. The number repeats seems to depend on the number of students enrolled on the course and the number of groups on the course.
This problem is present at the OU, I tracked it down to a line of sql in in backuplib.php in the method backup_groups_members_info() that reads
The sql reads as :
SELECT gm.* FROM pssr1_mdl_groups_members gm, pssr1_mdl_backup_ids bi WHERE gm.groupid = 44 AND bi.backup_code = 1220629007 AND bi.table_name = 'user'
The problem is serious because I have a course with a large number of students enrolled and asmany as 314 groups that cannot be restored. Even generating a backup with just labels and nothing else, no user data or anything generates a 35mb zip which contains a 374mb moodle.xml file. 95% of this file is made up of repeating group member data.
I made a test course with only a couple of students and groups and found that the sql listed above determined the results set from the db which determined the xml output.
I found a simple fix was to added the line
AND bi.old_id = gm.userid
to the end of the sql to restrict the id's correctly. I checked moodle core and this bug appears in there too so I wanted to check if a) this is the correct fix since an even simpler solution could be to remove the references to the 'mdl_backup_ids' table and make cleaner sql. I also wanted to know if others can replicate the problem.
I'm also wondering why a join wasn't used? Is it because the data access layer can't support it?
Hi Colin,
well spotted!
The JOIN condition is 100% missing there, I'll add it now!
Anyway, just for curiosity.... that query shouldn't be returning duplicate records at all. It's one get_records() call, and, as it returns one associative (by id) array, php should be "removing" duplicates transparently. In fact, I've executed it here and cannot get duplicates from within Moodle (but I get them from line command, of course). How can you be getting such duplicates there?
Ciao