Author Topic: "Create contact with user data" causes duplicate email address. (patch included)  (Read 2816 times)

markc

  • Freshman
  • *
  • Posts: 47
    • View Profile
On 1.6.1 and 1.6.2 if I go to Administration -> Add User and select Create contact with user data when creating the user, the contact that is created will have the users email address listed for both email1 and email2.

This is because during this code block around line 740 of ../application/functions.php:
Code: [Select]
       $contact = $user->getContact();
        if ($contact instanceof Contact) {
                // update contact data with data entered for this user
                $contact->setCompanyId($user->getCompanyId());
                // make user's email the contact's main email address
                if ($contact->getEmail2() == $user->getEmail()) {
                        $contact->setEmail2($contact->getEmail());
                } else if ($contact->getEmail3() == $user->getEmail()) {
                        $contact->setEmail3($contact->getEmail());
                } else if ($contact->getEmail2() == "") {
                        $contact->setEmail2($contact->getEmail());
                } else {
                        $contact->setEmail3($contact->getEmail());
                }
                $contact->setEmail($user->getEmail());
                $contact->save();
        }

the software is trying to change the order that the addresses are listed so that it can set the contact's address to be the same as the user's address. However, the code fails to check whether the user and contact already have the same address, resulting in Email1 (previously created during the create_user function) getting moved to Email2, and a duplicate Email1 being put in its place.

I believe the patch I've attached resolves the issue by skipping the entire block of code if $contact->getEmail and $user->getEmail are already the same.

As always though...please let me know if I'm over-looking something horribly obvious.

Mark


P.S. I haven't used the patch program much in the past so this may be helpful info... In my own environment, a cd into the root of fengoffice before "patch -p1 < ...path_to_patch_file..." seems to resolve the issue.
« Last Edit: March 27, 2010, 08:33:06 pm by markc »

ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Great, thanks!