Lines 1000-1008
sub EnqueueLetter {
Link Here
|
1000 |
my $dbh = C4::Context->dbh(); |
1000 |
my $dbh = C4::Context->dbh(); |
1001 |
my $statement = << 'ENDSQL'; |
1001 |
my $statement = << 'ENDSQL'; |
1002 |
INSERT INTO message_queue |
1002 |
INSERT INTO message_queue |
1003 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type ) |
1003 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note ) |
1004 |
VALUES |
1004 |
VALUES |
1005 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ? ) |
1005 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? ) |
1006 |
ENDSQL |
1006 |
ENDSQL |
1007 |
|
1007 |
|
1008 |
my $sth = $dbh->prepare($statement); |
1008 |
my $sth = $dbh->prepare($statement); |
Lines 1017-1022
ENDSQL
Link Here
|
1017 |
$params->{'to_address'}, # to_address |
1017 |
$params->{'to_address'}, # to_address |
1018 |
$params->{'from_address'}, # from_address |
1018 |
$params->{'from_address'}, # from_address |
1019 |
$params->{'letter'}->{'content-type'}, # content_type |
1019 |
$params->{'letter'}->{'content-type'}, # content_type |
|
|
1020 |
$params->{'delivery_note'} || '', # delivery_note |
1020 |
); |
1021 |
); |
1021 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
1022 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
1022 |
} |
1023 |
} |
Lines 1113-1119
sub GetQueuedMessages {
Link Here
|
1113 |
|
1114 |
|
1114 |
my $dbh = C4::Context->dbh(); |
1115 |
my $dbh = C4::Context->dbh(); |
1115 |
my $statement = << 'ENDSQL'; |
1116 |
my $statement = << 'ENDSQL'; |
1116 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1117 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note |
1117 |
FROM message_queue |
1118 |
FROM message_queue |
1118 |
ENDSQL |
1119 |
ENDSQL |
1119 |
|
1120 |
|
Lines 1296-1302
sub _send_message_by_email {
Link Here
|
1296 |
unless ($member) { |
1297 |
unless ($member) { |
1297 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1298 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1298 |
_set_message_status( { message_id => $message->{'message_id'}, |
1299 |
_set_message_status( { message_id => $message->{'message_id'}, |
1299 |
status => 'failed' } ); |
1300 |
status => 'failed', |
|
|
1301 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1300 |
return; |
1302 |
return; |
1301 |
} |
1303 |
} |
1302 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1304 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
Lines 1304-1310
sub _send_message_by_email {
Link Here
|
1304 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1306 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1305 |
# warning too verbose for this more common case? |
1307 |
# warning too verbose for this more common case? |
1306 |
_set_message_status( { message_id => $message->{'message_id'}, |
1308 |
_set_message_status( { message_id => $message->{'message_id'}, |
1307 |
status => 'failed' } ); |
1309 |
status => 'failed', |
|
|
1310 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1308 |
return; |
1311 |
return; |
1309 |
} |
1312 |
} |
1310 |
} |
1313 |
} |
Lines 1346-1356
sub _send_message_by_email {
Link Here
|
1346 |
|
1349 |
|
1347 |
if ( sendmail( %sendmail_params ) ) { |
1350 |
if ( sendmail( %sendmail_params ) ) { |
1348 |
_set_message_status( { message_id => $message->{'message_id'}, |
1351 |
_set_message_status( { message_id => $message->{'message_id'}, |
1349 |
status => 'sent' } ); |
1352 |
status => 'sent', |
|
|
1353 |
delivery_note => '' } ); |
1350 |
return 1; |
1354 |
return 1; |
1351 |
} else { |
1355 |
} else { |
1352 |
_set_message_status( { message_id => $message->{'message_id'}, |
1356 |
_set_message_status( { message_id => $message->{'message_id'}, |
1353 |
status => 'failed' } ); |
1357 |
status => 'failed', |
|
|
1358 |
delivery_note => $Mail::Sendmail::error } ); |
1354 |
carp $Mail::Sendmail::error; |
1359 |
carp $Mail::Sendmail::error; |
1355 |
return; |
1360 |
return; |
1356 |
} |
1361 |
} |
Lines 1399-1411
sub _send_message_by_sms {
Link Here
|
1399 |
|
1404 |
|
1400 |
unless ( $member->{smsalertnumber} ) { |
1405 |
unless ( $member->{smsalertnumber} ) { |
1401 |
_set_message_status( { message_id => $message->{'message_id'}, |
1406 |
_set_message_status( { message_id => $message->{'message_id'}, |
1402 |
status => 'failed' } ); |
1407 |
status => 'failed', |
|
|
1408 |
delivery_note => 'Missing SMS number' } ); |
1403 |
return; |
1409 |
return; |
1404 |
} |
1410 |
} |
1405 |
|
1411 |
|
1406 |
if ( _is_duplicate( $message ) ) { |
1412 |
if ( _is_duplicate( $message ) ) { |
1407 |
_set_message_status( { message_id => $message->{'message_id'}, |
1413 |
_set_message_status( { message_id => $message->{'message_id'}, |
1408 |
status => 'failed' } ); |
1414 |
status => 'failed', |
|
|
1415 |
delivery_note => 'Message is duplicate' } ); |
1409 |
return; |
1416 |
return; |
1410 |
} |
1417 |
} |
1411 |
|
1418 |
|
Lines 1413-1419
sub _send_message_by_sms {
Link Here
|
1413 |
message => $message->{'content'}, |
1420 |
message => $message->{'content'}, |
1414 |
} ); |
1421 |
} ); |
1415 |
_set_message_status( { message_id => $message->{'message_id'}, |
1422 |
_set_message_status( { message_id => $message->{'message_id'}, |
1416 |
status => ($success ? 'sent' : 'failed') } ); |
1423 |
status => ($success ? 'sent' : 'failed'), |
|
|
1424 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1425 |
|
1417 |
return $success; |
1426 |
return $success; |
1418 |
} |
1427 |
} |
1419 |
|
1428 |
|
Lines 1431-1439
sub _set_message_status {
Link Here
|
1431 |
} |
1440 |
} |
1432 |
|
1441 |
|
1433 |
my $dbh = C4::Context->dbh(); |
1442 |
my $dbh = C4::Context->dbh(); |
1434 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1443 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1435 |
my $sth = $dbh->prepare( $statement ); |
1444 |
my $sth = $dbh->prepare( $statement ); |
1436 |
my $result = $sth->execute( $params->{'status'}, |
1445 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1446 |
$params->{'delivery_note'} || '', |
1437 |
$params->{'message_id'} ); |
1447 |
$params->{'message_id'} ); |
1438 |
return $result; |
1448 |
return $result; |
1439 |
} |
1449 |
} |