Updated: Comment #31
Problem/Motivation
Integrate Relation with Feeds module so that Relations can be created from Feeds sources.
Proposed resolution
New module implementing Feeds APIs and adding needed Feeds plugins.
Remaining tasks
Directional binary relations are working. Other types of relations still need work. Module has been committed already to enable automated tests.
User interface changes
New processor for feeds
API changes
New sub-module, 'relation_feeds'
Related Issues
- none yet
Original report by @philipz
Did anyone try or has some ideas on how to approach importing relations with Feeds? I guess this might be a combination of generic entity processor and some custom relation targets.
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | relation_feeds-1345958-39.patch | 9.36 KB | mikran |
| #39 | interdiff.txt | 612 bytes | mikran |
| #33 | interdiff.txt | 3.41 KB | mikran |
| #33 | relation_feeds-1345958-33.patch | 9.26 KB | mikran |
| #32 | relation_feeds-1345958-32.patch | 8.33 KB | mikran |
Comments
Comment #1
killtheliterate commentedI'm interested in this as well.
Comment #2
rowerlowe commentedme too :)
Comment #3
batje commentedI just tried this with patch 69 from the above issue.
How far I got:
I can select a 'Entity processor Relation'
On the settings page of the Entity processor, the field 'Endpoints' is mandatory. I filled in "node:iati_activity,node:iati_organisation" (but anything will save)
The big issue appears to be the fields that you can select on the Mappig page. The only fields available are Relation Type, Endpoints and rid. (plus GUID and Temporary Field, which are provided by Feeds)
It seems that Relation wont be able to work with a generic solution. Especially the lookup of the Nids of the Endpoints (using the GUID feeds way) will require some custom code.
I have about 30 records so far, so I'll opt for manual for the time being.
Comment #4
Anonymous (not verified) commentedI'm currently work on a feeds integration patch for relation, but there's a weird architectural problem to address. It would make sense to have a separate Relation entity processor and handle the actual endpoints mapping via hook_feeds_processor_targets_alter; however, this approach is limited as endpoints are multidimensional fields that would have to exist beyond the scope of a single item returned from a feed parser. This is currently not possible in feeds.
My direction so far, as there can only really be a single
entityendpoint field per relation bundle, is to tie it all within a relation entity processor, which has access to all data in a single feeds item.The other issue is knowing which entity is referenced via an endpoint. I suggest following the model approached by the references module, that is allowing users to choose between mapping based on another feeds GUID (which has the added benefit of returning the entity type of an item natively), but if we were to ask for the ID of the entity, then we can't infer the entity type, which causes problems with relation entpoints that are non-directional or where multiple entity types are possible within the target or source. We could allow the entity type to be mapped as well, but that would require the Feeds Tamper to provide a default value unless the value is embedded with in the feed data itself, which is dubious. For one, I think the UX problems with Feeds Tamper as well as the complexity it adds to feeds that a user may not have control over is not a good way to go. I'm leaning to allowing users in the processor settings form, as opposed to the mapping form, to set the entity type for the source and target, which is less flattering, but certainly more stable.
Comment #5
Anonymous (not verified) commentedAttached is a patch to feeds that works keying off of the feeds GUID of the other items, or the entity ID itself. There's a few todos marked in there, plust it needs tests, but it works well.
Comment #6
gmak commentedI'm getting the following error after patching:
Could this be caused by the files not being the correct location? Where does the RelationFeedsProcessor.inc need to be placed?
Thanks
Comment #7
Anonymous (not verified) commented@gmak - the relationFeedsProcessor should just be in the relation module location. You might need to clear cache twice in order to see the feeds processor if you alreayd have these modules enabled.
Comment #8
castelar commentedGetting these notices/warnings on mapping page:
Notice: Undefined index: in RelationFeedsProcessor->getTypeInfo() (line 188 of ....RelationFeedsProcessor.inc).
Notice: Trying to get property of non-object in RelationFeedsProcessor->getMappingTargets() (line 398 of ....RelationFeedsProcessor.inc).
Warning: Invalid argument supplied for foreach() in RelationFeedsProcessor->getMappingTargets() (line 398 of ....RelationFeedsProcessor.inc).
Notice: Trying to get property of non-object in RelationFeedsProcessor->getMappingTargets() (line 398 of ..../RelationFeedsProcessor.inc).
Warning: Invalid argument supplied for foreach() in RelationFeedsProcessor->getMappingTargets() (line 398 of ..../RelationFeedsProcessor.inc).
Comment #9
shawn dearmond commentedPatch in #5 applied to today's git pull.
However, in my testing, I received an error upon import.
I made one change to the code in line 177 of RelationFeedsProcessor.inc:
Now it works with entity ids.
@kevee's right, though, it could probably use some tests.
Comment #10
shawn dearmond commentedOops! Forgot to add the new file. Don't use #9. Use this one instead.
Comment #11
olofbokedal commentedFixed an SQL error when expiring imported items.
In the
expire()function,SELECT 1 FROM {relation} n JOIN {feeds_item} fi ON fi.entity_type = 'relation' AND r.rid = fi.entity_id WHERE fi.id = :id AND r.created < :createdchanged to
SELECT 1 FROM {relation} r JOIN {feeds_item} fi ON fi.entity_type = 'relation' AND r.rid = fi.entity_id WHERE fi.id = :id AND r.created < :created.Modified the patch from #10.
Comment #12
alexwoods commentedThe import will fail with an unuseful error message if no entity matches one of the endpoints guids. Checking that $entity_feed has a value at line 170 results in bad relations of this sort being skipped.
Comment #13
kououken commentedPlease excuse my ignorance, as I know very little about Drupal's API and its inner workings, but I would really like to be able to use this functionality to import thousands of relations, and unfortunately can't seem to find a combination of source and target mapping settings to successfully import any. I attempted to contact some of the above posters privately without any luck.
The patch currently offers the following ID-like options in the mapper settings:
My question is, which of these corresponds with a relation's intended endpoints? I have tried every combination I can think of and none seem to work. (some combinations will say "Added X relations", but none are created)
For example, if I had existing content such as:
...and I am trying to import a relation "is similar to" from the data:
...what should my mapper source/target settings look like? I feel like if someone can answer this for me I should be able to troubleshoot the problem on my own, but I'm currently a bit lost in the huge array of possibilities between Source, Target and Unique Target options.
Any help or simple example mapper settings would be greatly appreciated!
Best regards,
Daniel Dupriest
Comment #14
kingswoodute commentedSubscribe - feeds integration would be great!
Comment #15
mikran commentedI added an option to skip duplicates. Ideally I would want such setting to endpoints only I think but for now entity hash is used to check this. What you think?
I'll continue working with this, fixing the issue raised in comment 12 and other watchdog errors.
Comment #16
mikran commented* uid added to new relations
* GUID vs entity ID check fixed
Comment #17
naught101 commentedPatch has multiple trailing spaces. See #1987056: Stick to the coding standards
Comment #18
mikran commentedI've opened this issue #1950182: Only update when mapped fields are updated. in feeds queue, it should help when importing unique relations.
Comment #19
mikran commentedwhitespace fix
Comment #20
vadym.kononenko commentedI've added fix for the correct work of this patch with 'blank source' fields produced by the 'Feeds Tamper' module.
Patch 'relation-7.x-1.0-rc4-feeds-processor--feeds-tamper--lowercase.patch' shows my changes from the state #19 of the current issue (https://drupal.org/node/1345958#comment-7462628).
Patch: 'relation-7.x-1.x-dev--feeds-integration.patch' is the accumulated patch for the DEV version of the 'Relation' module.
Patch: 'relation-7.x-1.0-rc4--feeds-integration.patch' is the accumulated patch for the latest supported version of the 'Relation' module.
Comment #21
aaronbaumanI'm using the a "Feeds GUID" to "endpoints" mapping, and RelationFeedsProcessor causes a fatal error if the endpoint is not found by the GUID.
This is because RelationFeedsProcessor doesn't check its results before assigning endpoints, which eventually causes entity_load() to be called on an empty id, which causes a fatal error in common.inc
I'll provide 3 updated patches, same as those in #20.
Comment #22
aaronbaumanComment #23
mikran commentedFeedsProcessor adds 'bundle' field to config form and that's exactly the same as added 'relation_type' field. Attached patch removes the duplicate field.
'relation_type' was used for mappings earlier and now that it's 'bundle' from FeedsProcessor the existing importers are obviously now broken.
Comment #24
mikran commentedAnother patch. I added some tests as well as made some minor code style and documentation changes.
Tests are not passing cleanly at the moment as endpoints are configured as
user:*.Comment #26
mikran commentedI changed 'skip_duplicates' config setting to 'unique_enpoints' and that can be used to update existing relations if other unique mapping targets are not available.
Next, I'm wondering if it is really needed to override FeedsProcessor::process().
Previous patch still can't find Feeds test class so I'm leaving this as 'needs work', but reviews are welcome :).
Comment #27
mikran commentedSeveral changes this time around. I moved all the code to separate sub-module 'relation_feeds'. This new sub-module has dependency to feeds so tests should now work. It was surprisingly easy to get rid of the overridden FeedsProcessor::process(), unless I missed something big.
Tests are passing locally so let's see what test bot thinks.
Comment #29
mikran commentedSplit off to module requires some additional things, and some renames I missed
Comment #31
mikran commentedI completely forgot that test bot can not use dependencies from patch files before those are committed. So I'm committing patch from #29. It's separate module so not much harm is done either way, but I'm pretty sure tests should pass (they do so locally).
So a fresh patch for further development from now on.
Comment #32
mikran commentedNew patch, binary, unary, n-ary relations should all work now. If testbot gives green I'll have a break from feeds integration for now.
Comment #33
mikran commentedAdded FeedsValidationExceptions - instead of just skipping invalid endpoints.
Comment #34
aaronbaumanafter updating to latest version, i don't have any relation fields available as mapping targets.
existing feeds importers that did expose the fields are broken now with "Missing" in the "target" column.
i'm guessing this has something to do with changing the namespace.
Comment #35
anybodySame problem here.
Comment #35.0
anybodyIssue summary added
Comment #36
vistree commentedHi, I installed the newest dev to get the new submodul (relation feeds). After that, I applied the patch from #33
Now in feeds, I can create a Relation processor. But - no individual fields appear in the mapping list. Under target, there are only global fields like GUID and Relation ID.
Does anyone know, if this is still a problem with this patches here, or if I did something wrong?
Comment #37
mikran commentedThere should be a bundle selector in processor settings where you can select the relation type. I'm using this on almost daily basis and it works just fine for me.
Comment #38
vistree commentedHi mikran,
yes, I already set up the bundle (Tab "Relation processor"). But my individual fields don't show up in the mapping tab ...
Is my installation path correct? I first installed dev from 2013-Oct-01, than I added ONE patch (#33). Or do I have to add also an other patch?
Kind regards and a nice weekend!
Comment #39
mikran commentedActually you're right. Entity fields are not there. Here is a new patch
Comment #40
mikran commentedComment #41
mikran commentedComment #42
mikran commentedNow that #1033202: [Meta] Generic entity processor is in RelationProcessor should most likely extend FeedsEntityProcessor.
Comment #43
mikran commentedI've just committed latest path from this issue. Earlier version of feeds integration was not usable at all so this fixes that. Other improvements, such as generic entity processor related ones, can be opened as follow-ups. Marking this as fixed, it's about time to push a new release of Relation out.
Comment #45
dqdawesome! great work! ++