0

FYI: I'm using the module Migrate 7.x-2.5

I'm trying to migrate users from a custom built PHP website, backed by a mysql database, into Drupal.

Each user can have multiple statutes assigned to him. In the source database I have a table 'users' with a column 'stat_id'.

+---------+---------+
| user_id | stat_id |
+---------+---------+
|       1 | ;2;     |
|       2 | ;26;    |
|       3 | ;3;     |
|       4 | ;27;28; |
|       5 | ;19;2;  |
+---------+---------+

The name of the statutes is stored in the table 'users_statuut'.

+---------+----------------------------+
| stat_id | statuut_nl                 |
+---------+----------------------------+
|       1 | Doctoraatsstudent          |
|       2 | Postdoctoraal onderzoeker  |
|       3 | Administratieve medewerker |
|       6 | Diensthoofd                |
|       7 | Laborant                   |
+---------+----------------------------+

In Drupal I created a term vocabulary 'statutes' with the names of all the statutes. And I added a term reference field to the user profile that can select multiple values from this vocabulary.

What I can't figure out is how to migrate the data from the source table into Drupal. I've already managed to migrate simple fields like username, email, password,... so that's working, but I have no idea how to get the statutes into the term reference field.

Any help is really appreciated.

0

Use a callback with a separator to transform the source value to the destination value. For example:

  $this->addFieldMapping('statuut_nl', 'stat_id')
   ->separator(';')
   ->callbacks(array($this, 'computeValue'));

  protected function computeValue($value) {
    $allowed_values = array(
      2 => 'Postdoctoraal onderzoeker',
      ...
    );

    return ($allowed_values[$value]);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.