Closed (works as designed)
Project:
Feeds
Version:
7.x-2.0-alpha4
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Jan 2012 at 13:11 UTC
Updated:
15 Oct 2020 at 15:10 UTC
Jump to comment: Most recent
Comments
Comment #1
paispita commentedComment #2
paispita commentedIs that a difficult thing to do?
In my humble opinion this should actually be the default behavior, if not for feeds, at least for node import..
Comment #3
Richard_1618 commentedI agree, but here is a link you may find interesting http://drupal.org/node/652180 I'm still having a little difficulty in applying these patches but it looks like a more hopeful direction that anything else I've seen so far.
Comment #4
Richard_1618 commentedAny help would be seriously appreciated in resolving this issue of assigning the imported nodes to the author / user that imported them.
Comment #5
paispita commentedComment #6
paispita commentedSo by using
global $user;
$user->name
one can have access to the logged in user name.
Can anybody point out where I should use the above snippet?
Comment #7
paispita commentedAnswer:
In sites\all\modules\feeds\plugins\feedsnodeproccesor.inc, on line 31 one must replace the whole function with this:
protected function newEntity(FeedsSource $source) {
global $user;
$node = new stdClass();
$node->type = $this->config['content_type'];
$node->changed = REQUEST_TIME;
$node->created = REQUEST_TIME;
$node->language = LANGUAGE_NONE;
node_object_prepare($node);
// Populate properties that are set by node_object_prepare().
$node->log = 'Created by FeedsNodeProcessor';
$node->uid = $user->uid; //Changed functionality - the author of the node is the name of the user who imported it.
//$node->uid = $this->config['author']; //original
return $node;
}
Comment #8
paispita commentedComment #9
Adam Wood commentedApologies in advance if this patch isn't suppose to do this!
I'm trying to allow users to add their blog via RSS, and assign their username to the nodes created. This patch has worked well for the initial import, however when new items are imported periodically, via cron, then they are reassigned to 'anonymous'.
Is there a way to set this so that the user who created the import is assigned as the author of all nodes created, not just the initial import?
Also, should this be committed to the next release as a standard option? As I'd imagine that people would need to use this functionality quite often.
Thanks
Comment #10
Adam Wood commentedAfter spending days looking at this, it turns out you can do this by default using the mappings for the import. The patch above isn't necessary to achieve this.
That's it. The initial import and (in our case) future RSS imports will all be assigned the ID of the user who created that import node.
Hope this helps anyone else on this. This should really be in the documentation...
Comment #11
davemaxg commentedThanks Adam!
Comment #12
blogook commentedBut what if one chooses to use stand alone form?
When I use the above mentioned method, 2 nodes are created .. one that is fetched by the feed and one that is created ..
Comment #13
blogook commentedmy problem is solved
https://drupal.org/node/1796008
Comment #14
Magicthought commentedWell said Adam Wood, it made my day!
Comment #15
WorldFallz commentedOk, i give up. I've been searching for the 'correct' way to do this for several hours across a couple of days now. And every single thread I've found assumes the use case of using a feed node. I have about a dozen of these and I don't want to create 12 content types and all those nodes just to be able to set the author of an import. that's just crazy, lol.
Using the STANDALONE form there is no "Feed Node: User ID" to use. And the author field allows selecting any user, but not the user doing the import ($global $user;).
Has anyone figured out how to set the user nodes imported using the standalone form to the user doing the import? I don't care if it's code. This comes close, but I can't believe I have to do an additional node_load on all imported nodes.
I'm thinking one of the feeds hooks should do it, but I've been unsuccessful thus far.
I can't believe this is that unique a use case. Either I'm missing something blatantly obvious, or I'm just doing something weird, lol.
Any info/insight would be greatly appreciated.
Comment #16
WorldFallz commentedI'm an idiot, lol. Didn't read the whole post.
Here's how to do it without hacks and without additional node_loads:
Comment #17
nithinkolekar commented@blogook how #1796008: two nodes are created worked for this issue? could you please share your configuration/setup?
Comment #18
gregceni commentedThanks Adam & WorldFallz, I'm close but they're still going in as "Anonymous (not verified)". I have a .csv of 4 new content items of a content type called 'course_listings'. I'm *not* attaching the Feed to this content type because I want it standalone.
Does one add that code snippet to the feeds.module or the feeds.api.php? And do I still need to add the Source=Feed Node: User ID and Target=User ID? I've tried all those combinations but my nodes are still going in as Anonymous.
And the "MYMODULE" part doesn't apply (or does it?) because this is not a custom module. I realise this can get clobbered.
// feeds.api.php
Comment #19
WorldFallz commentedYou need to create a custom module for this and replace the "MYMODULE" portion of the function call with the name of your module.
Comment #20
gregceni commentedWorldFallz, awesome. Thank you. I made a new module (new course.info and course.module files in /sites/all/modules/custom/) with only that "*_feeds_presave" function in it, changed the names of the 'hook' and 'entity_type', tested it in masquerade mode and voila! Thank you!
Comment #21
Qadees commented@gregceni, Please what file extension did you give to the module you created in custom directory, and what is suppose to be the 'hook' name.
I know this may awkward after long time asking for it again. I created the file and dump in custom module directory but it didn't work.
Any help please.