From 1c244fe0223b3e063f0d62482c34c4149e844fd6 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 15 Sep 2020 15:07:28 +1200 Subject: [PATCH] Bug 20453: Manage sending of HOLD_MANUAL_CANCEL notice with patron messaging preferences To test: 1) Apply this patch and run database updates 2) Confirm the 'Hold manually cancelled' option shows on the patron messaging preferences table on both the staff client and the OPAC. It should be unchecked (NOT enabled). 3) Follow the test plan from the second patch "Send notice when cancelling a hold from intranet" 4) Confirm that after completing the test plan, Borrower A has not been sent any notices (Check Notices tab) 5) Check the 'Hold manually cancelled' option in the patron messaging preferences (enable). 6) Go through the previous test plan again. 7) Refresh the Notices tab each time you cancel a hold. Confirm a new notice is pending with each refresh. Sponsored-by: Waikato Institute of Technology --- C4/Reserves.pm | 18 ++++++++++++++++-- circ/pendingreserves.pl | 18 ++++++++++++++++-- .../atomicupdate/bug_20453-message_attributes.perl | 6 ++++++ .../atomicupdate/bug_20453-message_transports.perl | 6 ++++++ .../prog/en/includes/messaging-preference-form.inc | 1 + .../opac-tmpl/bootstrap/en/modules/opac-messaging.tt | 1 + reserve/request.pl | 9 ++++++++- 7 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_20453-message_attributes.perl create mode 100644 installer/data/mysql/atomicupdate/bug_20453-message_transports.perl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 96c2d4ca89..c6d61b4bbc 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1021,7 +1021,14 @@ sub ModReserve { 'borrowers', $hold_borrowernumber } ); - C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $hold_borrowernumber, message_name => 'Hold_Manually_Cancelled' }); + + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ){ + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + } + } } elsif ($rank =~ /^\d+/ and $rank > 0) { logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) ) if C4::Context->preference('HoldsLog'); @@ -1236,7 +1243,14 @@ sub ModReserveCancelAll { 'borrowers', $hold_borrowernumber } ); - C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $hold_borrowernumber, message_name => 'Hold_Manually_Cancelled' }); + + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ){ + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + } + } #step 2 launch the subroutine of the others reserves ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 182e02b3ee..8623e1b903 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -73,7 +73,14 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) { 'borrowers', $hold_borrowernumber } ); - C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $hold_borrowernumber, message_name => 'Hold_Manually_Cancelled' }); + + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ){ + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $hold_borrower->unblessed, 'email'); + } + } } } elsif ( $op =~ m|^mark_as_lost| ) { my $hold = Koha::Holds->find( $reserve_id ); @@ -152,7 +159,14 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) { 'borrowers', $hold_borrowernumber } ); - C4::Message->enqueue($letter, $patron->unblessed, 'email'); + + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $hold_borrowernumber, message_name => 'Hold_Manually_Cancelled' }); + + while ( my ( $transport, $letter_code ) = each %{ $messaging_preferences->{transports} } ){ + if ( $transport eq 'email' ){ + C4::Message->enqueue($letter, $patron->unblessed, 'email'); + } + } } elsif ( not $item ) { push @messages, { type => 'alert', code => 'hold_placed_at_biblio_level'}; } # else the url parameters have been modified and the user is not allowed to continue diff --git a/installer/data/mysql/atomicupdate/bug_20453-message_attributes.perl b/installer/data/mysql/atomicupdate/bug_20453-message_attributes.perl new file mode 100644 index 0000000000..3bb6282143 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_20453-message_attributes.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{INSERT IGNORE INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (7, 'Hold_Manually_Cancelled', 0) }); + + NewVersion( $DBversion, 20453, "Add Hold_Manually_Cancelled message attribute"); +} diff --git a/installer/data/mysql/atomicupdate/bug_20453-message_transports.perl b/installer/data/mysql/atomicupdate/bug_20453-message_transports.perl new file mode 100644 index 0000000000..52eac6ece9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_20453-message_transports.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{INSERT IGNORE INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code, branchcode) VALUES (7, "email", 0, "reserves", "HOLD_MANUAL_CANCEL", null) }); + + NewVersion( $DBversion, 20453, "Add HOLD_MANUAL_CANCEL message transport" ); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index 2f948c6236..91ee74fc18 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc @@ -20,6 +20,7 @@ [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout + [% ELSIF ( messaging_preference.Hold_Manually_Cancelled ) %]Hold manually cancelled [% ELSE %]Unknown [% END %] [% IF ( messaging_preference.takes_days ) %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index 3d3192fc6b..53b701cb9a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -61,6 +61,7 @@ [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout + [% ELSIF ( messaging_preference.Hold_Manually_Cancelled ) %]Hold manually cancelled [% ELSE %]Unknown [% END %] [% IF ( messaging_preference.takes_days ) %]