Lines 898-906
sub EnqueueLetter {
Link Here
|
898 |
my $dbh = C4::Context->dbh(); |
898 |
my $dbh = C4::Context->dbh(); |
899 |
my $statement = << 'ENDSQL'; |
899 |
my $statement = << 'ENDSQL'; |
900 |
INSERT INTO message_queue |
900 |
INSERT INTO message_queue |
901 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type ) |
901 |
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type, delivery_note ) |
902 |
VALUES |
902 |
VALUES |
903 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ? ) |
903 |
( ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?, ?, ? ) |
904 |
ENDSQL |
904 |
ENDSQL |
905 |
|
905 |
|
906 |
my $sth = $dbh->prepare($statement); |
906 |
my $sth = $dbh->prepare($statement); |
Lines 915-920
ENDSQL
Link Here
|
915 |
$params->{'to_address'}, # to_address |
915 |
$params->{'to_address'}, # to_address |
916 |
$params->{'from_address'}, # from_address |
916 |
$params->{'from_address'}, # from_address |
917 |
$params->{'letter'}->{'content-type'}, # content_type |
917 |
$params->{'letter'}->{'content-type'}, # content_type |
|
|
918 |
$params->{'delivery_note'} || '', # delivery_note |
918 |
); |
919 |
); |
919 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
920 |
return $dbh->last_insert_id(undef,undef,'message_queue', undef); |
920 |
} |
921 |
} |
Lines 1004-1010
sub GetQueuedMessages {
Link Here
|
1004 |
|
1005 |
|
1005 |
my $dbh = C4::Context->dbh(); |
1006 |
my $dbh = C4::Context->dbh(); |
1006 |
my $statement = << 'ENDSQL'; |
1007 |
my $statement = << 'ENDSQL'; |
1007 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1008 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note |
1008 |
FROM message_queue |
1009 |
FROM message_queue |
1009 |
ENDSQL |
1010 |
ENDSQL |
1010 |
|
1011 |
|
Lines 1137-1143
sub _send_message_by_email {
Link Here
|
1137 |
unless ($member) { |
1138 |
unless ($member) { |
1138 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1139 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1139 |
_set_message_status( { message_id => $message->{'message_id'}, |
1140 |
_set_message_status( { message_id => $message->{'message_id'}, |
1140 |
status => 'failed' } ); |
1141 |
status => 'failed', |
|
|
1142 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1141 |
return; |
1143 |
return; |
1142 |
} |
1144 |
} |
1143 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1145 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
Lines 1145-1151
sub _send_message_by_email {
Link Here
|
1145 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1147 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1146 |
# warning too verbose for this more common case? |
1148 |
# warning too verbose for this more common case? |
1147 |
_set_message_status( { message_id => $message->{'message_id'}, |
1149 |
_set_message_status( { message_id => $message->{'message_id'}, |
1148 |
status => 'failed' } ); |
1150 |
status => 'failed', |
|
|
1151 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1149 |
return; |
1152 |
return; |
1150 |
} |
1153 |
} |
1151 |
} |
1154 |
} |
Lines 1186-1196
sub _send_message_by_email {
Link Here
|
1186 |
_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 |
1189 |
_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 |
1187 |
if ( sendmail( %sendmail_params ) ) { |
1190 |
if ( sendmail( %sendmail_params ) ) { |
1188 |
_set_message_status( { message_id => $message->{'message_id'}, |
1191 |
_set_message_status( { message_id => $message->{'message_id'}, |
1189 |
status => 'sent' } ); |
1192 |
status => 'sent', |
|
|
1193 |
delivery_note => '' } ); |
1190 |
return 1; |
1194 |
return 1; |
1191 |
} else { |
1195 |
} else { |
1192 |
_set_message_status( { message_id => $message->{'message_id'}, |
1196 |
_set_message_status( { message_id => $message->{'message_id'}, |
1193 |
status => 'failed' } ); |
1197 |
status => 'failed', |
|
|
1198 |
delivery_note => $Mail::Sendmail::error } ); |
1194 |
carp $Mail::Sendmail::error; |
1199 |
carp $Mail::Sendmail::error; |
1195 |
return; |
1200 |
return; |
1196 |
} |
1201 |
} |
Lines 1239-1251
sub _send_message_by_sms {
Link Here
|
1239 |
|
1244 |
|
1240 |
unless ( $member->{smsalertnumber} ) { |
1245 |
unless ( $member->{smsalertnumber} ) { |
1241 |
_set_message_status( { message_id => $message->{'message_id'}, |
1246 |
_set_message_status( { message_id => $message->{'message_id'}, |
1242 |
status => 'failed' } ); |
1247 |
status => 'failed', |
|
|
1248 |
delivery_note => 'Missing SMS number' } ); |
1243 |
return; |
1249 |
return; |
1244 |
} |
1250 |
} |
1245 |
|
1251 |
|
1246 |
if ( _is_duplicate( $message ) ) { |
1252 |
if ( _is_duplicate( $message ) ) { |
1247 |
_set_message_status( { message_id => $message->{'message_id'}, |
1253 |
_set_message_status( { message_id => $message->{'message_id'}, |
1248 |
status => 'failed' } ); |
1254 |
status => 'failed', |
|
|
1255 |
delivery_note => 'Message is duplicate' } ); |
1249 |
return; |
1256 |
return; |
1250 |
} |
1257 |
} |
1251 |
|
1258 |
|
Lines 1253-1259
sub _send_message_by_sms {
Link Here
|
1253 |
message => $message->{'content'}, |
1260 |
message => $message->{'content'}, |
1254 |
} ); |
1261 |
} ); |
1255 |
_set_message_status( { message_id => $message->{'message_id'}, |
1262 |
_set_message_status( { message_id => $message->{'message_id'}, |
1256 |
status => ($success ? 'sent' : 'failed') } ); |
1263 |
status => ($success ? 'sent' : 'failed'), |
|
|
1264 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1265 |
|
1257 |
return $success; |
1266 |
return $success; |
1258 |
} |
1267 |
} |
1259 |
|
1268 |
|
Lines 1271-1280
sub _set_message_status {
Link Here
|
1271 |
} |
1280 |
} |
1272 |
|
1281 |
|
1273 |
my $dbh = C4::Context->dbh(); |
1282 |
my $dbh = C4::Context->dbh(); |
1274 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1283 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1275 |
my $sth = $dbh->prepare( $statement ); |
1284 |
my $sth = $dbh->prepare( $statement ); |
1276 |
my $result = $sth->execute( $params->{'status'}, |
1285 |
my $result = $sth->execute( $params->{'status'}, |
1277 |
$params->{'message_id'} ); |
1286 |
$params->{'delivery_note'}, |
|
|
1287 |
$params->{'message_id'} || '' ); |
1278 |
return $result; |
1288 |
return $result; |
1279 |
} |
1289 |
} |
1280 |
|
1290 |
|