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

Course restore does not restore user roles when enrol plugin is not manual

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0.1
    • Fix Version/s: None
    • Component/s: Enrolments
    • Labels:
    • Affected Branches:
      MOODLE_20_STABLE

      Description

      When you restoring a course in Moodle 2.0.1 and you have students that are enrolled in the course using another enrolment plugin which is not 'manual', all student role assignment is not done.

      If the users where assigned in the course using the manual enrolment, then you have no problem. All student role come just fine.

      Looks like role_assignments is done before user enrolment. But other enrol plugins need the enrolid of the instance in the course to assign role which does not exist until the enrolment is done.

      The should be a way to create the enrolment instance in the course first before doing role assignment.

      Look into /backup/moodle2/restore_stepslib.php

      Inside the <b>public function process_assignment($data) {</b>

      This is the part that is failing

      <pre>
      if (empty($data->component))

      { // assign standard manual roles // TODO: role_assign() needs one userid param to be able to specify our restore userid role_assign($newroleid, $newuserid, $contextid); }

      else if ((strpos($data->component, 'enrol_') === 0)) {
      // Deal with enrolment roles
      error_log($data->component." - found ");
      if ($enrolid = $this->get_mappingid('enrol', $data->itemid)) {
      error_log("Found new value for ".$data->itemid . " as ". $enrolid);
      if ($component = $DB->get_field('enrol', 'component', array('id'=>$enrolid))) {

      </pre>

      So for manual enrol, you use when component is empty which does not require an enrolment instance in the course before assigning roles. Hence works.

      But for the rest, the section <b>if ($enrolid = $this->get_mappingid('enrol', $data->itemid)) {</b> fails since the enrol plugin is done later.

      Please fix the order, unless l am missing something.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              skodak Petr Skoda
              Reporter:
              bazaar Mawuli Kuivi
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              8 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: