Thank you for the wonderful migrate module. @mikeryan, I have read many of your helpful posts.
For my case, I am moving information from a relatively complexly interconnected Drupal 6 site to it's hand-built counterpart in Drupal 7. Migrate D2D is great but I could not get my use case to fit, so I am using good old Migrate. I have successfully used Migrate to migrate users, profiles (profile2), pages (articles?), and individual items of field collections. I will simplify my case as much as possible for this support request.
In my systems, each faculty user can have a profile called profile_faculty. The faculty profile had an unlimited multigroup in D6 with Degree Type (field_degree_type: text) and Degree Details (field_degree_details: text). The D7 is the same but in a field collection and both the multigroup and field collection are called field_degrees_held.
So a simplified example would be of the form:
profile_faculty:'23'
field_degrees_held
delta:0 degree_type:'BA' degree_details:'University of Somewhere, 2012'
delta:1 degree_type:'MA' degree_details:'Another Institution, 2013'
My Migrate class code will migrate either delta 0 or delta 1, but not both. I realize that my source query has to pull a record for each. It seems to do this. However, I am not doing something right with adding the field collection values so that they do not overwrite each other.
I have reviewed all the migrate / field collection documentation I could find, including the migrate and field collection code. Clearly, I don't understand it enough or I would probably have my answer.
There is something I am missing to create more than one item in a Field Collection. [I must be very dense because it looks like a lot of people have figured it out.] Any hints? Please.
Here is the field collection migration code I am using.
<?php
class degreeMigration extends GEOGProfileMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Migration of degree multi-group info D6 to field collection D7');
//specify dependencies. Since this is a field collection, depends on the migration of the Profile (to which it is attached)
//this is the name given to the Profile part of the "GEOGProfileMigration", so therefore it is "GEOGProfiles"
$this->dependencies = array('GEOGProfiles');
//create the query for the source data
$query = db_select(OUR_SOURCE_DATABASE .'.node', 'n')
->fields('n', array('nid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'moderate', 'sticky', 'tni$
->condition('n.type', 'profile_faculty', '=');
$query->leftJoin(OUR_DEST_DATABASE .'.migrate_map_geogprofilesfcdegrees', 'map', 'map.sourceid1 = n.uid');
$query->leftJoin(OUR_SOURCE_DATABASE .'.content_field_degree_details', 'dd', 'n.nid = dd.nid');
$query->addField('dd', 'field_degree_details_value');
$query->leftJoin(OUR_SOURCE_DATABASE .'.content_field_degree_type', 'dt', 'n.nid = dt.nid and dd.delta = dt.delta');
$query->addField('dt', 'field_degree_type_value');
$query->orderBy('n.uid','ASC');
$this->source = new MigrateSourceSQL($query);
//specify destination. copied this from instructions on https://drupal.org/node/1900640
$this->destination = new MigrateDestinationFieldCollection('field_degrees_held',
array('host_entity_type' => 'profile2') );
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'D6 unique user ID',
'alias' => 'n',
),
),
MigrateDestinationFieldCollection::getKeySchema()
);
//map host entity ID to source entity ID
$this->addFieldMapping('host_entity_id', 'uid')->sourceMigration('GEOGProfiles');
$this->addFieldMapping('field_degree_type','field_degree_type_value');
$this->addFieldMapping('field_degree_details','field_degree_details_value');
}
}
?>
This is based on a class GEOGProfileMigration, which I can post as well, if that helps. It is pulling from the source database and the $this->map is as such:
<?php
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'D6 Unique User ID',
'alias' => 'u',
)
),
MigrateDestinationProfile2::getKeySchema()
);
?>
I have spent many, many hours/days/weeks trying to get this migration going - and wanted to try everything I could before bringing my noob question to the Drupal site. So please know that I am extremely grateful for any guidance.
Comments
Comment #1
mikaoelitiana@gmail.com commentedI am having the same problem, have you found any solution?
Comment #2
mngates commentedNo, sorry. I am still struggling with this and unable to find assistance.
Comment #3
mngates commentedYes! Finally solved this. I was struggling with the multiplicity of the Source and had been unable to specify the composite key correctly. In the end, the fix for me came in this part:
It was setting the delta as well as adding the alias that did the trick. Seems so easy now that it works..
Comment #4
mngates commentedJust closing this issue
Comment #5
guypaddock commentedNOTE: For anyone stumbling on this thread in searches and following the code provided by the OP, for D7 ignore the comment that "GEOGProfileMigration" should be "GEOGProfile" in the dependency list. If the class name is "GEOGProfileMigration", that's what should appear in the dependency list.
This led us down the wrong path while coming up to speed with Migration.
Comment #6
fjose commentedHello @mngates, Can you show me the whole example to migrate fields from D6 to Field Collection in D7??
Thank very much for your help!