Lines 157-197
the message.
Link Here
|
157 |
|
157 |
|
158 |
# C4::Message->enqueue($letter, $borrower, $transport) |
158 |
# C4::Message->enqueue($letter, $borrower, $transport) |
159 |
sub enqueue { |
159 |
sub enqueue { |
160 |
my ($class, $letter, $borrower, $transport) = @_; |
160 |
my ( $class, $letter, $patron, $transport ) = @_; |
161 |
my $metadata = _metadata($letter); |
161 |
my $metadata = _metadata($letter); |
162 |
my $to_address = _to_address($borrower, $transport); |
162 |
my $to_address = _to_address( $patron, $transport ); |
163 |
|
163 |
|
164 |
# Same as render_metadata |
164 |
# Same as render_metadata |
165 |
my $format ||= sub { $_[0] || "" }; |
165 |
my $format ||= sub { $_[0] || "" }; |
166 |
my $body = join('', map { $format->($_) } @{$metadata->{body}}); |
166 |
my $body = join( '', map { $format->($_) } @{ $metadata->{body} } ); |
167 |
$letter->{content} = $metadata->{header} . $body . $metadata->{footer}; |
167 |
$letter->{content} = $metadata->{header} . $body . $metadata->{footer}; |
168 |
|
168 |
|
169 |
$letter->{metadata} = Encode::decode_utf8(Dump($metadata)); |
169 |
$letter->{metadata} = Encode::decode_utf8( Dump($metadata) ); |
170 |
C4::Letters::EnqueueLetter({ |
170 |
C4::Letters::EnqueueLetter( |
171 |
letter => $letter, |
171 |
{ |
172 |
borrowernumber => $borrower->{borrowernumber}, |
172 |
letter => $letter, |
173 |
message_transport_type => $transport, |
173 |
borrowernumber => $patron->id, |
174 |
to_address => $to_address, |
174 |
message_transport_type => $transport, |
175 |
}); |
175 |
to_address => $to_address, |
|
|
176 |
} |
177 |
); |
176 |
} |
178 |
} |
177 |
|
179 |
|
178 |
# based on message $transport, pick an appropriate address to send to |
180 |
# based on message $transport, pick an appropriate address to send to |
179 |
sub _to_address { |
181 |
sub _to_address { |
180 |
my ($borrower, $transport) = @_; |
182 |
my ( $patron, $transport ) = @_; |
181 |
my $address; |
183 |
my $address; |
182 |
if ($transport eq 'email') { |
184 |
if ( $transport eq 'email' ) { |
183 |
$address = $borrower->{email} |
185 |
$address = $patron->notice_email_address; |
184 |
|| $borrower->{emailpro} |
186 |
} |
185 |
|| $borrower->{B_email}; |
187 |
elsif ( $transport eq 'sms' ) { |
186 |
} elsif ($transport eq 'sms') { |
188 |
$address = $patron->smsalertnumber; |
187 |
$address = $borrower->{smsalertnumber}; |
189 |
} |
188 |
} else { |
190 |
else { |
189 |
warn "'$transport' is an unknown message transport."; |
191 |
warn "'$transport' is an unknown message transport."; |
190 |
} |
192 |
} |
191 |
if (not defined $address) { |
193 |
if ( not defined $address ) { |
192 |
warn "An appropriate $transport address " |
194 |
warn "An appropriate $transport address " |
193 |
. "for borrower $borrower->{userid} " |
195 |
. "for borrower " |
194 |
. "could not be found."; |
196 |
. $patron->userid |
|
|
197 |
. "could not be found."; |
195 |
} |
198 |
} |
196 |
return $address; |
199 |
return $address; |
197 |
} |
200 |
} |