Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-28220

Users And Data Not Restored When Backup File Contains All Site Users

    Details

    • Database:
      Any
    • Testing Instructions:
      Hide

      1. Create a course and enroll one or more users, but make sure at least one user that exists on the site is not enrolled in the course.
      2. Create at least one activity with some user data (create a quiz and take it as a student or create a forum and post in it, for example).
      3. Perform a course backup with user data and choose to include only the course users.
      4. Download the backup file and open moodle.xml.
      5. Note that the user records contain <ROLES><ROLE><TYPE>needed</TYPE></ROLE></ROLES>.
      6. Restore the course and note that users are enrolled and their user data is restored.
      7. Perform a course backup with user data but this time choose to include all site users.
      8. Download the backup file and open moodle.xml.
      9. Note that NO user records contain <ROLES><ROLE><TYPE>needed</TYPE></ROLE></ROLES>.
      10. Restore the course and note that users are not enrolled and no user data is restored.

      Expected:
      In step 9, the user records for the users who are in the course should presumably include the "needed" role type.
      In step 10, the course users should be enrolled into the course and their user data should be restored.

      Show
      1. Create a course and enroll one or more users, but make sure at least one user that exists on the site is not enrolled in the course. 2. Create at least one activity with some user data (create a quiz and take it as a student or create a forum and post in it, for example). 3. Perform a course backup with user data and choose to include only the course users. 4. Download the backup file and open moodle.xml. 5. Note that the user records contain <ROLES><ROLE><TYPE>needed</TYPE></ROLE></ROLES>. 6. Restore the course and note that users are enrolled and their user data is restored. 7. Perform a course backup with user data but this time choose to include all site users. 8. Download the backup file and open moodle.xml. 9. Note that NO user records contain <ROLES><ROLE><TYPE>needed</TYPE></ROLE></ROLES>. 10. Restore the course and note that users are not enrolled and no user data is restored. Expected: In step 9, the user records for the users who are in the course should presumably include the "needed" role type. In step 10, the course users should be enrolled into the course and their user data should be restored.
    • Workaround:
      Hide

      Create backups with only the course users, not all site users. The default for automated backups is All Users so it would need to be changed in Site admin > Courses > Backups. I think the default for manual backups is for just the course users.

      If you have a backup that is missing the role type info and you need to restore that course with user data, the role type info can be manually added to the XML file. Doing so and then restoring with the modified XML file will enroll the users and restore their data. In the section that reads <ROLES></ROLES>, insert <ROLE><TYPE>needed</TYPE></ROLE> for the users who should be in the course. Warning: this could be very tedious.

      Show
      Create backups with only the course users, not all site users. The default for automated backups is All Users so it would need to be changed in Site admin > Courses > Backups. I think the default for manual backups is for just the course users. If you have a backup that is missing the role type info and you need to restore that course with user data, the role type info can be manually added to the XML file. Doing so and then restoring with the modified XML file will enroll the users and restore their data. In the section that reads <ROLES></ROLES>, insert <ROLE><TYPE>needed</TYPE></ROLE> for the users who should be in the course. Warning: this could be very tedious.
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      When a course is backed up with only the course users, restoring that course works as expected. The course is created, users are enrolled, and their data is restored. However, when a course is backed up with all site users, restoring the course does NOT work as expected. The course is created but no users are enrolled and no user data is restored.

      I tracked this down to the user role information in the backup file. The restore process looks for a role type of "needed" to know that the user is needed for the course. In the backup with only course users, each user has this role type as shown here:

      <USER>
      <ID>6</ID>
      -irrelevant data removed-
      <ROLES>
      <ROLE>
      <TYPE>needed</TYPE>
      </ROLE>
      </ROLES>
      </USER>

      When all users are backed up, none of the users have the "needed" role type. Their user records look like this, even for users who are needed:

      <USER>
      <ID>6</ID>
      -irrelevant data removed-
      <ROLES>
      </ROLES>
      </USER>

      We have seen this issue in both automated backups and manual backups.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                17 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: