I have a client that wants to get away from email address as the determining factor as to if a user is new or not. They want the import insert / update process to key off a profile field that contains a unique identifier that has other value to them.

I've poked around in the code a bit but keep hitting duplicate email checks and all my imports keep running as INSERTs, no UPDATEs.

If someone could help point me in the right direction where to add this, I would like to add this as something to contribute back, but if something custom for this case, then thats fine too. I'm sure it's doable, but I'm just a little confused as where to put it.

Thanks.

Comments

dzescsd’s picture

I'm interested by the reply

robert castelo’s picture

Status: Active » Closed (duplicate)

See my reply here:

http://drupal.org/node/375544#comment-1386716

This request is covered by the other, so marking it as a duplicate.

emackn’s picture

OK, thanks for the reply.

I actually got something to work, but it's specific to my data. If you want, I can post what I did with some explanation. Otherwise, I don't want to muddy up the water with a temporary solution, i.e. xml sitemap, heh.

I look forward to seeing a final solution.

dzescsd’s picture

OK. Can you send what you did and some explanation ?

Thanks.

emackn’s picture

Here's what I did,

in user_import.module, I changed the _user_import_process from this (around line 1470)

if ($update_setting && !empty($fields['user']['email'][0])) {
  $existing_account = user_load(array('mail' => $fields['user']['email'][0]));
  if ($existing_account) 
    $account = (array) $existing_account;
}

to this

  // ['profile'][18] is the new profile field i want to key off of, not too readable, but thats what I have to work with.
  if ($update_setting && !empty($fields['user']['email'][0]) && !empty($fields['profile'][18][0])) {
     $record_id = $fields['profile'][18][0];
     $results = array();
     $sql = "SELECT uid FROM {profile_values} WHERE fid = 18 AND value = '%s'";
     $result = db_query($sql, $record_id);
     while($item = db_fetch_object($result)) {
       $results[] = $item;
     }
    
    $existing_account = array();
    // new user
    if (count($results) == 0) {
      $account = array('uid'=>''); 
    }
    elseif( count($results) > 1) {  // duplicate records
      user_import_errors(t('Duplicate Record ID Found!'));
    }
    else {  // existing user
      $existing_account = user_load(array('uid' => $results[0]->uid));
    }

}