Lines 1021-1027
sub GetQueuedMessages {
Link Here
|
1021 |
|
1021 |
|
1022 |
my $dbh = C4::Context->dbh(); |
1022 |
my $dbh = C4::Context->dbh(); |
1023 |
my $statement = << 'ENDSQL'; |
1023 |
my $statement = << 'ENDSQL'; |
1024 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1024 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, sentto_address |
1025 |
FROM message_queue |
1025 |
FROM message_queue |
1026 |
ENDSQL |
1026 |
ENDSQL |
1027 |
|
1027 |
|
Lines 1150-1166
sub _send_message_by_email {
Link Here
|
1150 |
|
1150 |
|
1151 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1151 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1152 |
my $to_address = $message->{'to_address'}; |
1152 |
my $to_address = $message->{'to_address'}; |
|
|
1153 |
if (!$to_address && $member) { |
1154 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1155 |
} |
1153 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1156 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1154 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
1157 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
1155 |
unless ($to_address) { |
1158 |
unless ($to_address) { |
1156 |
unless ($member) { |
1159 |
if (!$member) { |
1157 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1160 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1158 |
_set_message_status( { message_id => $message->{'message_id'}, |
1161 |
_set_message_status( { message_id => $message->{'message_id'}, |
1159 |
status => 'failed' } ); |
1162 |
status => 'failed' } ); |
1160 |
return; |
1163 |
return; |
1161 |
} |
1164 |
} |
1162 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1165 |
else { |
1163 |
unless ($to_address) { |
|
|
1164 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1166 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1165 |
# warning too verbose for this more common case? |
1167 |
# warning too verbose for this more common case? |
1166 |
_set_message_status( { message_id => $message->{'message_id'}, |
1168 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1204-1211
sub _send_message_by_email {
Link Here
|
1204 |
|
1206 |
|
1205 |
_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 |
1207 |
_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 |
1206 |
if ( sendmail( %sendmail_params ) ) { |
1208 |
if ( sendmail( %sendmail_params ) ) { |
1207 |
_set_message_status( { message_id => $message->{'message_id'}, |
1209 |
_set_message_status( { message_id => $message->{'message_id'}, |
1208 |
status => 'sent' } ); |
1210 |
status => 'sent', |
|
|
1211 |
sentto_address => $to_address } ); |
1209 |
return 1; |
1212 |
return 1; |
1210 |
} else { |
1213 |
} else { |
1211 |
_set_message_status( { message_id => $message->{'message_id'}, |
1214 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1289-1299
sub _set_message_status {
Link Here
|
1289 |
return unless exists $params->{ $required_parameter }; |
1292 |
return unless exists $params->{ $required_parameter }; |
1290 |
} |
1293 |
} |
1291 |
|
1294 |
|
1292 |
my $dbh = C4::Context->dbh(); |
|
|
1293 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1295 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
|
|
1296 |
my @values; |
1297 |
push @values,$params->{'status'}; |
1298 |
if (exists($params->{'sentto_address'})) { |
1299 |
$statement = 'UPDATE message_queue SET status=?, sentto_address=? WHERE message_id = ?'; |
1300 |
push @values,$params->{'sentto_address'}; |
1301 |
} |
1302 |
push @values,$params->{'message_id'}; |
1303 |
my $dbh = C4::Context->dbh(); |
1294 |
my $sth = $dbh->prepare( $statement ); |
1304 |
my $sth = $dbh->prepare( $statement ); |
1295 |
my $result = $sth->execute( $params->{'status'}, |
1305 |
my $result = $sth->execute( @values ); |
1296 |
$params->{'message_id'} ); |
|
|
1297 |
return $result; |
1306 |
return $result; |
1298 |
} |
1307 |
} |
1299 |
|
1308 |
|