Lines 826-832
sub GetQueuedMessages {
Link Here
|
826 |
|
826 |
|
827 |
my $dbh = C4::Context->dbh(); |
827 |
my $dbh = C4::Context->dbh(); |
828 |
my $statement = << 'ENDSQL'; |
828 |
my $statement = << 'ENDSQL'; |
829 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
829 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, sentto_address |
830 |
FROM message_queue |
830 |
FROM message_queue |
831 |
ENDSQL |
831 |
ENDSQL |
832 |
|
832 |
|
Lines 937-953
sub _send_message_by_email {
Link Here
|
937 |
|
937 |
|
938 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
938 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
939 |
my $to_address = $message->{'to_address'}; |
939 |
my $to_address = $message->{'to_address'}; |
|
|
940 |
if (!$to_address && $member) { |
941 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
942 |
} |
940 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
943 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
941 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
944 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
942 |
unless ($to_address) { |
945 |
unless ($to_address) { |
943 |
unless ($member) { |
946 |
if (!$member) { |
944 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
947 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
945 |
_set_message_status( { message_id => $message->{'message_id'}, |
948 |
_set_message_status( { message_id => $message->{'message_id'}, |
946 |
status => 'failed' } ); |
949 |
status => 'failed' } ); |
947 |
return; |
950 |
return; |
948 |
} |
951 |
} |
949 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
952 |
else { |
950 |
unless ($to_address) { |
|
|
951 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
953 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
952 |
# warning too verbose for this more common case? |
954 |
# warning too verbose for this more common case? |
953 |
_set_message_status( { message_id => $message->{'message_id'}, |
955 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 980-987
sub _send_message_by_email {
Link Here
|
980 |
|
982 |
|
981 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
983 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
982 |
if ( sendmail( %sendmail_params ) ) { |
984 |
if ( sendmail( %sendmail_params ) ) { |
983 |
_set_message_status( { message_id => $message->{'message_id'}, |
985 |
_set_message_status( { message_id => $message->{'message_id'}, |
984 |
status => 'sent' } ); |
986 |
status => 'sent', |
|
|
987 |
sentto_address => $to_address } ); |
985 |
return 1; |
988 |
return 1; |
986 |
} else { |
989 |
} else { |
987 |
_set_message_status( { message_id => $message->{'message_id'}, |
990 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1043-1053
sub _set_message_status {
Link Here
|
1043 |
return unless exists $params->{ $required_parameter }; |
1046 |
return unless exists $params->{ $required_parameter }; |
1044 |
} |
1047 |
} |
1045 |
|
1048 |
|
1046 |
my $dbh = C4::Context->dbh(); |
|
|
1047 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1049 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
|
|
1050 |
my @values; |
1051 |
push @values,$params->{'status'}; |
1052 |
if (exists($params->{'sentto_address'})) { |
1053 |
$statement = 'UPDATE message_queue SET status=?, sentto_address=? WHERE message_id = ?'; |
1054 |
push @values,$params->{'sentto_address'}; |
1055 |
} |
1056 |
push @values,$params->{'message_id'}; |
1057 |
my $dbh = C4::Context->dbh(); |
1058 |
print STDERR "statement: $statement\n",@values,"\n"; |
1048 |
my $sth = $dbh->prepare( $statement ); |
1059 |
my $sth = $dbh->prepare( $statement ); |
1049 |
my $result = $sth->execute( $params->{'status'}, |
1060 |
my $result = $sth->execute( @values ); |
1050 |
$params->{'message_id'} ); |
|
|
1051 |
return $result; |
1061 |
return $result; |
1052 |
} |
1062 |
} |
1053 |
|
1063 |
|