Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have an XML file with projects and tasks. Every project can have tasks and subprojects of arbitrary depth. I have read the documentation about XML-based sources at https://drupal.org/node/1152156 and the XML examples in the module, but they just seem to deal with flat, one-level files easily accessible with fixed XPath paths.
My file has a structure similar to this:
<data>
<project>
<id>...</id>
...
<task>
<id>...</id>
...
</task>
<project>
<id>...</id>
...
<task>
<id>...</id>
...
</task>
<project>
...
</project>
</project>
</project>
</data>
How can I migrate this file into nodes of type "project" and "task"? The question is not how to create that hierarchy with nodes in Drupal, but how to traverse this file with migrate.
Comments
Comment #1
Ronino CreditAttribution: Ronino commentedComment #2
13rac1 CreditAttribution: 13rac1 commentedI'd suggest you pre-process all your data into a separate bare MySQL database. It'll make the migration far simpler.
OR
Create two XML migrations using the same source. Assuming you have an entity_reference pointing from the task to the project. You make all the projects first. Then make all the tasks referencing the projects.
Comment #3
mikeryanThe answer depends how you're implementing the hierarchy in Drupal. Let's say that each project has a node reference field pointing to its parent project, field_parent_project (NULL, of course, for top-level projects). Then, you should be able to handle the relationship with something like (bearing with my xpath rustiness):
This would pull the parent's source ID, and (since the parent would be saved before its children) translating that to the parent's Drupal node ID using your migration's map table.
Comment #4
mikeryanComment #5
Alina Basarabeanu CreditAttribution: Alina Basarabeanu commentedHi,
I've got same problem, can't get the parent id.
My xml structure is :
I run one migrate which import each item.
The problem in on second migration where I am using :
childID is created in prepareKey(), doesn't exist in xml.
The xml for each child doesn't contain any information about the parent item and I need the itemID.
Already tried to use a field on child entity but still can't get the parent id.