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

Performing the restore of a course, from a teacher's perspective, flushs the role assignements

    Details

    • Database:
      MySQL
    • Testing Instructions:
      Hide

      1/ backup course without enrolments and roles
      2/ restore the course into the same course deleting data using teacher account
      3/ verify teacher is reenrolled into course during restore
      4/ enrol some users and create some groups
      5/ restore again overriding current course but keeping enrols and groups (new options in course settings)

      Show
      1/ backup course without enrolments and roles 2/ restore the course into the same course deleting data using teacher account 3/ verify teacher is reenrolled into course during restore 4/ enrol some users and create some groups 5/ restore again overriding current course but keeping enrols and groups (new options in course settings)
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w47_MDL-27233_m22_restoreenrol

      Description

      Performing the restore of a course, from a teacher's perspective, flushs the role assignements. Permissions have been checked for the teacher to attribute role assignements to users in a restore process.

      Steps to replicate the bug :

      1- As administrator, Create an "empty course" for the test
      2- Assign another user as teacher of the course.
      3- Log in as this user and perform a backup of the course. Assure that "Include enrolled users" and "Include user role assignments" are checked.
      4- Perform the restore of the course. Choose "Delete the contents of this course and then restore" and continue.Assure that "Include enrolled users" and "Include user role assignments" are checked.

      After restoring, its says "This course is currently unavailable to students".

      If you go back as administrator, you can see that the user is still there but he is no more teacher of the course.

      --------------------------------------------------------------------------

      I dug the code a bit and found these things :

      1- The function process_assignement

      "/moodle/backup/moodle2/restore_stepslib.php"

      public function process_assignment($data) {
         global $DB;
       
         $data = (object)$data;
       
         // Check roleid, userid are one of the mapped ones
         if (!$newroleid = $this->get_mappingid('role', $data->roleid)) {
            return;
         }
       
         ...

      The method get_mappingid returns 0 when it should return 3 and so the assignment fails.
      get_mappingid is checking on the column newitemid of the temporary table backup_ids_temp. If I output the table content, I can clearly see that it is effectively set to 0.

      "backup_ids_temp content"

      ...
       
      [8] => stdClass Object ( [id] => 8 [backupid] => c07aa265cba1cccd0e58119906ca6576 [itemname] => role [itemid] => 3 [newitemid]=> 0
       
      ... 

      2- The functions that affect the content of the table "backup_ids_temp"

      "/moodle/backup/util/dbops/restore_dbops.php"

      protected static function get_best_assignable_role($role, $courseid, $userid, $samesite) {
         global $CFG, $DB;
       
         // Gather various information about roles
         $coursectx = get_context_instance(CONTEXT_COURSE, $courseid);
         $allroles = $DB->get_records('role');
         $assignablerolesshortname = get_assignable_roles($coursectx, ROLENAME_SHORT, false, $userid);
       
         ...

      get_assignable_roles returns an empty array of role.

      I think the problem may be that the role assignments are deleted before the call to the function, so the match can't be done.

      Hope it helps!

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  28 Vote for this issue
                  Watchers:
                  16 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    5/Dec/11