From 501355b8391d857a4c50858debd5f01146ae2df9 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 30 Dec 2015 06:00:42 -0800 Subject: [PATCH] addEmailAddress: redundant add w/ same address. This should succeed as the previous tests show. They now pass: ok 21 - addEmailAddress: fails adding existing email address with mismatched type. ok 22 - addEmailAddress: succeeds when adding email that already exists... ok 23 - addEmailAddress: ... and returns same id. --- Supporters/lib/Supporters.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 8e0b845..049b757 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -201,9 +201,19 @@ sub addEmailAddress($$$$) { unless defined $emailAddressType and Mail::RFC822::Address::valid($emailAddress); my $existingEmail = $self->_lookupEmailAddress($emailAddress); - die "addEmailAddress: attempt to add email address that exists, using a different type!" - if defined $existingEmail and $existingEmail->{type} ne $emailAddressType; + if (defined $existingEmail) { + die "addEmailAddress: attempt to add email address that exists, using a different type!" + if $existingEmail->{type} ne $emailAddressType; + + my $val = $self->dbh()->selectall_hashref("SELECT email_address_id, donor_id " . + "FROM donor_email_address_mapping WHERE " . + "donor_id = " . $self->dbh->quote($id, 'SQL_INTEGER') . " AND " . + "email_address_id = " . $self->dbh->quote($existingEmail->{id}, 'SQL_INTEGER'), + 'donor_id'); + return $val->{$id}{email_address_id} + if (defined $val and defined $val->{$id} and defined $val->{$id}{email_address_id}); + } my($sth, $addressId); $self->_beginWork();