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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 2.2
    • 2.0.4, 2.1.1, 2.2
    • Backup, Course
    • MySQL
    • MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • MOODLE_22_STABLE
    • w47_MDL-27233_m22_restoreenrol
    • 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)

      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!

            skodak Petr Skoda
            gaudreaj Jean-Philippe Gaudreau
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            28 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.