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
    • Rank:
      17837

      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.

        Activity

        Hide
        Michael Blake added a comment -

        This issue has been reported to cause issues at a MP site. Please give it priority.

        Show
        Michael Blake added a comment - This issue has been reported to cause issues at a MP site. Please give it priority.
        Hide
        Michael de Raadt added a comment -

        Is there any evidence if this affects 2.x? I assume not.

        Show
        Michael de Raadt added a comment - Is there any evidence if this affects 2.x? I assume not.
        Hide
        Chris Follin added a comment -

        No, 2.x doesn't have this problem. The option to select Course Users or All Site Users doesn't exist in 2.x.

        Show
        Chris Follin added a comment - No, 2.x doesn't have this problem. The option to select Course Users or All Site Users doesn't exist in 2.x.
        Hide
        Mark Nielsen added a comment -

        Attaching a patch to address the issue. When backing up users, it now always populates the needed and enrolled users in order to determine if role assignment information is needed for those users or not.

        Show
        Mark Nielsen added a comment - Attaching a patch to address the issue. When backing up users, it now always populates the needed and enrolled users in order to determine if role assignment information is needed for those users or not.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        U P S T R E A M I Z E D !

        Many thanks, this is now available in all the repos (git & cvs).

        Closing, ciao

        Show
        Eloy Lafuente (stronk7) added a comment - U P S T R E A M I Z E D ! Many thanks, this is now available in all the repos (git & cvs). Closing, ciao
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Doh,

        somehow this issue was closed incorrectly when processing all the integrated issues this week. (sort of most voted and current in integration filters mix). Apologies for the confusion, reseting to previous status!

        Ciao, Eloy

        Show
        Eloy Lafuente (stronk7) added a comment - Doh, somehow this issue was closed incorrectly when processing all the integrated issues this week. (sort of most voted and current in integration filters mix). Apologies for the confusion, reseting to previous status! Ciao, Eloy
        Hide
        Dan Marsden added a comment -

        Moodle 1.9 is no longer supported for general bug fixes - closing this as won't fix as the comments suggest this is not an issue in Moodle 2 - thanks.

        Show
        Dan Marsden added a comment - Moodle 1.9 is no longer supported for general bug fixes - closing this as won't fix as the comments suggest this is not an issue in Moodle 2 - thanks.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: