Bug 18398: Update C4::Message enqueue to use $patron->notice_email_address
This patch updates the enque method in C4::Message to expect a Koha::Patron object in the parameters and then uses that patron object to select the correct email address for notices as defined by AutoEmailPrimaryAddress. Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
92fbb49af7
commit
f7cfe3a705
4 changed files with 28 additions and 24 deletions
|
@ -3657,7 +3657,8 @@ sub SendCirculationAlert {
|
||||||
my $message = C4::Message->find_last_message($borrower, $type, $mtt);
|
my $message = C4::Message->find_last_message($borrower, $type, $mtt);
|
||||||
unless ( $message ) {
|
unless ( $message ) {
|
||||||
C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
|
C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
|
||||||
C4::Message->enqueue($letter, $borrower, $mtt);
|
my $patron = Koha::Patrons->find($borrower->{borrowernumber});
|
||||||
|
C4::Message->enqueue($letter, $patron, $mtt);
|
||||||
} else {
|
} else {
|
||||||
$message->append($letter);
|
$message->append($letter);
|
||||||
$message->update;
|
$message->update;
|
||||||
|
|
|
@ -157,41 +157,44 @@ the message.
|
||||||
|
|
||||||
# C4::Message->enqueue($letter, $borrower, $transport)
|
# C4::Message->enqueue($letter, $borrower, $transport)
|
||||||
sub enqueue {
|
sub enqueue {
|
||||||
my ($class, $letter, $borrower, $transport) = @_;
|
my ( $class, $letter, $patron, $transport ) = @_;
|
||||||
my $metadata = _metadata($letter);
|
my $metadata = _metadata($letter);
|
||||||
my $to_address = _to_address($borrower, $transport);
|
my $to_address = _to_address( $patron, $transport );
|
||||||
|
|
||||||
# Same as render_metadata
|
# Same as render_metadata
|
||||||
my $format ||= sub { $_[0] || "" };
|
my $format ||= sub { $_[0] || "" };
|
||||||
my $body = join('', map { $format->($_) } @{$metadata->{body}});
|
my $body = join( '', map { $format->($_) } @{ $metadata->{body} } );
|
||||||
$letter->{content} = $metadata->{header} . $body . $metadata->{footer};
|
$letter->{content} = $metadata->{header} . $body . $metadata->{footer};
|
||||||
|
|
||||||
$letter->{metadata} = Encode::decode_utf8(Dump($metadata));
|
$letter->{metadata} = Encode::decode_utf8( Dump($metadata) );
|
||||||
C4::Letters::EnqueueLetter({
|
C4::Letters::EnqueueLetter(
|
||||||
letter => $letter,
|
{
|
||||||
borrowernumber => $borrower->{borrowernumber},
|
letter => $letter,
|
||||||
message_transport_type => $transport,
|
borrowernumber => $patron->id,
|
||||||
to_address => $to_address,
|
message_transport_type => $transport,
|
||||||
});
|
to_address => $to_address,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
# based on message $transport, pick an appropriate address to send to
|
# based on message $transport, pick an appropriate address to send to
|
||||||
sub _to_address {
|
sub _to_address {
|
||||||
my ($borrower, $transport) = @_;
|
my ( $patron, $transport ) = @_;
|
||||||
my $address;
|
my $address;
|
||||||
if ($transport eq 'email') {
|
if ( $transport eq 'email' ) {
|
||||||
$address = $borrower->{email}
|
$address = $patron->notice_email_address;
|
||||||
|| $borrower->{emailpro}
|
}
|
||||||
|| $borrower->{B_email};
|
elsif ( $transport eq 'sms' ) {
|
||||||
} elsif ($transport eq 'sms') {
|
$address = $patron->smsalertnumber;
|
||||||
$address = $borrower->{smsalertnumber};
|
}
|
||||||
} else {
|
else {
|
||||||
warn "'$transport' is an unknown message transport.";
|
warn "'$transport' is an unknown message transport.";
|
||||||
}
|
}
|
||||||
if (not defined $address) {
|
if ( not defined $address ) {
|
||||||
warn "An appropriate $transport address "
|
warn "An appropriate $transport address "
|
||||||
. "for borrower $borrower->{userid} "
|
. "for borrower "
|
||||||
. "could not be found.";
|
. $patron->userid
|
||||||
|
. "could not be found.";
|
||||||
}
|
}
|
||||||
return $address;
|
return $address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,7 @@ sub set_waiting {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
C4::Message->enqueue($letter, $self->patron->unblessed, 'email');
|
C4::Message->enqueue($letter, $self->patron, 'email');
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ sub add_recall {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
C4::Message->enqueue( $letter, $checkout->patron->unblessed, 'email' );
|
C4::Message->enqueue( $letter, $checkout->patron, 'email' );
|
||||||
|
|
||||||
$item = Koha::Items->find( $itemnumber );
|
$item = Koha::Items->find( $itemnumber );
|
||||||
# add to statistics table
|
# add to statistics table
|
||||||
|
|
Loading…
Reference in a new issue