Hi. First off, thanks for this module...I use it extensively.
I'm using the Drupal migrate module to migrate data from a non-Drupal dB to a Drupal one and I've set up a content type person with child of person role in Drupal. The parent people will be migrated in first, then the children.
The migrate module provides functions that allow manipulation of data right before it's saved as a node or the $node object right after it's saved.
I have the parent/child nid/$node object available for either of those functions.
My question: what API calls from nodehierarchy.module can I use to update the child with the hierarchy info? Also, do I need to re-save the parent after the child is updated?
Thanks in advanced!
Dan
Comments
Comment #1
jbylsma commentedYou should be able to use nodeapi implementations, which will eventually lead you to the private function _nodehierarchy_save_node(). All that stuff is contained with nodehierarchy.module and is pretty well commented, so it would probably be beneficial to take a look there before pulling any triggers.
#621662-13: Programmically assign parent when creating a node from script and previous comments have some information about programmatically adding nodes. That might help you out.
Please report back your findings! I'm unfamiliar with Migrate, so I'm not sure whether supporting it natively Node Hierarchy is warranted or even feasible. I'd be curious to hear about your experience.
Comment #2
webdrips commentedHi Jonny.
Thank you so much for point me in the right direction! I'm happy to report it is working with a few slight modifications from the above link.
Typically Migrate module support for other modules has been handled either natively if it's a popular enough request (e.g. date) or somebody adds it to the Migrate Extras module typically as a field handler method that extends MigrateFieldHandler.
I'm guessing this would not a trivial task, but if an argument was coded to handle the parent nid, seems as if the rest could be handled via similar code. This is actually considered the more correct way to do it than what I did below.
First, we need to add the desired field to the $query object (migration coders will recognize this part):
Next we add the complete() function outside the constructor, which is the last function called for a given row being migrated (and thankfully where the $node object has already been saved to the dB).
That's it...be sure the import specifies the parents are required to import first and it works.
Thanks again...this saved me a lot of time!
Dan