Forgive me if I'm being dense. I've read all the open and closed issues regarding using Feed Items (Feeds item: Item GUID) to specify and update unique nodes. However, from what I can tell, this just sets a unique GUID upon import, which can then be used for future updating. If you are trying to update an existing node that was not created in this same way, no GUID exists and consequently the node cannot be updated via Feeds.
In D7 you can target the node ID, which exists for all nodes regardless of how they were created. Is there a way of doing this in D8? Or does the GUID exist for all nodes and I am just unaware of it?
Thanks for any info. Also, after having read these many issues I must say thanks for all the many hours and years of time spend on this module. It's much appreciated!
Thanks,
Mike
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | feeds-entity-id-2989279-20.patch | 21.89 KB | megachriz |
Comments
Comment #2
megachriz@Mike
A GUID value for an entity only exists when you inserted or updated that entity with Feeds and when you mapped to Feeds Item GUID. Or when you programmatically set a value for it.
Besides the GUID, other targets can be set as unique as well. Targets that generally can be set as unique are text fields, urls, email fields and telephone fields. I believe there is a feature request to allow number fields to be set as unique target as well.
There isn't a target for node ID indeed. I'm not sure how hard it will be to add that one. Let's turn this into a feature request for adding that.
Comment #3
argogi commented@mxwright did you ever solve this? facing the same issue, hoping to update entities with the only unique fields being photos and entity_id.
Comment #4
mxwright commented@argogi no unfortunately I haven't had the time, nor frankly the D8 chops, to tackle this. For me it's an almost essential part of Feeds that's still missing. I'm hoping to take a closer look soon.
Comment #5
back from 7 commentedThis is a feature that is needed. Old D7 uses NID as references to other content.
Comment #6
carolpettirossi commentedI would definitely use this feature if it was available.
I need to update some existing content created via UI. I've tried to add target to URL alias, but the Unique flag is not available.
Any ideas on how can I contribute? Is it difficult to add this target?
Thanks,
Carol
Comment #7
megachriz@carolpettirossi
Firstly, you need to create a new FeedsTarget plugin and figure out how it can set the ID of an entity. An extra challenge is that the ID of existing entities cannot be changed. So this should somehow be clarified in the user interface. And if someone tries to change the entity ID anyway, the import should fail.
It would be great that if someone maps to entity ID that "unique" is ticked by default.
So these requirements do make this feature harder to implement than other field types. Because it is easy for users to make errors with this target. And these errors should thus be catched and explained to the user. It would be a plus if errors can be prevented early on in the user interface, for example that the mapping form wouldn't allow to tick out the "Unique" checkbox for the entity ID target.
Great that you want to give it a shot.
Comment #8
megachrizWorking on this...
Comment #9
megachrizI figured out that Feeds doesn't display a target to entity ID, because Drupal has marked it as read only and because Feeds skips read only fields.
So this patch in fact exposes all read only fields, including entity ID. But I've made it so that Feeds only sets a value when the field in question doesn't have one yet. Because else I found out that you could run into the following error:
This is because Feeds always tries to empty targets first. And emptying entity ID apparently isn't allowed.
The patch depends on the patch from #2829283-82: Language support in Feed import.
And you'll probably also need the patch from #2918222: Use Number fields as unique mapping target in order to make this one useful. Without that patch you cannot set entity ID as unique target.
Comment #10
jamesdixon commented#9 failed to apply in latest 8.3.x dev so I rerolled it.
Comment #11
megachriz@jamesdixon
Thanks for helping, but it looks you forgot to upload the patch file. ;)
Comment #12
jamesdixon commentedAh made mistake uploading two files. Here we go!
Comment #13
mxwright commentedHaven't tested this latest patch yet, but in #9 two other patches were referenced - it looks like those have since been committed.. So we should be good to test this patch alone on the latest dev?
Comment #14
megachriz@mxwright
Yes, this patch can be tested on top of the latest dev. The other two mentioned issues are indeed done and their patches are in dev now.
In #2829283-100: Language support in Feed import an issue related to importing aliases was reported by @qdoscc:
On which I responded with:
So that implies that this patch could introduces issues for importing path aliases. I know the Pathauto module marks the path alias field as read-only, so I assume that module must be installed for the issue to appear.
Comment #15
jamesdixon commentedThis patch allows mapping to read only fields. It was tested to map to the read only name field for Entity Queues successfully:
#3106819: Error while importing Node Queues in D8
Comment #16
jamesdixon commentedMegachriz gave us some direction on what is needed next:
@jamesdixon Thanks for checking, the next step for that issue is:
Automated tests.
Check how this affects importing paths - using the node processor. I thought this was no longer possible since Drupal 8.8, but maybe I’m wrong about that.
Comment #17
megachrizThis patch adds the following:
And these tests also check that there are no SQL related warnings in the process.
entitySaveAccess(), the entity owner does not exist during kernel tests when their ID is 0. Therefore the invalid user warning is not triggered when the entity owner ID is 0.Next step: check how this patch affects importing aliases.
Comment #18
megachrizI forgot to add a test group for the kernel test "EntityIdTest".
Comment #19
megachrizI think that this patch fixes the issue for when importing paths.
You do need the patch from #3163927: Add supporting of pathauto when using the Pathauto module.
Comment #20
megachrizReroll (required after committing #3163927: Add supporting of pathauto).
Comment #21
govind.maloo commentedHi @MegaChriz
This is working as expected. I am ale to import data now. This also fixed the issue https://www.drupal.org/project/feeds/issues/3106819
We can merge this now.
Comment #22
tanubansal commentedYes its working fine and can be moved to RTBC
Comment #24
megachrizThanks for testing! Committed #20 with coding standards issues fixed.