I've seen requests to be able map to username - was done in D6 but not in D7 that I could find.

I've also seen requests to use parent node's author as the feed item author, or the current user (same thing as I understand it) -- I believe this is supposed to be working, but wasn't for me.

Plus I had a third need -- to be do the above two interchangeably on the same field mapping.

So here's my patch which provides a new mapping option:

Node author: if value is numeric, the Drupal User ID. If value is non-numeric, feeds will attempt to look up the Drupal user id by this name. If value is ommitted (or a username lookup fails), user UID is inherited from the feed author / form submitter (ie. current user). Username lookups are case-insensitive.

Best of all worlds as far as I can tell.

Let me know how it works for you....

Shiraz

Comments

shiraz dindar’s picture

Version: 7.x-2.x-dev » 7.x-2.0-alpha3
StatusFileSize
new1.54 KB

this patch no good -- ignore

shiraz dindar’s picture

StatusFileSize
new1.54 KB

Here's a re-issue of the patch as the last one omitted a check which caused empty user field nodes to be set to anon instead of uploading user. Fixed now.

cnolle’s picture

I've tried this out (actually using the first version) and it works just fine. Good work, well done. Thank you.

ptrl’s picture

Status: Needs review » Needs work

Have problem applying the patch with git. The patch have trailing whitespaces and you cant run the patch from feeds dir.

git apply -v feeds_user_multi_4.patch 
feeds_user_multi_4.patch:11: trailing whitespace.
          $target_node->uid=$value; 
feeds_user_multi_4.patch:14: trailing whitespace.
          $target_node->uid=$loaded_user->uid; 
feeds_user_multi_4.patch:18: trailing whitespace.
          $target_node->uid=$user->uid; 
feeds_user_multi_4.patch:20: trailing whitespace.
        break; 
Checking patch FeedsNodeProcessor.inc...
error: FeedsNodeProcessor.inc: No such file or directory

Wound't it make more sense to extend the UID to check if it's numeric or if you should load the uid by username instead? The fallback should be the User you select in the node processor settings.

ptrl’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.x-dev
StatusFileSize
new1.29 KB

He is the beginning of that patch. Loading of Author on Node processor settings doesn't work. If anyone knows feeds better than me probably have an easy fix for this.

e2thex’s picture

This patch really need to just add a option for user name. User names can be numeric, so doing a numeric check is not a safe way to decide if a field is a uid or a user name.

Best to have two fields one for uids and one fir user names

dooug’s picture

StatusFileSize
new1.4 KB

The previous patches didn't apply to the latest 7.x-2.x-dev.

I agree with e2thex that the username could be numeric and would cause conflicts, so my patch includes a new mapping target for username.

ptrl’s picture

Good point. Never reflected on usernames that only contains numbers :)

Richard_1618’s picture

THANK YOU VERY MUCH!

WORKED PERFECTLY AND PATCHED LIKE NEVER BEFORE!!!

I used the (feeds_user_multi_4.patch) patch in D7

dooug’s picture

Status: Needs work » Needs review

@Richard_1618, you stated that:

I used the (feeds_user_multi_4.patch) patch in D7

As mentioned in my comment above, that patch will be problematic for user names that are numeric (for instance a user name like: 3453463). So be cautious with that patch, as it might confuse a numeric user name for a user id. You can try some of the more recent patches as other proposed alternatives.

joshuautley’s picture

Priority: Normal » Minor

#2 Did what I needed, but understanding its implementation was a guess.

After I applied the patch. I ended up discovering that I had to make map from a field that i wouldn't even use in order for the Author to be set as the current user. I feel that an alternative solution should be available in the node settings to allow for the current user as apposed to just Anonymous or a specific predefined user. Maybe add some token integration?

rocky1138’s picture

I had to make a small array of the real names-to-usernames (as my feed supplies a real full name) in order to get this to work, but once I did that it worked wonderfully. I've spent hours trying to solve this one. Thank you so much.

$usernames['My Name'] = 'myname';
$usernames['Your Name']  = 'username1';

