Closed (fixed)
Project:
Migrate
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
19 Dec 2011 at 20:13 UTC
Updated:
21 Aug 2013 at 13:16 UTC
I have an XML file that I can importing into a custom table [as part of a larger routine].
In general, importing into the custom table works well.
But some of the XML files are structured a little differently, and I'm not sure how to approach it.
<CourseProperty>
<CourseID>52797</CourseID>
<PropertyID>27</PropertyID>
<PropertyValue>ABC</PropertyValue>
</CourseProperty>
<CourseProperty>
<CourseID>52797</CourseID>
<PropertyID>31</PropertyID>
<PropertyValue>More text here</PropertyValue>
</CourseProperty>
I'm unsure how to setup the query in the import class
$item_xpath = '/ROOT/CourseProperty'; // relative to document
$item_ID_xpath = 'CourseID' . 'PropertyID'; // relative to item_xpath and gets assembled
Any suggestions?
Comments
Comment #1
alanburke commentedIt looks like I have 2 different issues.
One is setting up the query in the import class.
I tried
And in 6.2 stable version, this returns the correct number of records in the XML file.
However, I got an error
Call to undefined function _drupal_decode_exception()when trying to run the import.So I updated to the dev version, which gives a longer and more helpful SQL error
but now the list of records is reduced to the number of distinct CourseIDs in the file.
The more helpful SQL error on import now says
This error is possibly related to how I have set up the map
Any pointers welcome.
Comment #2
mikeryanYes, the XML sources do assume you're dealing with a single-value primary key. To deal with multi-part keys, you'll need to override the XML source (I'm guessing you're using MigrateItemsXML?). Add a second ID xpath to the constructor and save it, and override getItemID to apply both xpaths and concatenate the strings using a pipe or something like as a separator. I'm sure there will be more tweaking necessary, but that should get you started.
Is this helpful?
Comment #3
alanburke commentedHi Mike
That's a great start. Thanks!
I've done as suggested, with that.
One bit I don't quite understand is the function getItem($id)
It is called from within multiitems.inc but where is the ID generated?
I think I need to set that ID to match the ID I am generating in getItemID
Comment #4
alanburke commentedI have to override getIDsFromXML to get the right IDs.
Looking good now.
Thanks.
[I'll leave this open for just a bit longer]
Comment #5
alanburke commentedClosing this.
Thanks a million for the help Mike!
Comment #7
burningdog commentedSee #8 at #1812946: Can't use multiple sourceID's with an XML source data for an example of how to do this.