public function process_enrolment($data) {
        global $DB;

        if (!isset($this->plugins)) {
            $this->plugins = enrol_get_plugins(true);
        }

        $data = (object)$data;

        // Process only if parent instance have been mapped.
        if ($enrolid = $this->get_new_parentid('enrol')) {
            $oldinstancestatus = ENROL_INSTANCE_ENABLED;
            $oldenrolid = $this->get_old_parentid('enrol');
            if (isset($this->originalstatus[$oldenrolid])) {
                $oldinstancestatus = $this->originalstatus[$oldenrolid];
            }
            if ($instance = $DB->get_record('enrol', array('id'=>$enrolid))) {
                // And only if user is a mapped one.
                if ($userid = $this->get_mappingid('user', $data->userid)) {
                    if (isset($this->plugins[$instance->enrol])) {
                        $this->plugins[$instance->enrol]->restore_user_enrolment($this, $data, $instance, $userid, $oldinstancestatus);
                    }
                }
            }
        }
    }