_lookupEmailAddress: replace _lookupEmailAddressId

Actually, I will ultimately need the whole record for my purposes, so
rework this function to return everything.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 05:41:10 -08:00
parent 4d2fc22de1
commit 736f022005
2 changed files with 27 additions and 11 deletions

View file

@ -977,7 +977,7 @@ sub _lookupRequestTypeById($$) {
}
######################################################################
=item _lookupEmailAddressId()
=item _lookupEmailAddress()
Parameters:
@ -990,21 +990,36 @@ Parameters:
=back
Returns: scalar, which is the email_address.id found iff. the C<$emailAddress> is valid and
already in the supporter database's email_address table.
Returns: undef if the email address is not found, otherwise a hash with the following values:
=over
=item emailAddress: The email address as given
=item id: The email_adress.id
=item type: The email_adress type
=item dateEncountered: The date_encountered of this email address.
=back
=cut
sub _lookupEmailAddressId($$) {
sub _lookupEmailAddress($$) {
my($self, $emailAddress) = @_;
die "_lookupEmailAddressId() called with undef" unless defined $emailAddress;
my $val = $self->dbh()->selectall_hashref("SELECT id, email_address FROM email_address WHERE email_address = " .
$self->dbh->quote($emailAddress), 'email_address');
my $val = $self->dbh()->selectall_hashref("SELECT ea.id, ea.email_address, at.name, ea.date_encountered " .
"FROM email_address ea, address_type at " .
"WHERE ea.type_id = at.id AND " .
"email_address = " . $self->dbh->quote($emailAddress),
'email_address');
if (defined $val and defined $val->{$emailAddress}) {
return $val->{$emailAddress}{id};
return { id => $val->{$emailAddress}{id}, emailAddress => $val->{$emailAddress}{email_address},
type => $val->{$emailAddress}{name}, dateEncountered => $val->{$emailAddress}{date_encountered}};
} else {
return undef;
}

View file

@ -538,16 +538,17 @@ dies_ok { $sp->_verifyId("String") } "_verifyId: dies for non-numeric id";
# This is a hacky way to test this; but should work
ok(not ($sp->_verifyId($drapperId + 10)), "_verifyId: non-existent id is not found");
=item _lookupEmailAddressId
=item _lookupEmailAddress
=cut
dies_ok { $sp->_lookupEmailAddressId(undef); } "_lookupEmailAddressId: dies for undefined email_address";
dies_ok { $sp->_lookupEmailAddress(undef); } "_lookupEmailAddressId: dies for undefined email_address";
is($sp->_lookupEmailAddressId('drapper@example.org'), $drapperEmailId,
is_deeply($sp->_lookupEmailAddress('drapper@example.org'),
{ emailAddress => 'drapper@example.org', id => $drapperEmailId, type => 'work', dateEncountered => $today },
"_lookupEmailAddressId: returns email Id for known item");
is($sp->_lookupEmailAddressId('drapper@example.com'), undef,
is($sp->_lookupEmailAddress('drapper@example.com'), undef,
"_lookupEmailAddressId: returns undef for unknown item.");
$sp = undef;