Lines 911-919
sub EnqueueLetter {
Link Here
|
911 |
my $dbh = C4::Context->dbh(); |
911 |
my $dbh = C4::Context->dbh(); |
912 |
my $statement = << 'ENDSQL'; |
912 |
my $statement = << 'ENDSQL'; |
913 |
INSERT INTO message_queue |
913 |
INSERT INTO message_queue |
914 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type ) |
914 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note ) |
915 |
VALUES |
915 |
VALUES |
916 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ? ) |
916 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? ) |
917 |
ENDSQL |
917 |
ENDSQL |
918 |
|
918 |
|
919 |
my $sth = $dbh->prepare($statement); |
919 |
my $sth = $dbh->prepare($statement); |
Lines 928-933
ENDSQL
Link Here
|
928 |
$params->{'to_address'}, # to_address |
928 |
$params->{'to_address'}, # to_address |
929 |
$params->{'from_address'}, # from_address |
929 |
$params->{'from_address'}, # from_address |
930 |
$params->{'letter'}->{'content-type'}, # content_type |
930 |
$params->{'letter'}->{'content-type'}, # content_type |
|
|
931 |
$params->{'delivery_note'} || '', # delivery_note |
931 |
); |
932 |
); |
932 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
933 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
933 |
} |
934 |
} |
Lines 1017-1023
sub GetQueuedMessages {
Link Here
|
1017 |
|
1018 |
|
1018 |
my $dbh = C4::Context->dbh(); |
1019 |
my $dbh = C4::Context->dbh(); |
1019 |
my $statement = << 'ENDSQL'; |
1020 |
my $statement = << 'ENDSQL'; |
1020 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1021 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note |
1021 |
FROM message_queue |
1022 |
FROM message_queue |
1022 |
ENDSQL |
1023 |
ENDSQL |
1023 |
|
1024 |
|
Lines 1071-1077
sub GetMessage {
Link Here
|
1071 |
return unless $message_id; |
1072 |
return unless $message_id; |
1072 |
my $dbh = C4::Context->dbh; |
1073 |
my $dbh = C4::Context->dbh; |
1073 |
return $dbh->selectrow_hashref(q| |
1074 |
return $dbh->selectrow_hashref(q| |
1074 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type |
1075 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note |
1075 |
FROM message_queue |
1076 |
FROM message_queue |
1076 |
WHERE message_id = ? |
1077 |
WHERE message_id = ? |
1077 |
|, {}, $message_id ); |
1078 |
|, {}, $message_id ); |
Lines 1195-1201
sub _send_message_by_email {
Link Here
|
1195 |
unless ($member) { |
1196 |
unless ($member) { |
1196 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1197 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1197 |
_set_message_status( { message_id => $message->{'message_id'}, |
1198 |
_set_message_status( { message_id => $message->{'message_id'}, |
1198 |
status => 'failed' } ); |
1199 |
status => 'failed', |
|
|
1200 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1199 |
return; |
1201 |
return; |
1200 |
} |
1202 |
} |
1201 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1203 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
Lines 1203-1209
sub _send_message_by_email {
Link Here
|
1203 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1205 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1204 |
# warning too verbose for this more common case? |
1206 |
# warning too verbose for this more common case? |
1205 |
_set_message_status( { message_id => $message->{'message_id'}, |
1207 |
_set_message_status( { message_id => $message->{'message_id'}, |
1206 |
status => 'failed' } ); |
1208 |
status => 'failed', |
|
|
1209 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1207 |
return; |
1210 |
return; |
1208 |
} |
1211 |
} |
1209 |
} |
1212 |
} |
Lines 1244-1254
sub _send_message_by_email {
Link Here
|
1244 |
_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 |
1247 |
_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 |
1245 |
if ( sendmail( %sendmail_params ) ) { |
1248 |
if ( sendmail( %sendmail_params ) ) { |
1246 |
_set_message_status( { message_id => $message->{'message_id'}, |
1249 |
_set_message_status( { message_id => $message->{'message_id'}, |
1247 |
status => 'sent' } ); |
1250 |
status => 'sent', |
|
|
1251 |
delivery_note => '' } ); |
1248 |
return 1; |
1252 |
return 1; |
1249 |
} else { |
1253 |
} else { |
1250 |
_set_message_status( { message_id => $message->{'message_id'}, |
1254 |
_set_message_status( { message_id => $message->{'message_id'}, |
1251 |
status => 'failed' } ); |
1255 |
status => 'failed', |
|
|
1256 |
delivery_note => $Mail::Sendmail::error } ); |
1252 |
carp $Mail::Sendmail::error; |
1257 |
carp $Mail::Sendmail::error; |
1253 |
return; |
1258 |
return; |
1254 |
} |
1259 |
} |
Lines 1297-1309
sub _send_message_by_sms {
Link Here
|
1297 |
|
1302 |
|
1298 |
unless ( $member->{smsalertnumber} ) { |
1303 |
unless ( $member->{smsalertnumber} ) { |
1299 |
_set_message_status( { message_id => $message->{'message_id'}, |
1304 |
_set_message_status( { message_id => $message->{'message_id'}, |
1300 |
status => 'failed' } ); |
1305 |
status => 'failed', |
|
|
1306 |
delivery_note => 'Missing SMS number' } ); |
1301 |
return; |
1307 |
return; |
1302 |
} |
1308 |
} |
1303 |
|
1309 |
|
1304 |
if ( _is_duplicate( $message ) ) { |
1310 |
if ( _is_duplicate( $message ) ) { |
1305 |
_set_message_status( { message_id => $message->{'message_id'}, |
1311 |
_set_message_status( { message_id => $message->{'message_id'}, |
1306 |
status => 'failed' } ); |
1312 |
status => 'failed', |
|
|
1313 |
delivery_note => 'Message is duplicate' } ); |
1307 |
return; |
1314 |
return; |
1308 |
} |
1315 |
} |
1309 |
|
1316 |
|
Lines 1311-1317
sub _send_message_by_sms {
Link Here
|
1311 |
message => $message->{'content'}, |
1318 |
message => $message->{'content'}, |
1312 |
} ); |
1319 |
} ); |
1313 |
_set_message_status( { message_id => $message->{'message_id'}, |
1320 |
_set_message_status( { message_id => $message->{'message_id'}, |
1314 |
status => ($success ? 'sent' : 'failed') } ); |
1321 |
status => ($success ? 'sent' : 'failed'), |
|
|
1322 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1323 |
|
1315 |
return $success; |
1324 |
return $success; |
1316 |
} |
1325 |
} |
1317 |
|
1326 |
|
Lines 1329-1337
sub _set_message_status {
Link Here
|
1329 |
} |
1338 |
} |
1330 |
|
1339 |
|
1331 |
my $dbh = C4::Context->dbh(); |
1340 |
my $dbh = C4::Context->dbh(); |
1332 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1341 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1333 |
my $sth = $dbh->prepare( $statement ); |
1342 |
my $sth = $dbh->prepare( $statement ); |
1334 |
my $result = $sth->execute( $params->{'status'}, |
1343 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1344 |
$params->{'delivery_note'} || '', |
1335 |
$params->{'message_id'} ); |
1345 |
$params->{'message_id'} ); |
1336 |
return $result; |
1346 |
return $result; |
1337 |
} |
1347 |
} |