Is this possible?
Can you provide us with some documentation about migrating D6 core profiles to D7 core user fields?

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

It should be straightforward - the D6 profile fields are presented as source fields, and any D7 fields on users will be presented as destination fields, so you should be able to map them directly. Are you using the UI for your migration, or programming it? Through the UI, you can edit the field mapping directly and choose what D6 profile field goes to what D7 user field. Programmatically, you would do something like:

$this->addFieldMapping('field_birthplace', 'profile_birthplace');
anrikun’s picture

Thanks for your answer @mikeryan, but where am I supposed to put this code? Inside what function?
I prefer to do it programmatically rather than using the UI.

heronog’s picture

Here is some code that worked for me. You need to create a custom query for the profile fields.
I don't know if there is a better way to obtain this data from the source database, if there is I'd love to know.

class CustomUserMigrationWithProfileFields extends DrupalUser6Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Map our custom user profile fields
    $this->addFieldMapping('field_first_d7_field', 'profile_first_field');
    $this->addFieldMapping('field_second_d7_field', 'profile_second_field');
    $this->addFieldMapping('field_third_d7_field', 'profile_third_field');

    $this->destination = new DrupalDestinationUser();
  }



  protected function query() {
    // Get the default query (all rows in the users table other than uid 1)
    $query = parent::query();

    //Making a subquery that will result in a comma separated list of profile fields,
    //ordered by field ID so that we can trust the order.

    // This assumes that all users have all fields in the table. If you have 6 fields a
    // UID should appear 6 times in the profile_values table.

    $profile_subquery = Database::getConnection('default', MIGRATE_SOURCE_DATABASE)
                        ->select('profile_values', 'pv')
                        ->groupBy('pv.uid')
                        ->orderBy('pv.uid');
    $profile_subquery->addExpression('group_concat(pv.value ORDER BY pv.fid)', 'pv_data');
    $profile_subquery->addField('pv', 'uid');

    $query->join($profile_subquery, 'p', 'u.uid=p.uid');
    $query->addField('p', 'pv_data');

    //print $query->__toString(); ///In case you want to see the complete query.

    return $query;
  }

  public function prepareRow($row) { //Split the comma separated values to get our profile data
    $profile_data = split(',',$row->pv_data);
    $row->profile_first_field = $profile_data[0];
    $row->profile_second_field = $profile_data[1];
    $row->profile_third_field = $profile_data[2];
  }
anrikun’s picture

@heronog: thanks for your code, I will try it and let you know!

anrikun’s picture

Actually, as @mikeryan stated, the only thing necessary is to add field mappings. You don't have to add any custom query:

<?php
class CustomMigrateDrupalUser6Migration extends DrupalUser6Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Map profile fields.
    $this->addFieldMapping('field_user_lastname',  'profile_lastname');
    $this->addFieldMapping('field_user_firstname', 'profile_firstname');
  }
}
?>

Thanks again to both of you!

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.