supporters/scripts/find-supporter.plx

114 lines
3.9 KiB
Text
Raw Normal View History

2016-01-25 00:18:29 +00:00
#!/usr/bin/perl
use strict;
use warnings;
2021-02-17 18:43:26 +00:00
use utf8;
2016-01-25 00:18:29 +00:00
use autodie qw(open close);
use DBI;
2021-02-17 18:43:26 +00:00
binmode STDOUT, ":utf8";
binmode STDIN, ":utf8";
2016-01-25 00:18:29 +00:00
use Supporters;
if (@ARGV < 2) {
print STDERR "usage: $0 <SUPPORTERS_SQLITE_DB_FILE> <CRITERION> <SEARCH_PARAMETER> <VERBOSE>\n";
exit 1;
}
my($SUPPORTERS_SQLITE_DB_FILE, $CRITERION, $SEARCH_PARAMETER, $VERBOSE) = @ARGV;
$VERBOSE = 0 if not defined $VERBOSE;
my $dbh = DBI->connect("dbi:SQLite:dbname=$SUPPORTERS_SQLITE_DB_FILE", "", "",
{ RaiseError => 1, sqlite_unicode => 1 })
or die $DBI::errstr;
my $sp = new Supporters($dbh, ['none']);
my $found = 0;
my(@supporterIds);
die "Can only search on id, ledgerEntityId, emailAddress" unless $CRITERION =~ /^(ledgerEntityId|emailAddress|id)$/;
if ($CRITERION eq 'id') {
push(@supporterIds, $SEARCH_PARAMETER);
} else {
@supporterIds = $sp->findDonor({$CRITERION => $SEARCH_PARAMETER });
}
2016-03-11 19:05:05 +00:00
my @requestTypes = $sp->getRequestType();
2016-01-25 00:18:29 +00:00
foreach my $id (@supporterIds) {
$found = 1;
2021-02-10 22:25:40 +00:00
my $rtTicket = $sp->_getDonorField('rt_ticket', $id);
$rtTicket = "" if not defined $rtTicket;
$rtTicket = "[sfconservancy.org #$rtTicket]" if $rtTicket ne "";
my $preferredEmail = $sp->getPreferredEmailAddress($id);
my $preferredPostal = $sp->getPreferredPostalAddress($id);
2021-02-10 22:25:40 +00:00
print "Found: BEGIN: $id, ", $sp->getLedgerEntityId($id), "\n";
print " RT: $rtTicket" if $rtTicket ne "";
print " Public Ack: ";
if (not defined $sp->getPublicAck($id)) {
print "unknown\n";
} elsif ($sp->getPublicAck($id)) {
print "yes\n";
print " Display name for public ack: \"", $sp->getDisplayName($id), "\"\n";
} else {
print "no\n";
}
my(%addr) = $sp->getEmailAddresses($id);
print " Email Addresses: ";
my $cnt = 0;
foreach my $email (keys %addr) {
$cnt++;
print $email;
print "(preferred)" if (defined $preferredEmail) and $email eq $preferredEmail;
print ", " unless $cnt == scalar keys %addr;
}
my(%postalAddresses) = $sp->getPostalAddresses($id);
if (scalar keys %postalAddresses <= 0) {
print "\n NO POSTAL ADDRESSES.\n";
} else {
print "\n Postal Addresses:\n";
foreach my $address (keys %postalAddresses) {
2016-03-11 20:29:58 +00:00
print " PREFERRED FOLLOWS:\n" if (defined $preferredPostal) and $address eq $preferredPostal;
print " Encountered $postalAddresses{$address}{id} on $postalAddresses{$address}{date_encountered} via $postalAddresses{$address}{name}\n";
foreach my $addrLine (split("\n", $address)) {
print " $addrLine\n";
}
2016-03-11 19:10:39 +00:00
}
}
2016-03-11 19:05:05 +00:00
foreach my $requestType (@requestTypes) {
my $req = $sp->getRequest({ donorId => $id, requestType => $requestType});
if (defined $req) {
print " Request $req->{requestId} of $req->{requestType}";
2016-03-11 19:05:05 +00:00
print "($req->{requestConfiguration})" if defined $req->{requestConfiguration};
print " made on $req->{requestDate}";
if (not defined $req->{fulfillDate}) {
print "\n";
} else {
print "...\n fulfilled on $req->{fulfillDate}";
print "...\n by: $req->{fulfilledBy}" if defined $req->{fulfilledBy};
print "...\n via: $req->{fulfilledVia}" if defined $req->{fulfilledVia};
}
if (not defined $req->{holdDate} ) {
2016-03-11 19:05:05 +00:00
print "\n";
} else {
print "...\n put on hold on $req->{holdDate} by $req->{holder}";
2017-01-02 19:58:34 +00:00
print "...\n release on: $req->{holdReleaseDate}" if defined $req->{holdReleaseDate};
print "...\n on hold because: $req->{heldBecause}\n" if defined $req->{heldBecause};
2016-03-11 19:05:05 +00:00
}
}
}
2021-02-10 22:25:40 +00:00
print "END: $id, ", $sp->getLedgerEntityId($id);
print " RT: $rtTicket" if $rtTicket ne "";
print "\n";
2016-01-25 00:18:29 +00:00
}
print "No entries found\n" unless $found;
###############################################################################
#
# Local variables:
# compile-command: "perl -c send-mass-email.plx"
# End: