Lines 963-971
sub EnqueueLetter {
Link Here
|
963 |
my $dbh = C4::Context->dbh(); |
963 |
my $dbh = C4::Context->dbh(); |
964 |
my $statement = << 'ENDSQL'; |
964 |
my $statement = << 'ENDSQL'; |
965 |
INSERT INTO message_queue |
965 |
INSERT INTO message_queue |
966 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, reply_address, content_type ) |
966 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, reply_address, content_type, delivery_note ) |
967 |
VALUES |
967 |
VALUES |
968 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? ) |
968 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ?, ? ) |
969 |
ENDSQL |
969 |
ENDSQL |
970 |
|
970 |
|
971 |
my $sth = $dbh->prepare($statement); |
971 |
my $sth = $dbh->prepare($statement); |
Lines 981-986
ENDSQL
Link Here
|
981 |
$params->{'from_address'}, # from_address |
981 |
$params->{'from_address'}, # from_address |
982 |
$params->{'reply_address'}, # reply_address |
982 |
$params->{'reply_address'}, # reply_address |
983 |
$params->{'letter'}->{'content-type'}, # content_type |
983 |
$params->{'letter'}->{'content-type'}, # content_type |
|
|
984 |
$params->{'delivery_note'} || '', # delivery_note |
984 |
); |
985 |
); |
985 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
986 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
986 |
} |
987 |
} |
Lines 1123-1129
sub GetQueuedMessages {
Link Here
|
1123 |
|
1124 |
|
1124 |
my $dbh = C4::Context->dbh(); |
1125 |
my $dbh = C4::Context->dbh(); |
1125 |
my $statement = << 'ENDSQL'; |
1126 |
my $statement = << 'ENDSQL'; |
1126 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, updated_on |
1127 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, updated_on, delivery_note |
1127 |
FROM message_queue |
1128 |
FROM message_queue |
1128 |
ENDSQL |
1129 |
ENDSQL |
1129 |
|
1130 |
|
Lines 1177-1183
sub GetMessage {
Link Here
|
1177 |
return unless $message_id; |
1178 |
return unless $message_id; |
1178 |
my $dbh = C4::Context->dbh; |
1179 |
my $dbh = C4::Context->dbh; |
1179 |
return $dbh->selectrow_hashref(q| |
1180 |
return $dbh->selectrow_hashref(q| |
1180 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, updated_on, to_address, from_address, reply_address, content_type |
1181 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, updated_on, to_address, from_address, reply_address, content_type, delivery_note |
1181 |
FROM message_queue |
1182 |
FROM message_queue |
1182 |
WHERE message_id = ? |
1183 |
WHERE message_id = ? |
1183 |
|, {}, $message_id ); |
1184 |
|, {}, $message_id ); |
Lines 1282-1288
sub _get_unsent_messages {
Link Here
|
1282 |
|
1283 |
|
1283 |
my $dbh = C4::Context->dbh(); |
1284 |
my $dbh = C4::Context->dbh(); |
1284 |
my $statement = qq{ |
1285 |
my $statement = qq{ |
1285 |
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.reply_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code |
1286 |
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.reply_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code, mq.delivery_note |
1286 |
FROM message_queue mq |
1287 |
FROM message_queue mq |
1287 |
LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber |
1288 |
LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber |
1288 |
WHERE status = ? |
1289 |
WHERE status = ? |
Lines 1333-1339
sub _send_message_by_email {
Link Here
|
1333 |
unless ($patron) { |
1334 |
unless ($patron) { |
1334 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1335 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1335 |
_set_message_status( { message_id => $message->{'message_id'}, |
1336 |
_set_message_status( { message_id => $message->{'message_id'}, |
1336 |
status => 'failed' } ); |
1337 |
status => 'failed', |
|
|
1338 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1337 |
return; |
1339 |
return; |
1338 |
} |
1340 |
} |
1339 |
$to_address = $patron->notice_email_address; |
1341 |
$to_address = $patron->notice_email_address; |
Lines 1341-1347
sub _send_message_by_email {
Link Here
|
1341 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1343 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1342 |
# warning too verbose for this more common case? |
1344 |
# warning too verbose for this more common case? |
1343 |
_set_message_status( { message_id => $message->{'message_id'}, |
1345 |
_set_message_status( { message_id => $message->{'message_id'}, |
1344 |
status => 'failed' } ); |
1346 |
status => 'failed', |
|
|
1347 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1345 |
return; |
1348 |
return; |
1346 |
} |
1349 |
} |
1347 |
} |
1350 |
} |
Lines 1417-1423
sub _send_message_by_email {
Link Here
|
1417 |
_set_message_status( |
1420 |
_set_message_status( |
1418 |
{ |
1421 |
{ |
1419 |
message_id => $message->{'message_id'}, |
1422 |
message_id => $message->{'message_id'}, |
1420 |
status => 'sent' |
1423 |
status => 'sent', |
|
|
1424 |
delivery_note => '' |
1421 |
} |
1425 |
} |
1422 |
); |
1426 |
); |
1423 |
return 1; |
1427 |
return 1; |
Lines 1426-1432
sub _send_message_by_email {
Link Here
|
1426 |
_set_message_status( |
1430 |
_set_message_status( |
1427 |
{ |
1431 |
{ |
1428 |
message_id => $message->{'message_id'}, |
1432 |
message_id => $message->{'message_id'}, |
1429 |
status => 'failed' |
1433 |
status => 'failed', |
|
|
1434 |
delivery_note => $Mail::Sendmail::error |
1430 |
} |
1435 |
} |
1431 |
); |
1436 |
); |
1432 |
carp "$_"; |
1437 |
carp "$_"; |
Lines 1477-1489
sub _send_message_by_sms {
Link Here
|
1477 |
|
1482 |
|
1478 |
unless ( $patron and $patron->smsalertnumber ) { |
1483 |
unless ( $patron and $patron->smsalertnumber ) { |
1479 |
_set_message_status( { message_id => $message->{'message_id'}, |
1484 |
_set_message_status( { message_id => $message->{'message_id'}, |
1480 |
status => 'failed' } ); |
1485 |
status => 'failed', |
|
|
1486 |
delivery_note => 'Missing SMS number' } ); |
1481 |
return; |
1487 |
return; |
1482 |
} |
1488 |
} |
1483 |
|
1489 |
|
1484 |
if ( _is_duplicate( $message ) ) { |
1490 |
if ( _is_duplicate( $message ) ) { |
1485 |
_set_message_status( { message_id => $message->{'message_id'}, |
1491 |
_set_message_status( { message_id => $message->{'message_id'}, |
1486 |
status => 'failed' } ); |
1492 |
status => 'failed', |
|
|
1493 |
delivery_note => 'Message is duplicate' } ); |
1487 |
return; |
1494 |
return; |
1488 |
} |
1495 |
} |
1489 |
|
1496 |
|
Lines 1491-1497
sub _send_message_by_sms {
Link Here
|
1491 |
message => $message->{'content'}, |
1498 |
message => $message->{'content'}, |
1492 |
} ); |
1499 |
} ); |
1493 |
_set_message_status( { message_id => $message->{'message_id'}, |
1500 |
_set_message_status( { message_id => $message->{'message_id'}, |
1494 |
status => ($success ? 'sent' : 'failed') } ); |
1501 |
status => ($success ? 'sent' : 'failed'), |
|
|
1502 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1503 |
|
1495 |
return $success; |
1504 |
return $success; |
1496 |
} |
1505 |
} |
1497 |
|
1506 |
|
Lines 1515-1523
sub _set_message_status {
Link Here
|
1515 |
} |
1524 |
} |
1516 |
|
1525 |
|
1517 |
my $dbh = C4::Context->dbh(); |
1526 |
my $dbh = C4::Context->dbh(); |
1518 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1527 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1519 |
my $sth = $dbh->prepare( $statement ); |
1528 |
my $sth = $dbh->prepare( $statement ); |
1520 |
my $result = $sth->execute( $params->{'status'}, |
1529 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1530 |
$params->{'delivery_note'} || '', |
1521 |
$params->{'message_id'} ); |
1531 |
$params->{'message_id'} ); |
1522 |
return $result; |
1532 |
return $result; |
1523 |
} |
1533 |
} |