As highlighted by
MDL-31386, there is a potential for moodle backups to restore incorrectly when natural database row order doesn't meet the ID sortorder.
To address this, I think we need to look at two solutions:
- ensuring that data is always sorted by ID at the backup phase (unless another field is more suitable in a particular case); and
- ensuring that when restoring data, the XML data is re-sorted by ID if one is present.