diff --git a/README.md b/README.md index 880cb02..73aef46 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,5 @@ Common Tasks These are recipes for some common tasks that one might want to complete on the command line with the Supporters database. +* Add a Supporter from the command line: + ./scripts/add-supporter.plx diff --git a/scripts/add-supporter.plx b/scripts/add-supporter.plx new file mode 100644 index 0000000..6c442bb --- /dev/null +++ b/scripts/add-supporter.plx @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DBI; +use Encode qw(encode decode); +use Supporters; + +if (@ARGV != 1 and @ARGV !=2) { + print STDERR "usage: $0 \n"; + exit 1; +} + +my($SUPPORTERS_SQLITE_DB_FILE, $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; + +print "Ledger Entity Id: "; +my $entityId = ; +chomp $entityId; + +print "Display Name: "; +my $displayName = ; +chomp $displayName; + +print "Public Ack (0 or 1): "; +my $publicAck = ; +chomp $publicAck; + +print "Email Address: "; +my $email = ; +chomp $email; + +print "Email Address Type: "; +my $emailType = ; +chomp $emailType; + + +print "Want T-Shirt: "; +my $tshirt = ; +chomp $tshirt; + +my $tshirtSize; + +if ($tshirt) { + print "T-Shirt Size: "; + $tshirtSize = ; + chomp $tshirtSize; +} + +print "Want announcemailing list: "; +my $wantList = ; +chomp $wantList; + +print "postal Address (. to end):\n"; +my $postal; +while (my $line = ) { + last if /^\s*\.\s*$/; + $postal .= $line; +} + +my $sp = new Supporters($dbh, [ "none" ]); + +my $donorId = $sp->addSupporter({ ledger_entity_id => $entityId, email_address => $email, email_address_type => $emailType, + display_name => $displayName, public_ack => $publicAck} ); +if ($tshirt) { + my $requestParamaters = { donorId => $donorId, requestConfiguration => $tshirtSize, requestType => 't-shirt-0' }; + $sp->addRequest($requestParamaters); +} +if ($wantList) { + my $requestParamaters = { donorId => $donorId, requestType => 'join-announce-email-list' }; + $sp->addRequest($requestParamaters); +} +if ($postal and $postal !~ /^\s*$/) { + print "postal type: "; + my $postalType = ; + chomp $postalType; + $sp->addPostalAddress($donorId, $postal, $postalType); +}