From 9270f064635ee16910d2a3d1e3e491e6bac22976 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Wed, 15 Jan 2014 16:25:17 +0200 Subject: [PATCH] Bug 11561: restore previous behavior of generation of hold print notices This patch prevents duplicate hold available print notices from being sent and enforces making a print notice if no other transports can be used. ------------------------- - REPLICATING THE ISSUE - ------------------------- 1. Set a Patrons "Hold filled"-messaging preference to SMS + Email 2. Remove the SMS number (sms notification number) and all email addresses. 3. Make a reservation for this Patron. 4. Check-in the reserved Item. 5. message_queue-table has two generated print notices for the Hold_filled event. One for both failed message transport types, email and sms. 1. Set a Patrons "Hold filled"-messaging preference to empty, remove all checks from boxes. 2. Make a reservation for this Patron 3. Check-in the reserved Item. 4. message_queue-table has no message for the Hold-filled event. This is problematic because a Patron should get some kind of a notification for a filled Hold. ----------------------------- - AFTER APPLYING THIS PATCH - ----------------------------- If all message transport types for "Hold filled" fail, a print notice is queued in the message_queue table. Only one print message is queued even if many transports attempts fail. Signed-off-by: Galen Charlton --- C4/Reserves.pm | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 339621b267..ad866af229 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1921,12 +1921,9 @@ sub _koha_notify_reserve { substitute => { today => C4::Dates->new()->output() }, ); - my $print_sent = 0; - while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) { - if ( ($mtt eq 'email' and not $to_address) or ($mtt eq 'sms' and not $borrower->{smsalertnumber}) ) { - # email or sms is requested but not exist, do a print. - $mtt = 'print'; - } + my $notification_sent = 0; #Keeping track if a Hold_filled message is sent. If no message can be sent, then default to a print message. + my $send_notification = sub { + my ( $mtt, $letter_code ) = (@_); $letter_params{letter_code} = $letter_code; $letter_params{message_transport_type} = $mtt; my $letter = C4::Letters::GetPreparedLetter ( %letter_params ) @@ -1938,7 +1935,21 @@ sub _koha_notify_reserve { from_address => $admin_email_address, message_transport_type => $mtt, } ); + }; + + while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) { + if ( ($mtt eq 'email' and not $to_address) or ($mtt eq 'sms' and not $borrower->{smsalertnumber}) ) { + # email or sms is requested but not exist + next; + } + &$send_notification($mtt, $letter_code); + $notification_sent++; } + #Making sure that a print notification is sent if no other transport types can be utilized. + if (! $notification_sent) { + &$send_notification('print', 'HOLD'); + } + } =head2 _ShiftPriorityByDateAndPriority -- 2.39.5