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 1150-1156
sub _send_message_by_email {
Link Here
|
1150 |
unless ($member) { |
1151 |
unless ($member) { |
1151 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1152 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1152 |
_set_message_status( { message_id => $message->{'message_id'}, |
1153 |
_set_message_status( { message_id => $message->{'message_id'}, |
1153 |
status => 'failed' } ); |
1154 |
status => 'failed', |
|
|
1155 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1154 |
return; |
1156 |
return; |
1155 |
} |
1157 |
} |
1156 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1158 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
Lines 1158-1164
sub _send_message_by_email {
Link Here
|
1158 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1160 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1159 |
# warning too verbose for this more common case? |
1161 |
# warning too verbose for this more common case? |
1160 |
_set_message_status( { message_id => $message->{'message_id'}, |
1162 |
_set_message_status( { message_id => $message->{'message_id'}, |
1161 |
status => 'failed' } ); |
1163 |
status => 'failed', |
|
|
1164 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1162 |
return; |
1165 |
return; |
1163 |
} |
1166 |
} |
1164 |
} |
1167 |
} |
Lines 1199-1209
sub _send_message_by_email {
Link Here
|
1199 |
_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 |
1200 |
if ( sendmail( %sendmail_params ) ) { |
1203 |
if ( sendmail( %sendmail_params ) ) { |
1201 |
_set_message_status( { message_id => $message->{'message_id'}, |
1204 |
_set_message_status( { message_id => $message->{'message_id'}, |
1202 |
status => 'sent' } ); |
1205 |
status => 'sent', |
|
|
1206 |
delivery_note => '' } ); |
1203 |
return 1; |
1207 |
return 1; |
1204 |
} else { |
1208 |
} else { |
1205 |
_set_message_status( { message_id => $message->{'message_id'}, |
1209 |
_set_message_status( { message_id => $message->{'message_id'}, |
1206 |
status => 'failed' } ); |
1210 |
status => 'failed', |
|
|
1211 |
delivery_note => $Mail::Sendmail::error } ); |
1207 |
carp $Mail::Sendmail::error; |
1212 |
carp $Mail::Sendmail::error; |
1208 |
return; |
1213 |
return; |
1209 |
} |
1214 |
} |
Lines 1252-1264
sub _send_message_by_sms {
Link Here
|
1252 |
|
1257 |
|
1253 |
unless ( $member->{smsalertnumber} ) { |
1258 |
unless ( $member->{smsalertnumber} ) { |
1254 |
_set_message_status( { message_id => $message->{'message_id'}, |
1259 |
_set_message_status( { message_id => $message->{'message_id'}, |
1255 |
status => 'failed' } ); |
1260 |
status => 'failed', |
|
|
1261 |
delivery_note => 'Missing SMS number' } ); |
1256 |
return; |
1262 |
return; |
1257 |
} |
1263 |
} |
1258 |
|
1264 |
|
1259 |
if ( _is_duplicate( $message ) ) { |
1265 |
if ( _is_duplicate( $message ) ) { |
1260 |
_set_message_status( { message_id => $message->{'message_id'}, |
1266 |
_set_message_status( { message_id => $message->{'message_id'}, |
1261 |
status => 'failed' } ); |
1267 |
status => 'failed', |
|
|
1268 |
delivery_note => 'Message is duplicate' } ); |
1262 |
return; |
1269 |
return; |
1263 |
} |
1270 |
} |
1264 |
|
1271 |
|
Lines 1266-1272
sub _send_message_by_sms {
Link Here
|
1266 |
message => $message->{'content'}, |
1273 |
message => $message->{'content'}, |
1267 |
} ); |
1274 |
} ); |
1268 |
_set_message_status( { message_id => $message->{'message_id'}, |
1275 |
_set_message_status( { message_id => $message->{'message_id'}, |
1269 |
status => ($success ? 'sent' : 'failed') } ); |
1276 |
status => ($success ? 'sent' : 'failed'), |
|
|
1277 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1278 |
|
1270 |
return $success; |
1279 |
return $success; |
1271 |
} |
1280 |
} |
1272 |
|
1281 |
|
Lines 1284-1292
sub _set_message_status {
Link Here
|
1284 |
} |
1293 |
} |
1285 |
|
1294 |
|
1286 |
my $dbh = C4::Context->dbh(); |
1295 |
my $dbh = C4::Context->dbh(); |
1287 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1296 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1288 |
my $sth = $dbh->prepare( $statement ); |
1297 |
my $sth = $dbh->prepare( $statement ); |
1289 |
my $result = $sth->execute( $params->{'status'}, |
1298 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1299 |
$params->{'delivery_note'} || '', |
1290 |
$params->{'message_id'} ); |
1300 |
$params->{'message_id'} ); |
1291 |
return $result; |
1301 |
return $result; |
1292 |
} |
1302 |
} |