Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 exported.
Comment | File | Size | Author |
---|---|---|---|
#8 | 1896384-node_export_dependency_entity_reference-8.patch | 2.25 KB | pcambra |
#4 | correct_entitity_references-1896384-4.patch | 5.53 KB | Sheldon Rampton |
#3 | correct_entity_reference_2.diff | 3.08 KB | olklein |
#1 | correct_entitity_references-1896384-1.patch | 2.97 KB | Sheldon Rampton |
Comments
Comment #1
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedHere'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.
Comment #2
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedComment #3
olklein CreditAttribution: olklein commentedThank 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.
Comment #4
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedThank 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.
Comment #5
ramper CreditAttribution: ramper commentedThank 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!
Comment #6
zeropx CreditAttribution: zeropx commentedThanks. #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?
Comment #7
EdgarPE CreditAttribution: EdgarPE commentedTried #4 patch, looks like it works for us on Entity Refereces. Though, it wasn't a thorough test.
Comment #8
pcambraThe 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.
Comment #9
citricguy CreditAttribution: citricguy commentedConfirming that patch #8 also resolves the 'entity relation' issue as well.
Thank you @danielb, @pcambra and @Sheldon Rampton
Comment #10
mediabounds CreditAttribution: mediabounds commentedPatch #8 also solved the issue that I was having with node dependencies not being restored after importing nodes.
Comment #11
pcambraSetting #8 as RTBC as for #9 and #10
Comment #12
Atomox CreditAttribution: Atomox commentedAfter applying the patch in #8, when reimporting, I'm getting duplicate entries for the entities being referenced. I.E. The referenced entities, which already exist, are being recreated. Has anyone else encountered this issue? These duplicated entities are also the only nodes in the system which are missing uuids, while their original versions (in the system, with lower nids) do have UUIDs.
Comment #13
dooug CreditAttribution: dooug commentedI applied the patch from #8 on node_export 7.x-3.x.
Why does it add the
$save
parameter here which is unused in this function?Comment #14
CoffeyMachine CreditAttribution: CoffeyMachine commentedI tried both #8 and #4. Neither maintained the entity reference in my case where I am importing both the referencING and referencED nodes at the same time.
Comment #15
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedComment #16
JMC CreditAttribution: JMC commentedPatch #8 works for me.
@Atomox, I don't seem to be getting the issue you mentioned but I think it would be possible to get it if you have the default setting for how existing nodes are handled - it defaults to "create a new node". I set mine to "Create a new revision..." and it's working fine.
@CoffeyMachine, I've probably misunderstood your comment, but you mentioned that you are importing both nodes at the same time as if you were marking both to be exported yourself, i.e. rather than just selecting the parent node and allowing the dependency module to find and include the referenced nodes. If that's right, it might be worth trying again with just the parent node(s) selected for export?
Comment #17
vdbemden CreditAttribution: vdbemden commentedPatches #4 combined with #8 worked using "drush ne-export" on my parents and children nodes !
The nodes contained also taxonomy terms and all is good !
Thanks :)
Comment #18
a.milkovskyPatches do not create referenced entities but just copies their ids.
Do I understand it right?
Comment #19
danielb CreditAttribution: danielb commented