Active
Project:
Migrate Extras
Version:
7.x-2.5
Component:
Profile2
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
14 Dec 2012 at 14:23 UTC
Updated:
21 Jan 2013 at 22:29 UTC
Apologies in advance for not being able to get my head around this. I am trying to get a d6->d7 migration started, and in the old site have profile fields which I would like to migrate into Profile2 fields on the new site. Here's what I have so far:
// User Migration class
class ukcUserProfileMigration extends Migration {
// class constructor
public function __construct() {
parent::__construct(MigrateGroup::getInstance('allukcusers'));
$this->description = t('Migrate Drupal 6 user profiles');
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
),
MigrateDestinationProfile2::getKeySchema()
);
$query = Database::getConnection('default', 'legacy')
->select('users', 'u')
->fields('u', array('uid'))
->condition('u.uid', 1, '>');
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationProfile2('main');
// Create the field mappings
$this->addFieldMapping('field_account_first_name', 'profile_first_name');
}
public function prepareRow($current_row) {
$profile_fields = Database::getConnection('default', 'legacy')
->select('profile_values', 'pv')
->fields('pv', array('fid', 'value'))
->condition('pv.uid', $current_row->uid)
->condition('pv.fid', 3, '>')
->orderBy('pv.fid', 'ASC')
->execute()
->fetchAllKeyed();
// print_r ($profile_fields[4]);
foreach ($profile_fields as $row) {
$current_row->profile_first_name[] = $profile_fields[4];
}
}
}
I'll add additional field mappings once I have the thing working.
This is putting everyone's first name into the field_data_field_account_first_name table as expected, but it is not putting the associated uid into the profile table.
Appreciate any suggestions.
Comments
Comment #1
tmwagner commentedI don't see any mapping of the UID in your code. After you get that in, you need to associate this migration with a previous migration wherein you moved the user object.
So, if you've moved your users with a migration called MoveLegacyUser, your mapping might look like this:
And, if you look, I have a default value. That probably will produce results that you may not want... I'm thinking using prepareRow to drop the rows that don't have a matching user object. However, if you make this migration contingent on the previous "MoveLegacyUser" migration, that, in theory shouldn't happen.
Comment #1.0
tmwagner commentededited to correct comments