I'm working on a D6-> D7 user migration where I need the source to be a node, not a user. To get around the restriction of only one author per node, in the source D6 site we created a Source content type, and then in other node types (article, video, etc), we created field_source as a node reference field to reference Source nodes.
So now, in my user migration to D7, I need to get the data from the Source nodes instead of users. Here's what I have so far.
/**
* Override of DrupalUser6Migration.
*/
class CNSUserMigration extends DrupalUser6Migration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->addFieldMapping('name', 'title');
// Set a default password for all users.
$this->addFieldMapping('pass')->defaultValue('Pass!234');
$this->addFieldMapping('field_twitter', 'field_twitter_id_value')->description('Twitter ID');
$this->addFieldMapping('field_job_title', 'field_source_title_value')->description('Job title');
$this->addFieldMapping('field_bio', 'body')->description('Bio');
// By default, the primary key is the uid from the users table,
// but since our user source is a source nid, need to replace
// uid with the nid of the source node.
$this->map = new MigrateSQLMap($this->machineName,
array(
'nid' => array('type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Source node nid',
'alias' => 'n',
),
),
DrupalDestinationUser::getKeySchema()
);
}
/**
* Override of DrupalUser6Migration::query()
*
* @return mixed
*/
protected function query() {
// Create query from scratch to get source nodes referenced from field_source
$query = Database::getConnection('default', $this->sourceConnection)
->select('node', 'n')
->fields('n', array('nid', 'title'));
$query->innerJoin('content_field_source', 'cfs', 'cfs.field_source_nid = n.nid');
$query->innerJoin('content_type_source', 'cts', 'cts.nid = cfs.field_source_nid');
$query->fields('cts', array('field_source_title_value', 'field_twitter_id_value'));
$query->innerJoin('node_revisions', 'nr', 'n.nid = nr.nid');
$query->fields('nr', array('body'));
$query->distinct();
return $query;
}
}
So my query works fine and gets all the relevant Source nodes, but when I ran it the first time, I realized I had to change my source PK to be the nid of the Source node instead of the default uid from the users table. As you can see above, I overrode the map with a new MigrateSQLMap object in my constructor. However, when I run the migration, it creates the first user from the query, but then all of the subsequent source records also point to that first new user instead of creating new users. Now that I've defined a new source PK, do I also need to do something on the destination side to cause it to create new users?
Thanks.