Lines 1004-1010
sub GetQueuedMessages {
Link Here
|
1004 |
|
1004 |
|
1005 |
my $dbh = C4::Context->dbh(); |
1005 |
my $dbh = C4::Context->dbh(); |
1006 |
my $statement = << 'ENDSQL'; |
1006 |
my $statement = << 'ENDSQL'; |
1007 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1007 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note |
1008 |
FROM message_queue |
1008 |
FROM message_queue |
1009 |
ENDSQL |
1009 |
ENDSQL |
1010 |
|
1010 |
|
Lines 1137-1143
sub _send_message_by_email {
Link Here
|
1137 |
unless ($member) { |
1137 |
unless ($member) { |
1138 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1138 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1139 |
_set_message_status( { message_id => $message->{'message_id'}, |
1139 |
_set_message_status( { message_id => $message->{'message_id'}, |
1140 |
status => 'failed' } ); |
1140 |
status => 'failed', |
|
|
1141 |
delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } ); |
1141 |
return; |
1142 |
return; |
1142 |
} |
1143 |
} |
1143 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1144 |
$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})"; |
1146 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1146 |
# warning too verbose for this more common case? |
1147 |
# warning too verbose for this more common case? |
1147 |
_set_message_status( { message_id => $message->{'message_id'}, |
1148 |
_set_message_status( { message_id => $message->{'message_id'}, |
1148 |
status => 'failed' } ); |
1149 |
status => 'failed', |
|
|
1150 |
delivery_note => 'Unable to find an email address for this borrower' } ); |
1149 |
return; |
1151 |
return; |
1150 |
} |
1152 |
} |
1151 |
} |
1153 |
} |
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 |
1188 |
_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 ) ) { |
1189 |
if ( sendmail( %sendmail_params ) ) { |
1188 |
_set_message_status( { message_id => $message->{'message_id'}, |
1190 |
_set_message_status( { message_id => $message->{'message_id'}, |
1189 |
status => 'sent' } ); |
1191 |
status => 'sent', |
|
|
1192 |
delivery_note => '' } ); |
1190 |
return 1; |
1193 |
return 1; |
1191 |
} else { |
1194 |
} else { |
1192 |
_set_message_status( { message_id => $message->{'message_id'}, |
1195 |
_set_message_status( { message_id => $message->{'message_id'}, |
1193 |
status => 'failed' } ); |
1196 |
status => 'failed', |
|
|
1197 |
delivery_note => $Mail::Sendmail::error } ); |
1194 |
carp $Mail::Sendmail::error; |
1198 |
carp $Mail::Sendmail::error; |
1195 |
return; |
1199 |
return; |
1196 |
} |
1200 |
} |
Lines 1239-1259
sub _send_message_by_sms {
Link Here
|
1239 |
|
1243 |
|
1240 |
unless ( $member->{smsalertnumber} ) { |
1244 |
unless ( $member->{smsalertnumber} ) { |
1241 |
_set_message_status( { message_id => $message->{'message_id'}, |
1245 |
_set_message_status( { message_id => $message->{'message_id'}, |
1242 |
status => 'failed' } ); |
1246 |
status => 'failed', |
|
|
1247 |
delivery_note => 'Missing SMS number' } ); |
1243 |
return; |
1248 |
return; |
1244 |
} |
1249 |
} |
1245 |
|
1250 |
|
1246 |
if ( _is_duplicate( $message ) ) { |
1251 |
if ( _is_duplicate( $message ) ) { |
1247 |
_set_message_status( { message_id => $message->{'message_id'}, |
1252 |
_set_message_status( { message_id => $message->{'message_id'}, |
1248 |
status => 'failed' } ); |
1253 |
status => 'failed', |
|
|
1254 |
delivery_note => 'Message is duplicate' } ); |
1249 |
return; |
1255 |
return; |
1250 |
} |
1256 |
} |
1251 |
|
1257 |
|
1252 |
my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'}, |
1258 |
my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'}, |
1253 |
message => $message->{'content'}, |
1259 |
message => $message->{'content'}, |
|
|
1260 |
message_id => $message->{'message_id'} |
1254 |
} ); |
1261 |
} ); |
1255 |
_set_message_status( { message_id => $message->{'message_id'}, |
1262 |
|
1256 |
status => ($success ? 'sent' : 'failed') } ); |
1263 |
# Some SMS::Send drivers return a hash with delivery note, and some only |
|
|
1264 |
# success value. Let's add an appropriate delivery note if driver returns |
1265 |
# us one. |
1266 |
if (ref($success) eq 'HASH') { |
1267 |
_set_message_status( { message_id => $message->{'message_id'}, |
1268 |
status => ($success->{status} ? 'sent' : 'failed'), |
1269 |
delivery_note => $success->{delivery_note} } ); |
1270 |
} else { |
1271 |
_set_message_status( { message_id => $message->{'message_id'}, |
1272 |
status => ($success ? 'sent' : 'failed'), |
1273 |
delivery_note => ($success ? '' : 'No notes from SMS driver') } ); |
1274 |
} |
1275 |
|
1257 |
return $success; |
1276 |
return $success; |
1258 |
} |
1277 |
} |
1259 |
|
1278 |
|
Lines 1271-1279
sub _set_message_status {
Link Here
|
1271 |
} |
1290 |
} |
1272 |
|
1291 |
|
1273 |
my $dbh = C4::Context->dbh(); |
1292 |
my $dbh = C4::Context->dbh(); |
1274 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1293 |
my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?'; |
1275 |
my $sth = $dbh->prepare( $statement ); |
1294 |
my $sth = $dbh->prepare( $statement ); |
1276 |
my $result = $sth->execute( $params->{'status'}, |
1295 |
my $result = $sth->execute( $params->{'status'}, |
|
|
1296 |
$params->{'delivery_note'}, |
1277 |
$params->{'message_id'} ); |
1297 |
$params->{'message_id'} ); |
1278 |
return $result; |
1298 |
return $result; |
1279 |
} |
1299 |
} |