Entity references (such as node references that link one node to another) break when importing nodes that have been exported via the node_export module. This happens because the module currently does not do any checking or updating to account for the fact that the node IDs of imported content may differ from the node IDs they possessed when they were originally imported.

Comments

Here's a patch I've written that uses UUIDs to keep entity references from breaking during node import. My path only fixes entity references. Additional patching would be necessary to enable this functionality for the node_reference module.

Status:Active» Needs review

StatusFileSize
new3.08 KB

Thank you for submitting this patch Sheldon. One concern is that $entity_original_uuids only get's populated with the NIDs of the nodes that contain an entity reference field. In the scenario of a referenced entity which doesn't have an entity reference field itself, the import would fail. While saving, the (old) NID of the referenced entity would be missing inside your reference ($entity_original_uuids). Thus the $new_uuid (line 634) would not be populated and the reference won't be updated.

As a fix I populate $entity_original_uuids with all the nodes that are to be imported by moving it outside the if-clause. New Patch is attached.

Thank you, olklein, for the fix. I've done some additional work to correct taxonomy term reference imports, which should also use UUIDs rather than taxonomy IDs to prevent term references from breaking.

The uuid_features module provides a way of exporting and importing taxonomy terms using UUIDs, so the node_export module just has to use the UUIDs to match up taxonomy term references in the exported node to the correct references in the imported node.

Here's my updated patch that includes the taxonomy terms fix.

Title:Entity references break when importing nodesEntity references and taxonomy terms break when importing nodes

Thank you Sheldon Rampton for the #4 patch (and also olklein, danielb) . I was getting totally frustrated after trying various methods to move some content, but it looks like I've found something that would work for now. Some nodes seem to cause a problem - especially if they have more than two kinds of file attachment - such as image, video and audio. I chose the "Remote file export, URL" for file export, but in some cases I get the error "The website encountered an unexpected error. Please try again later. " However these are few, and I can live with these for now. The main thing is that I got the taxonomy terms exported right!

Thanks. #4 worked great.

One thing I would like to note that if you are doing an import. Is that you can get some rogue UID's which I ended up with.

My fix was to edit the exported file and remap the UID #'s to ones that do exist or to a temp users ID. I am wondering if this is something that should be addressed in this patch or as a separate patch?

Tried #4 patch, looks like it works for us on Entity Refereces. Though, it wasn't a thorough test.

The patches in #4 and below are incompatible with the dependency submodule and actually the fix is simpler if you use it for taking care of references and taxonomies.

Here's a patch that moves the references check to a later stage (after import) so all the nodes are actually present, and also saves the node, which is needed at this point.

Confirming that patch #8 also resolves the 'entity relation' issue as well.

Thank you @danielb, @pcambra and @Sheldon Rampton

Patch #8 also solved the issue that I was having with node dependencies not being restored after importing nodes.

Status:Needs review» Reviewed & tested by the community

Setting #8 as RTBC as for #9 and #10