getLedgerEntityId: Initial implementation.

All tests now pass:

ok 15 - getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed
ok 16 - getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed
ok 17 - getLedgerEntityId: lives when valid id is given...
ok 18 - getLedgerEntityId: ...and return value is correct.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 11:31:36 -08:00
parent 0ca9d394e2
commit 2e14c340ec

View file

@ -381,6 +381,25 @@ for it.
=cut
sub getLedgerEntityId($$) {
my($self, $donorId) = @_;
die "getLedgerEntityId: invalid supporter id, $donorId" unless $self->_verifyId($donorId);
my $lei = $self->dbh()->selectall_hashref("SELECT ledger_entity_id FROM donor WHERE id = " .
$self->dbh->quote($donorId, 'SQL_INTEGER'),
'ledger_entity_id');
my $rowCount = scalar keys %{$lei};
die "setPreferredEmailAddress: DATABASE INTEGRITY ERROR: more than one email address is preferred for supporter, \"$donorId\""
if $rowCount > 1;
if ($rowCount == 1) {
my ($ledgerEntityId) = keys %$lei;
return $ledgerEntityId;
} else {
die "getLedgerEntityId: DATABASE INTEGRITY ERROR: $donorId was valid but non-1 row count returned";
}
}
######################################################################
=begin addPostalAddress