Lines 908-916
sub EnqueueLetter {
Link Here
|
908 |
my $dbh = C4::Context->dbh(); |
908 |
my $dbh = C4::Context->dbh(); |
909 |
my $statement = << 'ENDSQL'; |
909 |
my $statement = << 'ENDSQL'; |
910 |
INSERT INTO message_queue |
910 |
INSERT INTO message_queue |
911 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type ) |
911 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note ) |
912 |
VALUES |
912 |
VALUES |
913 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ? ) |
913 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? ) |
914 |
ENDSQL |
914 |
ENDSQL |
915 |
|
915 |
|
916 |
my $sth = $dbh->prepare($statement); |
916 |
my $sth = $dbh->prepare($statement); |
Lines 925-930
ENDSQL
Link Here
|
925 |
$params->{'to_address'}, # to_address |
925 |
$params->{'to_address'}, # to_address |
926 |
$params->{'from_address'}, # from_address |
926 |
$params->{'from_address'}, # from_address |
927 |
$params->{'letter'}->{'content-type'}, # content_type |
927 |
$params->{'letter'}->{'content-type'}, # content_type |
|
|
928 |
$params->{'delivery_note'} || '', # delivery_note |
928 |
); |
929 |
); |
929 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
930 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
930 |
} |
931 |
} |
Lines 1066-1072
sub GetQueuedMessages {
Link Here
|
1066 |
|
1067 |
|
1067 |
my $dbh = C4::Context->dbh(); |
1068 |
my $dbh = C4::Context->dbh(); |
1068 |
my $statement = << 'ENDSQL'; |
1069 |
my $statement = << 'ENDSQL'; |
1069 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1070 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note |
1070 |
FROM message_queue |
1071 |
FROM message_queue |
1071 |
ENDSQL |
1072 |
ENDSQL |
1072 |
|
1073 |
|
Lines 1120-1126
sub GetMessage {
Link Here
|
1120 |
return unless $message_id; |
1121 |
return unless $message_id; |
1121 |
my $dbh = C4::Context->dbh; |
1122 |
my $dbh = C4::Context->dbh; |
1122 |
return $dbh->selectrow_hashref(q| |
1123 |
return $dbh->selectrow_hashref(q| |
1123 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type |
1124 |
SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note |
1124 |
FROM message_queue |
1125 |
FROM message_queue |
1125 |
WHERE message_id = ? |
1126 |
WHERE message_id = ? |
1126 |
|, {}, $message_id ); |
1127 |
|, {}, $message_id ); |
Lines 1224-1230
sub _get_unsent_messages {
Link Here
|
1224 |
|
1225 |
|
1225 |
my $dbh = C4::Context->dbh(); |
1226 |
my $dbh = C4::Context->dbh(); |
1226 |
my $statement = qq{ |
1227 |
my $statement = qq{ |
1227 |
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code |
1228 |
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code, mq.delivery_note |
1228 |
FROM message_queue mq |
1229 |
FROM message_queue mq |
1229 |
LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber |
1230 |
LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber |
1230 |
WHERE status = ? |
1231 |
WHERE status = ? |
Lines 1271-1277
sub _send_message_by_email {
Link Here
|
1271 |
unless ($patron) { |
1272 |
unless ($patron) { |
1272 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1273 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1273 |
_set_message_status( { message_id => $message->{'message_id'}, |
1274 |
_set_message_status( { message_id => $message->{'message_id'}, |
1274 |
status => 'failed' } ); |
1275 |
status => 'failed', |
|
|
1276 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1275 |
return; |
1277 |
return; |
1276 |
} |
1278 |
} |
1277 |
$to_address = $patron->notice_email_address; |
1279 |
$to_address = $patron->notice_email_address; |
Lines 1279-1285
sub _send_message_by_email {
Link Here
|
1279 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1281 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1280 |
# warning too verbose for this more common case? |
1282 |
# warning too verbose for this more common case? |
1281 |
_set_message_status( { message_id => $message->{'message_id'}, |
1283 |
_set_message_status( { message_id => $message->{'message_id'}, |
1282 |
status => 'failed' } ); |
1284 |
status => 'failed', |
|
|
1285 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1283 |
return; |
1286 |
return; |
1284 |
} |
1287 |
} |
1285 |
} |
1288 |
} |
Lines 1322-1332
sub _send_message_by_email {
Link Here
|
1322 |
|
1325 |
|
1323 |
if ( Mail::Sendmail::sendmail( %sendmail_params ) ) { |
1326 |
if ( Mail::Sendmail::sendmail( %sendmail_params ) ) { |
1324 |
_set_message_status( { message_id => $message->{'message_id'}, |
1327 |
_set_message_status( { message_id => $message->{'message_id'}, |
1325 |
status => 'sent' } ); |
1328 |
status => 'sent', |
|
|
1329 |
delivery_note => '' } ); |
1326 |
return 1; |
1330 |
return 1; |
1327 |
} else { |
1331 |
} else { |
1328 |
_set_message_status( { message_id => $message->{'message_id'}, |
1332 |
_set_message_status( { message_id => $message->{'message_id'}, |
1329 |
status => 'failed' } ); |
1333 |
status => 'failed', |
|
|
1334 |
delivery_note => $Mail::Sendmail::error } ); |
1330 |
carp $Mail::Sendmail::error; |
1335 |
carp $Mail::Sendmail::error; |
1331 |
return; |
1336 |
return; |
1332 |
} |
1337 |
} |
Lines 1375-1387
sub _send_message_by_sms {
Link Here
|
1375 |
|
1380 |
|
1376 |
unless ( $patron and $patron->smsalertnumber ) { |
1381 |
unless ( $patron and $patron->smsalertnumber ) { |
1377 |
_set_message_status( { message_id => $message->{'message_id'}, |
1382 |
_set_message_status( { message_id => $message->{'message_id'}, |
1378 |
status => 'failed' } ); |
1383 |
status => 'failed', |
|
|
1384 |
delivery_note => 'Missing SMS number' } ); |
1379 |
return; |
1385 |
return; |
1380 |
} |
1386 |
} |
1381 |
|
1387 |
|
1382 |
if ( _is_duplicate( $message ) ) { |
1388 |
if ( _is_duplicate( $message ) ) { |
1383 |
_set_message_status( { message_id => $message->{'message_id'}, |
1389 |
_set_message_status( { message_id => $message->{'message_id'}, |
1384 |
status => 'failed' } ); |
1390 |
status => 'failed', |
|
|
1391 |
delivery_note => 'Message is duplicate' } ); |
1385 |
return; |
1392 |
return; |
1386 |
} |
1393 |
} |
1387 |
|
1394 |
|
Lines 1389-1395
sub _send_message_by_sms {
Link Here
|
1389 |
message => $message->{'content'}, |
1396 |
message => $message->{'content'}, |
1390 |
} ); |
1397 |
} ); |
1391 |
_set_message_status( { message_id => $message->{'message_id'}, |
1398 |
_set_message_status( { message_id => $message->{'message_id'}, |
1392 |
status => ($success ? 'sent' : 'failed') } ); |
1399 |
status => ($success ? 'sent' : 'failed'), |
|
|
1400 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1401 |
|
1393 |
return $success; |
1402 |
return $success; |
1394 |
} |
1403 |
} |
1395 |
|
1404 |
|
Lines 1413-1421
sub _set_message_status {
Link Here
|
1413 |
} |
1422 |
} |
1414 |
|
1423 |
|
1415 |
my $dbh = C4::Context->dbh(); |
1424 |
my $dbh = C4::Context->dbh(); |
1416 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1425 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1417 |
my $sth = $dbh->prepare( $statement ); |
1426 |
my $sth = $dbh->prepare( $statement ); |
1418 |
my $result = $sth->execute( $params->{'status'}, |
1427 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1428 |
$params->{'delivery_note'} || '', |
1419 |
$params->{'message_id'} ); |
1429 |
$params->{'message_id'} ); |
1420 |
return $result; |
1430 |
return $result; |
1421 |
} |
1431 |
} |