Lines 1016-1022
sub GetQueuedMessages {
Link Here
|
1016 |
|
1016 |
|
1017 |
my $dbh = C4::Context->dbh(); |
1017 |
my $dbh = C4::Context->dbh(); |
1018 |
my $statement = << 'ENDSQL'; |
1018 |
my $statement = << 'ENDSQL'; |
1019 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1019 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, sentto_address |
1020 |
FROM message_queue |
1020 |
FROM message_queue |
1021 |
ENDSQL |
1021 |
ENDSQL |
1022 |
|
1022 |
|
Lines 1145-1161
sub _send_message_by_email {
Link Here
|
1145 |
|
1145 |
|
1146 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1146 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1147 |
my $to_address = $message->{'to_address'}; |
1147 |
my $to_address = $message->{'to_address'}; |
|
|
1148 |
if (!$to_address && $member) { |
1149 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1150 |
} |
1148 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1151 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1149 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
1152 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && $sendAllEmailsTo =~ /@/ ); # some validation. This could be improved. |
1150 |
unless ($to_address) { |
1153 |
unless ($to_address) { |
1151 |
unless ($member) { |
1154 |
if (!$member) { |
1152 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1155 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1153 |
_set_message_status( { message_id => $message->{'message_id'}, |
1156 |
_set_message_status( { message_id => $message->{'message_id'}, |
1154 |
status => 'failed' } ); |
1157 |
status => 'failed' } ); |
1155 |
return; |
1158 |
return; |
1156 |
} |
1159 |
} |
1157 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1160 |
else { |
1158 |
unless ($to_address) { |
|
|
1159 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1161 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1160 |
# warning too verbose for this more common case? |
1162 |
# warning too verbose for this more common case? |
1161 |
_set_message_status( { message_id => $message->{'message_id'}, |
1163 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1199-1206
sub _send_message_by_email {
Link Here
|
1199 |
|
1201 |
|
1200 |
_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 |
1202 |
_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 |
1201 |
if ( sendmail( %sendmail_params ) ) { |
1203 |
if ( sendmail( %sendmail_params ) ) { |
1202 |
_set_message_status( { message_id => $message->{'message_id'}, |
1204 |
_set_message_status( { message_id => $message->{'message_id'}, |
1203 |
status => 'sent' } ); |
1205 |
status => 'sent', |
|
|
1206 |
sentto_address => $to_address } ); |
1204 |
return 1; |
1207 |
return 1; |
1205 |
} else { |
1208 |
} else { |
1206 |
_set_message_status( { message_id => $message->{'message_id'}, |
1209 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1284-1294
sub _set_message_status {
Link Here
|
1284 |
return unless exists $params->{ $required_parameter }; |
1287 |
return unless exists $params->{ $required_parameter }; |
1285 |
} |
1288 |
} |
1286 |
|
1289 |
|
1287 |
my $dbh = C4::Context->dbh(); |
|
|
1288 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1290 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
|
|
1291 |
my @values; |
1292 |
push @values,$params->{'status'}; |
1293 |
if (exists($params->{'sentto_address'})) { |
1294 |
$statement = 'UPDATE message_queue SET status=?, sentto_address=? WHERE message_id = ?'; |
1295 |
push @values,$params->{'sentto_address'}; |
1296 |
} |
1297 |
push @values,$params->{'message_id'}; |
1298 |
my $dbh = C4::Context->dbh(); |
1289 |
my $sth = $dbh->prepare( $statement ); |
1299 |
my $sth = $dbh->prepare( $statement ); |
1290 |
my $result = $sth->execute( $params->{'status'}, |
1300 |
my $result = $sth->execute( @values ); |
1291 |
$params->{'message_id'} ); |
|
|
1292 |
return $result; |
1301 |
return $result; |
1293 |
} |
1302 |
} |
1294 |
|
1303 |
|