| Project: | Feeds |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I am looking at using Feeds to import CSV data as nodes and wanted to assign all the nodes coming from a particular configuration to a specific user.
Seems this can be achieved relatively simply by adding a variable through FeedNodeProcessor.inc. A variable in the configDefaults() function, a field (with autocomplete) to the configForm(), and pulling that value out and assigning to node at the process() function.
I've attached a file that shows the final UI.
If this makes sense as functionality to have within Feeds and the method is ok (or could be improved) happy to roll a patch.
One complication might be that if one wants to assign different nodes to different users at the node import stage, based on a value in the feed through a mapper we would have to override the user assigned through the method described here (or resort to this user as the default one).
| Attachment | Size |
|---|---|
| assign_author.png | 73.87 KB |
Comments
#1
If we get user assignment to nodes we should offer at least 3 options:
- anonymous
- specific user (this screenshot)
- inherit from feed node (only available if an importer config is actually attached to a content type).
I'd appreciate your patch as it's a step in the right direction. Ideally we can get the inherit option before committing. In any case, this feature warrants tests.
#2
I also need this functionality.
In FeedAPI, I had the 'source' content type called feeds, and I had a node that initiated the download/import. In this case, I was able to set the authoring information on that node. All of the resulting imported nodes were then owned by the author information specified. In your example I am guessing this would be 'inherit from feed node'.
In Feeds, I have the exact same setup - source content type Feeds, a CSV feed configured, and authoring information. In this case, it is not respecting the authoring field. All of the resulting imported/created nodes are owned by 'anonymous'.
I don't quite know how to develop this, but I would love to have it fixed if someone submits a patch.
In FeedAPI, it seems this magic happened in feedapi_node.module, in the _feedapi_node_save function. There is a $node->uid = $feed_node->uid; statement right before the node_save($node); at the end of the function. I'm assuming this is what set it.
#3
OK, here is my completely unscientific patch that replicates the functionality from FeedAPI. I simply grab the node ID of the feed node, run a node_load against it, and map the UID. There is probably a better way to do this that doesn't involve node_load, but I really needed this to work tonight.
I'm wondering if it's a better idea to move the node_load above the foreach. That way it is loaded only one time.
#4
#3: certainly one of the puzzle pieces required here. Setting to NW as there's a patch.
#5
Here's a new version of the patch. The only difference is the node_load was moved outside of the loop. Now it just does a single node_load of the original feed node instead of doing it on every loop. I don't believe it would ever change so I don't think it really needs to be done inside of the loop.
#6
Setting the status back, sorry it defaulted to active.
#7
Just posting the patch that adds the functionality as shown in the image at the top for now - @rjbrown99 definitely adds another piece of the puzzle - will try to incorporate both as soon as a I get some time.
To sum up we have two scenarios so far:
1. The author of the imported items is set to be the same as the author of the Feed (in the case where you do create a feed and its not a standalone import)
2. The author of imported items is chosen from amongst the users through the config form
We should have an option to either do 1 or 2 but only when we are importing via a node as 1 does not really apply when importing on standalone.
Should also write some tests for these as well eventually
#8
Yes, scenario 1 in #7 will be much helpful and needed very much as this is what happened normally with feedapi-6.x-1.8 and this is what is normally expected in a multiuser scenario.
For example, let us suppose a drupal site like blogger.com, where each user has his blog and wants to occasionally import from feed of his other blogs, like wordpress.com blog or similar. What he imports need to be under his authorship in his blog (irrespective of whether he is the true author or user names are same across the net).
Assign_author.png is good at the "Admin" level, but at user (auth user) level the user needs to simply have the feed items/posts filling up his blog as blog posts (when feed item=blog content type)
Thanks for the patch, I got refererred here from #664348: Blog posts imported by an user do not show up in his blog and will highly be obliged if a patched FeedsNodeProcessor.inc is made available for download as a whole file.
#9
As I'v blogged about at http://hojtsy.hu/blog/2009-dec-17/highlighting-some-tweets-my-blog-exper... I'd be very supportive of this functionality. (Did not test the actual patch yet).
#10
Hi,
got a patch that covers the three cases - default to anonymous, can set user explicitly or inherit from Feed node (if Feed attached to Node).
UI wise it is all in settings section of NodeProcessor. Ideally the inherit author setting should be grayed out if the Feed is not set as "attachable" to a node - any suggestions on how to achieve that simply would be great.
Didn't test extensively - but hope this helps to move things forward.
Also, user choice happens outside the loop to avoid having to repeatedly load the Feed node to get the user id.
Attached is the Patch, the entire FeedsNodeProcessor (just replace your existing one..) and an image with the UI.
#11
The patch doesn't apply (it needs to be with the module folder as root, not drupal as root).
If applied manually the patch works as expected, but here is a style review.
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
-
+
+ //The user id to assign to FeedItems
Trailing space on the empty line.
There should be a space after //
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
+ //If Feed is not attached to a Node or inherit author not set assign user
+ //based on the explicit author setting
Agains space after the //
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
+ if (($source->feed_nid=='0')||$this->config['inherit_author']==0){
It needs space before and after ==, ||, ==. There should be a space between ) and {. There is trailing spaces at the end of the line.
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
+ //Load the user object based on the user name
It needs to be inline with the code below it. It needs a space after //
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
+ //If Feed is attached to a Node check whether user asked for Feed Items to
+ //inherit from Feed node author
Again space after //. Remove trailing space after the first line.
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -18,7 +18,23 @@
+ elseif ($this->config['inherit_author']==1){
Space before and after ==. Space between ) and {
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -60,8 +76,8 @@
+ $node->uid=$feed_item_uid;
Space before and after =
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -150,8 +166,10 @@
+ 'explicit_author'=>'anonymous',
Space before and after =>
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -150,8 +166,10 @@
+ );
Trailing space at the end of the line (nothing else changes in this line)
+++ sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc 28 Dec 2009 22:00:39 -0000@@ -181,6 +199,24 @@
+
return $form;
No need to add the empty line, but if you do, remove the trailing space.
This review is powered by Dreditor.
#12
Ok so i tested this patch and it works wonderfully. It applied correctly to HEAD. I reworked the patch to patch from the module root and I believe I made all the style changes mentioned above.
Thanks istos & rjbrown99 for the work!
#13
Great.
1. "Feed attached to Node" should be "Importer attached to Content type" - on UI and in code.
2. Add a period after all comments.
3. Can we grey out the widget for inherit_author if the importer is not attached to a content type?
4. Both modes: inherit and explicit need tests.
#14
excellent - thanks all. should be able to have a look at this next week I absolutely agree with 3 from alex_b, just need to have to figure out a good way to do it.
#15
Some of the code in FeedsNodeProcessor.inc will change if/when #600584: Use Batch API is committed. This patch currently conflicts with #7 in that thread.
Assuming that patch is applied first, only the first hunk of this fails. It's pretty trivial to reconcile, but I thought it was worth mentioning.
#16
Subscribing
#17
thanks a lot. this is exactly what i needed.
edit: as mentioned above this patch isn't working anymore in alpha-11 due to code changes.
#18
I need this feature too!
One idea: create a rule to set the owner when a new feed item node was created!
#19
This is a necessity for a site I am currently working on.
Please fix to work with Alpha 11
Thank you for awesome module
#20
This is great if you're using the Feed API method and attaching feeds to a feed node, but what about support for the stand alone form? In a number of the use cases I've worked with we wouldn't actually want a whole content type just to attach the import form to. Feeds claims support for this, and starts to provide it - but falls very short in a number of cases like this where it goes back to relying on feed_nid.
Right now I'm getting around this by just hard coding a nid in a custom node importer class which is easy enough thanks to the way feeds was built, but some of this would be nice out-of-the-box.
How would you propose UID selection for nodes generated from a stand alone form? One thought would be to provide a drop down or some other form element (perhaps just a field where you enter a UID) on the node processor's configuration. If there are some consistent thoughts on this topic I can likely through together a patch.
#21
#20:
This is actually taken care of. See the patch in #12 and my suggestion in #13 3.
Revisiting the patch in #12 I notice that we shouldn't store the user's name but her uid. The name can change.
There are some rough edges, indeed. One of them that using "feed_nid" as a variable name to identify a source is plain misleading. It should be "source_id" or plain "id" (although that starts to conflict with FeedsImporter's id). However, there aren't many hard assumptions on that feed_nid is actually a node. If there are, we should clean them up. Recently I used feed_nid to attach sources to users (uid = feed_nid) without any problems. Please open follow up issues if you find concrete items that need clarification or clean up. Thanks.
Related: #702734: Rename FeedsSource->feed_nid to FeedsSource->sid and FeedsImporter->id to FeedsImporter->name
#22
Ah, that's what I get for not taking the time to read over the entire issue. Sorry about that Alex. I knew I'd glanced over this in the past and had missed that addition when coming back today.
I'll review the other items I was having troubles with and see what their state is and open issues as needed. Thanks!
#23
Quick re-roll of #12 against CVS HEAD. I tried to account for alex_b's comments in #13, although I didn't see an easy way of doing item 3. I'm not seeing a good way of determining the state of content type attachment from FeedsNodeProcessor::configForm();. If you have some ideas I'd be happy to try it again. Also, no tests. I don't have the time at present to roll them.
#24
The configuration of a plugin is present as an array (from within a plugin) at $this->config.
#25
Right, but within FeedsNodeProcessor::configForm(); $this is the FeedsNodeProcessor object, and $this->config only seems to contain the mappings and items from FeedsNodeProcessor::configForm();. I'm not seeing the content type attachment setting. I'm sure it's probably available, I just haven't found it.
#26
Uh - sorry. The content type attachments are importer level. You can get them through feeds_importer($this->id)->config from within a processor.
There is only one possible importer for a given processor and that is the importer with the same id.
#27
Thanks for the patch but No 3 is the functionality I am chasing. Using the default RSS importer, changed to import blog posts, I need the Author of the imported blog posts to be the same as the author of the feed used to import them.
My php knowledge is is not up to this challenge but I would be happy to test.
Thanks
Gregg
#28
For what it's worth, I moved to using the patch from #12 which does what I originally wanted it to do in #3. I create a node of type feed which contains my feed settings. While editing that node at the bottom in the "authoring information" section, I assign the owner to be the user ID of whoever I want to own the created nodes. During the creation process it correctly sets the owner of the nodes.
Look at your feed node and make sure you have authoring information set to the correct user.
#29
Thanks.
I tried this but my use case involves a variety of different users importing blog posts through Feed.
The posts need to be the same author as the feed and they do not have access to the feed importer settings to manually set a userid
Any other ideas?
Thanks
Gregg
#30
Is there a way to map a drupal user to the author of the feed entry? I'm thinking on matching the feed author field with a profile field on user accounts or something similar. Any ideas?
#31
any updates on this?
is any possibilities to know when this patch will be updated to the latest release?
#32
4vinoth: What you see is the state of the art. Patch should apply against 6.x 1.x dev.
#33
OK alecx, Thanks for the update,
But when I can expect this issue is fixed, because without this i am unable to use this module. :(
#34
#33 - Looking at the movement on this issue in the last days and weeks, I wouldn't wait for anybody. You will either have to step up yourself and work on the patch or get somebody to do it for you. Remember, this is open source ;-)
#35
I applied the patch from #23 - worked fantastically. Are the maintainers of the Feeds module planning on making this a part of the first dev release?
Anyway, thanks for the work you guys put it on this - you got one thankful 'customer' !!
#36
#23: great.
The plan is to commit the patch when #13 - 3 and 4 are addressed. I am looking for volunteers to bring this puppy home.
#37
Subscribe - this causes a headache for content managers who have to sort the imported content, as they have to switch the input format manually from Filtered HTML to Full HTML, since the anonymous user defaults to Filtered HTML :(
#38
Hi alex_b was trying to figure out where I should be looking so that we can make a decision about whether to grey out the checkbox or not (point 3 of #13).
I thought it would be a case of having to check the value of $this->config['content_type'] that is available in configForm. However, no matter what the setting of Attached To in the actual form that variable is always feed_item. Which means that I am probably looking in the wrong place so any pointers would be greatly appreciated and I will try to take care of the remaining bits to wrap this issue up.
#39
I just found this issue. FWIW, I posted a patch on Feeds Inherit settings from parent feed node (like taxonomy). All I did was merge the feedapi inherit code into feeds. So it allows you to have your feed items inherit the following settings from the feed node: organic groups, author, taxonomy, and language.
Should one of these issues be marked as a duplicate of the other?
#40
#39: Indeed, there is overlap on the inheritance patch that picked up speed now: #632920: Inherit properties from parent feed node (taxonomy, author, OG, language). That patch will cover the inherit author option. This patch can now focus on assigning a specified user to a feed item.
#38: this question is now not relevant anymore, but what you're looking for is:
feeds_importer($this->id)->config['content_type'].#41
great - so should we assume that if a user assigns an author through the Feed setup form they don't want to inherit settings from the node and perhaps make that assumption clear in the interface? - something along the lines of "setting the author here will override the Feed node author"
#42
The contradiction is pretty self explaining, right? I would suggest to deal with this on validation - throw an error with a brief explanation if both options are set:
"A feed item cannot both have an assigned author and inherit its author from the feed node."
#43
I can confirm that patch from #39 works nicely to fix the author inherit issue.
It does not seem to be inheriting the authors default input filter so all imported items still default to the site default which in my case is plain text.
#44
I second #30.
The best approach strikes me as a custom mapper that tries to find the source author in the local usernames. Failing that, default to the selected UID assignment described here.
Should something like this be in a separate project?
<?php
/**
* Implementation of hook_migrate_fields_node().
*/
function feeds_usermapper_feeds_node_processor_targets_alter(&$targets, $content_type) {
$targets['uid'] = array(
'name' => t('Node author'),
'description' => t('The owner of the node.'),
'callback' => 'feeds_usermapper_feeds_set_target',
);
}
/**
* Mapping callback for author.
*/
function feeds_usermapper_feeds_set_target($node, $target, $value) {
// [insert optional username transformation here]
$user = user_load(array('name' => $value));
if (isset($user->uid)) {
$node->uid = $user->uid;
}
}
?>
#45
subscribing
#46
subscribe
#47
#44/#30: yes. This patch should either accept a uid or a name for specifying an item's author.
#23 accepts a name.
In order to make sure we're all on the same page, I'll reiterate what I've stated in #40: #632920: Inherit properties from parent feed node (taxonomy, author, OG, language) will cover inheritance of authorship from feed nodes, hence this patch can focus on assigning a specific author user to a node.
#48
subscribe
#49
I applied the patch in #23 to Alpha 15 and get a 500 error when visiting the admin section of feeds, anyone else having this problem?
#50
Hi, updated patch for this. It will now work against current head.
Given that inherit author from feed node issue gets solved somewhere else the option to assign a user explicitly only shows up when you choose Standalone form as an option.
Still doesn't handle assigning a user by uid which I need to fix but at least the issue is re-activated and people can go ahead and look at this once more. Will do more testing + refinements over the next couple of days.
---
one note: in order to check whether this is a standalone or whether it is attached to a content type I use
feeds_importer($this->id)->config['content_type'] == ''maybe we could assign a specific value to this (e.g. 'none')?
#51
I am assuming a few things here and may be wrong so with that said, I assume #50 is a reply to #49, and acknowledges that patch feeds-652180-2.patch (#23) does not work with Alpha 15. I also assume that the patch in #50 is meant to be applied after the patch in #23. If all these assumptions are correct I have a Hunk #2 FAILED at 68 error. If my assumptions are incorrect then it is only logical that I have an error.
#52
#50: The patch should store a uid for an assigned author instead of a name. Thus we can avoid doing a user_load() when it's expensive: when importing items. configFormValidate() might be your friend here.
Further, it assigns a user object to $node->uid which will break.
#53
#52: Now storing uid (but only showing users the user name) - configFormValidate is a friend - hope I used it properly.
silly mistake the result of last minute re-org. Not a problem anymore - tested a bit before submitting :-)
#51 hampshire - you don't need to apply any other patch. This patch should apply against the latest version of Feeds from CVS head.
ronald.
#54
This is looking good. Need to get some time to do a good review.
#55
- simplified
- added tests
I am going to commit this soon.
#56
Committed. Thank you.
http://drupal.org/cvs?commit=382136
#57
Automatically closed -- issue fixed for 2 weeks with no activity.
#58
I am new with Feeds, still wandering in its quite complex settings and future promised features (compared to Feed API we are invited to move from)
Apparently, this was committed in Beta 2, and it only gives the possibility to assign a specific author to all feed items coming through a given importer. If I set several Feeds, all items get the same author or anonymous depending on the choice.
It seems that it was discussed here (#30, #44) the possibility to inherit the author from the feed item, at the item level, but I don't find any such option.
1) is the latest beta2 incorporate the discussed features?
2) If yes, does it provides the possibility to inherit the author name from the feed item (providing the name matches a Drupal user I suppose)?
3) If yes, how to do that?
Thanks
#59
1-3 will be available with #632920: Inherit properties from parent feed node (taxonomy, author, OG, language)
#60
I succeeded to get the feed item authored by the Feed author thanks to
http://drupal.org/node/632920
My second issue seems to be the subject of this discussion: how to assign the original article author to the feed item Drupal node?
The node processor mapping offers the "Author" information as source, but nothing is selectable on the target side to link this to the feed item node author.
Thanks
#61
subscribing.
#62
#60: You're looking for #699176: Mapper for user id and user name
#63
subscribe
PS: I am using mailhandler + feeds to import emails as nodes.
The athor is set to some user which I never defined to do so ...
At the moment I am using a rule which changes the author after node is saved.