then change this line in FeedsNodeProcessor.inc to:
elseif ($value AND $loaded_user=user_load_by_name($usernames[$value])) {

franz’s picture

This can be extended even further: If an e-mail address is provided, look for user with that e-mail. I had use cases where this was very useful.

davemybes’s picture

Patch in #7 works perfectly. Previous patches are no longer applicable to Feeds.

shiraz dindar’s picture

Glad to see the development on this from my original patch!

My third need as originally noted -- mapping numbers as UIDs and text fields as usernames from the same field -- was admittedly a very custom need and not needed in a general patch. Glad it's been taken out.

Otherwise, things look good & slightly improved upon, and the patch been used without issue. How do we move this to the next stage?

shiraz dindar’s picture

Priority: Minor » Normal
Status: Needs review » Reviewed & tested by the community

still works on the latest dev... changing status.

franz’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/plugins/FeedsNodeProcessor.inc
@@ -209,6 +209,17 @@ class FeedsNodeProcessor extends FeedsProcessor {
+          // If user name exists, load uid, otherwise use default author.
+          if ($loaded_user = user_load_by_name(check_plain($value))) {
+            $target_node->uid = $loaded_user->uid;
+          } else {
+            // Load the default author.
+            $target_node->uid = $this->config['author'];

This logic is not expected, IMO. The description says I can use both an UID mapper and this, and if the username exists, UID is replaced. However, if username doesn't exist, UID is also being replaced! I don't even think the else part is needed, as leaving untouched will save it with the default author (if another mapper doesn't alter it).

dman’s picture

#7 Works good for me, and is appropriate. - though it needs a trivial re-roll for current 7.x-2.0-alpha4

I get the concern about why it explicitly "// Load the default author." - as I think a fail to match should just leave it alone and let the system handle it as usual.
The extra clause is unexpected and can be removed.

franz’s picture

As dman said, if someone wants to re-roll and remove the else clause, this will be good to go.

coderintherye’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Here is a re-rolled patch, plus the else clause is removed

coderintherye’s picture

StatusFileSize
new1.38 KB

Whoops, didn't realize the array structure had also changed in the second bit.

Here is a re-rolled patch including that change.

dman’s picture

:-) Yeah - the array structure needed doing but I called it trivial. Not as trivial as the usal whitespace/offset re-rolls, but still :-)
(I was head down making an actual thing for an actual client at the time, so didn't go into specifics)
#21 looks like what I ended up with.

franz’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me now.

franz’s picture

Status: Reviewed & tested by the community » Needs review

Sorry, can someone else test and confirm it's working?

Mazer.Rackham’s picture

This patch is not working for me.

Articles are only published with the name provided in the authoring field if "Attach to content type" is set to "stand alone" and if "Node Processor" "Content Type" is set to "Article."

franz’s picture

Wait, is it or is it not working? Why the thanks?

Mazer.Rackham’s picture

I thanked them because I appreciate their work. Is it so hard for you to tar.gz your website, make a .git blackup and test for yourself?

franz’s picture

Mazer.Rackham, thanks for the info.

I currently have no use for this feature itself, I was merely managing the issue because when it's fully tested and working, I intend to commit it, otherwise I can't spare enough time right now to do it myself.

Mazer.Rackham’s picture

My results may be skewed as I attempted applying other proposed patches to fix the same issue. I am going to sudo rm -rf the module, and test again with the patch. If I get the same results I'll attempt to debug. THANKS AGAIN GUYS! THIS (attempt at a) PATCH IS LIFE SAVER!!

Mazer.Rackham’s picture

http://www.youtube.com/watch?v=_F3SfmWx7t8

Made a VERY QUICK (1:30 second video) about my settings and experiences with the module and what I may be able to do to help. Found it much quicker than typing everything out.

This video was made AFTER I applied coderintherye's May 11th 2012 rerolled patch!!!

coderintherye’s picture

@#30

First, video, that's awesome. That's actually a really effective way to communicate the issue. I'd like to see more of that in other queues.

Now, I think the problem you are experiencing is actually different than the one presented here.

This issue relates actually to when you click on "Mapping" and define a mapper to go from "Author name" -> "User", with the patch one should be able to map to "Author Name" -> "User name" and it should fall back to anonymous if that user doesn't exist.

Where you are setting your user isn't actually a mapping in the sense we are referring to here, it's more just a setting to make the author be who you designate for every post, independent of mapping fields.

That said, with your issue, I noticed when you typed in your author name, it didn't actually autocomplete. Just to make sure, when you typed your username out in the field, did an autocomplete box pop up below with your username to click on? It should if the username is correct.

Granted, could be wrong on all that, so feel free to chime back in.

Mazer.Rackham’s picture

I actually did that before hand. Is this correct behavior for feeds?

I do not have anything mapped for author in the mapping field. I guess I must create a mapping and use feeds tamper to change the author id to be my own?

franz’s picture

There is an option in the Node Processor to set the default author for nodes imported by a particular importer. Does this solve it for you?

Mazer.Rackham’s picture

No. I already set that option and they are still imported as anonymous.

coderintherye’s picture

@Mazer I think you should at least try the node tamper option to see if it works.

robin monks’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #21 worked for me.

franz’s picture

Status: Reviewed & tested by the community » Needs work

Patch failed on latest code. Can someone re-roll?

franz’s picture

Status: Needs work » Closed (duplicate)

Actually, don't bother, found that this patch is more complete (also adds the user_from_email): #1241754: Add targets for author name and email in node processor.

clayfreeman’s picture

Great job on the patch. I have imported 36k nodes and 8k usernames with the help of this patch. I appreciate the work.