Comments

hpbruna’s picture

Status: Active » Needs review
StatusFileSize
new1.31 KB
vcrkid’s picture

I tried it patching it manually (my version of FeedsUserProcessor.inc has already been patched a couple of times) but it didn't work.

The problem is that the initial code include didn't exist in the original file, i.e.

 if (!empty($uid)) {
           $account->uid = $uid;
         }

I played with it and found that I wound up with this and it worked.

    if (empty($account->name) || empty($account->mail) || !valid_email_address($account->mail)) {
      throw new FeedsValidationException(t('User name missing or email not valid.'));
    }
+  
+ if (!empty($uid)) {
+            $account->uid = $uid;
+          }
+ 		
+ 		 // If uid is set and a user with that id doesn't exist, flag as new.
+      if (!empty($account->uid) && !user_load($account->uid)) {
+       $account->is_new = TRUE;}
	  }
  /**
   * Save a user account.
   */

You may want to verify the + signs as I'm just typing in everything manually.

The second part of the patch went it without any problem and it all worked out (as far as I can tell).

Thanks for the code, it's invaluable!

TheBarnacle’s picture

I just manually added this patch and it worked great. Thanks hpbruna and vcrkid!

Are there any plans to put this in the next release? I think it'd be a useful added feature.

twistor’s picture

Status: Needs review » Needs work

The patch does not currently apply, other than that, it looks good.

robcarr’s picture

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

Patch as rolled against latest DEV (27 Sep 12)

firfin’s picture

Marked #1171456: Importing users with UID / Adding nodes with UID ownership? as a duplicate of this one.
Will try this patch out asap.

firfin’s picture

Heaven-sent!

Patch applied cleanly against 7.x-2.0-alpha7 with only minor line differences:
Hunk #1 succeeded at 53 (offset 3 lines).
Hunk #2 succeeded at 175 (offset 11 lines).

After clearing caches UID is available as a selectable target in the user processors mapping.
After using it as unique the UIDs get used for the new users.

One happy puppy here! Thanks aargh, vcrkid and hpbruna!

One question though, shouldn't the if statement in the beginning of entityValidate() be modified to check for UID also?

One more successful review and test by community.

bsevere’s picture

#5 worked for me on 7.x-2.0-alpha7. This really helps, thanks!

timwood’s picture

Status: Needs review » Reviewed & tested by the community

Marking RTBC based on #8.

twistor’s picture

Title: Map to UID » Add UID target to FeedsUserProcesser.
Component: Feeds Import » Code
Assigned: hpbruna » Unassigned
Status: Reviewed & tested by the community » Needs work

Awesome, looks great. We just need a test...

timwood’s picture

Do you mean a simpletest?

twistor’s picture

Yesir.

sbakshian’s picture

Status: Needs work » Needs review

#5 worked for me too! Thanks very much :)

gaurav.goyal’s picture

Status: Needs review » Needs work

#5 Imports the users but does not give any error if some users are not imported, in my case i imported 7 users and the uid of 3 users were same, after import i got the message "Created 7 Users" and in actual only 5 users were created.

gaurav.goyal’s picture

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

Patch for #14

Status: Needs review » Needs work

The last submitted patch, feeds-uid-mapping-1570544-15.patch, failed testing.

gaurav.goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB

Submitting Patch Again for #16

gaurav.goyal’s picture

#15: feeds-uid-mapping-1570544-15.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, feeds-uid-mapping-1570544-17.patch, failed testing.

gaurav.goyal’s picture

StatusFileSize
new2.28 KB

Final Patch

gaurav.goyal’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, feeds-uid-mapping-1570544-20.patch, failed testing.

gaurav.goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB

Again Submitting Patch

Status: Needs review » Needs work

The last submitted patch, feeds-uid-mapping-1570544-23.patch, failed testing.

jannis’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: feeds-uid-mapping-1570544-23.patch, failed testing.

st8ofmindz79’s picture

mjcarter’s picture

Issue summary: View changes

In my case of needing to update existing users based on an input file mapped by UID, I mapped the UID column to the account e-mail address as a unique target, with this feeds_tamper_php script

$mail = db_query('SELECT  `mail` 
FROM  `users` 
WHERE  `uid` = :uid', array(':uid' => $field))->fetchField();
if(!empty($mail)){
return $mail;
}

The experimental entity importer added to feeds dev purports to allow UID mapped user imports - but it doesn't seem to work at all.

hectorelgomez’s picture

It works.

Thanks.

paulraines’s picture

Patch 5: feeds-uid-mapping-1570544-5.patch above no longer works in the dev branch with all the new Entity stuff. You get SQLSTATE errors when trying to import new users about entity_id being null

francoud’s picture

Any idea about how to apply this patch to the latest -dev version? I really need this feature...

andrewsizz’s picture

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

Added patch up to date

dang42’s picture

Just applied #32 to 7.x-2.0-beta2 --> it worked.

Thanks!

Dan

andrewsizz’s picture

StatusFileSize
new1.17 KB

Just fix one typo in comment.

megachriz’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Patch looks okay, but an automated test is needed to get this in.

dang42’s picture

Had to re-install feeds (my fault - not at all related to this patch...) then reapply the patch. Used #34 this time.

Worked flawlessly.

realgiucas’s picture

Patch 34 gives me this error for all the rows:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'uid' cannot be null

I'm sure the column in the csv file not null or empty
Any idea?

Collins405’s picture

Yep, same error as #37

megachriz’s picture

Status: Needs work » Needs review
StatusFileSize
new5.75 KB
new4.75 KB

I found an issue with the patch in #34 when creating new users. At first it reported a new user was created, but I didn't found this user. When trying to import an user with different details, I got the following error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'user-0' for key 'PRIMARY'

It seems as though that the anonymous user was updated, cause when I deleted all imported items, the anonymous user was deleted!

I fixed this issue by setting $account->is_new in FeedsUserProcessor::newEntity().

I also created a test for creating and updating users using the user ID as unique target.

@realgiucas, Collins405
I could not reproduce the error reported in #37. Can you check if you mapped your data correctly with the Feeds Import Preview module?

megachriz’s picture

StatusFileSize
new9.35 KB
new4.18 KB

I have tried again to reproduce the error in #37 and this time I succeeded. The error shows up when mapping to user ID, but not using that target as unique target. So basically it wasn't possible to change the user's ID.

I've added some validation and a database update query so it becomes possible to change a user's ID. I've made it so that if an user ID is already in use the following message is shown instead of a sql error:

Could not update user ID to 202 since that ID is already in use.

Status: Needs review » Needs work

The last submitted patch, 40: feeds-uid-target-1570544-40.patch, failed testing.

megachriz’s picture

Status: Needs work » Needs review

Hm. The testbot apparently had a hickup. One test was failing first, and now passes. Back to "Needs review".

megachriz’s picture

Issue tags: -Needs tests
StatusFileSize
new9.6 KB

Reroll.

  • MegaChriz committed 452ce86 on 7.x-2.x
    Issue #1570544 by MegaChriz, gaurav.goyal, AndrewsizZ, hpbruna, arrrgh,...
megachriz’s picture

Status: Needs review » Fixed

I tested the patch once more and I found no more issues with it. I also verified that the anonymous user isn't updated when the uid in the source is 0 and the user ID is marked as unique target. Putting in a negative user ID results into SQL errors, but I don't found it worthwile for Feeds to explicitly check on that. There could be a system that would allow negative user ID's (by implementing hook_schema_alter(), for example).

Committed #43. Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.