From 062bb9a80451700b128bfacad774de41168e8bb6 Mon Sep 17 00:00:00 2001 From: John Beppu Date: Tue, 3 Feb 2009 16:02:13 -0600 Subject: [PATCH] bug 324: Setting to_address - Enqueue the messages with a to_address. Signed-off-by: Daniel Sweeney Signed-off-by: Galen Charlton --- C4/Circulation.pm | 5 +++-- C4/Letters.pm | 3 --- C4/Message.pm | 48 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 95c97bdf48..d22e28ceaf 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2395,7 +2395,6 @@ B: sub SendCirculationAlert { my ($opts) = @_; my ($type, $item, $borrower) = ($opts->{type}, $opts->{item}, $opts->{borrower}); - my $dbh = C4::Context->dbh; my %message_name = ( CHECKIN => 'Item Check-in', CHECKOUT => 'Item Checkout', @@ -2410,11 +2409,13 @@ sub SendCirculationAlert { C4::Letters::parseletter($letter, 'borrowers', $borrower->{borrowernumber}); C4::Letters::parseletter($letter, 'branches', $item->{homebranch}); my @transports = @{ $borrower_preferences->{transports} }; + # warn "no transports" unless @transports; for (@transports) { + # warn "transport: $_"; my $message = C4::Message->find_last_message($borrower, $type, $_); if (!$message) { #warn "create new message"; - C4::Message->enqueue($letter, $borrower->{borrowernumber}, $_); + C4::Message->enqueue($letter, $borrower, $_); } else { #warn "append to old message"; $message->append($letter); diff --git a/C4/Letters.pm b/C4/Letters.pm index 2f0bbdbbf8..085ae9652d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -531,8 +531,6 @@ sub EnqueueLetter { return unless exists $params->{'borrowernumber'}; return unless exists $params->{'message_transport_type'}; - warn 'got passed the guard'; - # If we have any attachments we should encode then into the body. if ( $params->{'attachments'} ) { $params->{'letter'} = _add_attachments( @@ -564,7 +562,6 @@ ENDSQL $params->{'from_address'}, # from_address $params->{'letter'}->{'content-type'}, # content_type ); - warn $result; return $result; } diff --git a/C4/Message.pm b/C4/Message.pm index dcd3bad5bd..9a634daca5 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -120,28 +120,54 @@ sub find_last_message { } -=head3 C4::Message->enqueue($letter, $borrowernumber, $transport) +=head3 C4::Message->enqueue($letter, $borrower, $transport) This is a front-end for C that adds metadata to the message. =cut -# C4::Message->enqueue($letter, $borrowernumber, $transport) +# C4::Message->enqueue($letter, $borrower, $transport) sub enqueue { - my ($class, $letter, $borrowernumber, $transport) = @_; - my $metadata = _make_metadata($letter); + my ($class, $letter, $borrower, $transport) = @_; + my $metadata = _metadata($letter); + my $to_address = _to_address($borrower, $transport); $letter->{metadata} = Dump($metadata); - carp 'enqueuing...'; + #carp "enqueuing... to $to_address"; C4::Letters::EnqueueLetter({ - letter => $letter, - borrowernumber => $borrowernumber, - message_transport_type => $transport, + letter => $letter, + borrowernumber => $borrower->{borrowernumber}, + message_transport_type => $transport, + to_address => $to_address, }); } -# _make_metadata($letter) -- return the letter split into head/body/footer -sub _make_metadata { +# based on message $transport, pick an appropriate address to send to +sub _to_address { + my ($borrower, $transport) = @_; + my $address; + if ($transport eq 'email') { + $address = $borrower->{email} + || $borrower->{emailpro} + || $borrower->{B_email}; + } elsif ($transport eq 'sms') { + $address = $borrower->{smsalertnumber} + || $borrower->{phone} + || $borrower->{phonepro} + || $borrower->{B_phone}; + } else { + warn "'$transport' is an unknown message transport."; + } + if (not defined $address) { + warn "An appropriate $transport address " + . "for borrower $borrower->{userid} " + . "could not be found."; + } + return $address; +} + +# _metadata($letter) -- return the letter split into head/body/footer +sub _metadata { my ($letter) = @_; if ($letter->{content} =~ /----/) { my ($header, $body, $footer) = split(/----\r?\n?/, $letter->{content}); @@ -256,7 +282,7 @@ sub append { my $item; if (ref($letter_or_item)) { my $letter = $letter_or_item; - my $metadata = _make_metadata($letter); + my $metadata = _metadata($letter); $item = $metadata->{body}->[0]; } else { $item = $letter_or_item; -- 2.39.5