From 12b9d4cf2cae645acde0d090fb722e919a870536 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 9 Sep 2024 14:53:05 +0200 Subject: [PATCH] Bug 37868: Remove C4::Reserves::ToggleSuspend We can easily replace the calls by ->suspend_hold and ->resume. Test plan: No behaviour changes expected. Confirm that you can still suspend and resume holds (OPAC+staff) --- C4/Reserves.pm | 23 ------- .../prog/en/includes/holds_table.inc | 12 ++-- koha-tmpl/intranet-tmpl/prog/js/holds.js | 65 ++++++++++++------- opac/opac-modrequest-suspend.pl | 11 ++-- reserve/request.pl | 11 +++- t/db_dependent/Holds.t | 12 +--- 6 files changed, 66 insertions(+), 68 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index fa300799461..38e9bdb44c1 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -129,7 +129,6 @@ BEGIN { ToggleLowestPriority ReserveSlip - ToggleSuspend SuspendAll CalculatePriority @@ -1462,28 +1461,6 @@ sub ToggleLowestPriority { _FixPriority({ reserve_id => $reserve_id, rank => '999999' }); } -=head2 ToggleSuspend - - ToggleSuspend( $reserve_id ); - -This function sets the suspend field to true if is false, and false if it is true. -If the reserve is currently suspended with a suspend_until date, that date will -be cleared when it is unsuspended. - -=cut - -sub ToggleSuspend { - my ( $reserve_id, $suspend_until ) = @_; - - my $hold = Koha::Holds->find( $reserve_id ); - - if ( $hold->is_suspended ) { - $hold->resume() - } else { - $hold->suspend_hold( $suspend_until ); - } -} - =head2 SuspendAll SuspendAll( diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index 26edf3bf79c..dd99815cb2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -244,13 +244,15 @@ [% IF Koha.Preference('SuspendHoldsIntranet') %] [% UNLESS ( hold.found ) %] - + [% ELSE %] + + + [% END %] [% IF Koha.Preference('AutoResumeSuspendedHolds') %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index 71b1c4e1a96..d18d394787f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -445,37 +445,56 @@ $(document).ready(function() { }); }); - $(".toggle-suspend").on('click', function(e) { - e.preventDefault(); - let reserve_id = $(this).data('reserve-id'); - let biblionumber = $(this).data('biblionumber'); - let suspend_until = $('#suspend_until_' + reserve_id).val(); + function toggle_suspend(node, inputs) { + let reserve_id = $(node).data("reserve-id"); + let biblionumber = $(node).data("biblionumber"); let suspendForm = $("#hold-actions-form").attr({ - action: 'request.pl', - method: 'post' - }); - let sus_op = $("").attr({ - type: 'hidden', - name: 'op', - value: 'cud-toggleSuspend' + action: "request.pl", + method: "post", }); let sus_bn = $("").attr({ - type: 'hidden', - name: 'biblionumber', - value: biblionumber + type: "hidden", + name: "biblionumber", + value: biblionumber, }); let sus_ri = $("").attr({ - type: 'hidden', - name: 'reserve_id', + type: "hidden", + name: "reserve_id", value: reserve_id, }); - let sus_su = $("").attr({ - type: 'hidden', - name: 'suspend_until', - value: suspend_until - }); - suspendForm.append( sus_op, sus_bn, sus_ri, sus_su ); + inputs.push(sus_bn, sus_ri); + suspendForm.append(inputs); $("#hold-actions-form").submit(); return false; + } + $(".suspend-hold").on("click", function (e) { + e.preventDefault(); + let reserve_id = $(this).data("reserve-id"); + let suspend_until = $("#suspend_until_" + reserve_id).val(); + let inputs = [ + $("").attr({ + type: "hidden", + name: "op", + value: "cud-suspend", + }), + $("").attr({ + type: "hidden", + name: "suspend_until", + value: suspend_until, + }), + ]; + return toggle_suspend(this, inputs); + }); + $(".unsuspend-hold").on("click", function (e) { + e.preventDefault(); + let inputs = [ + $("").attr({ + type: "hidden", + name: "op", + value: "cud-unsuspend", + }), + ]; + return toggle_suspend(this, inputs); }); + }); diff --git a/opac/opac-modrequest-suspend.pl b/opac/opac-modrequest-suspend.pl index d004baba132..eeff53182d5 100755 --- a/opac/opac-modrequest-suspend.pl +++ b/opac/opac-modrequest-suspend.pl @@ -19,7 +19,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Output; -use C4::Reserves qw( ToggleSuspend SuspendAll ); +use C4::Reserves qw( SuspendAll ); use C4::Auth qw( get_template_and_user ); use Koha::Patrons; @@ -38,11 +38,14 @@ my $suspend = $query->param('suspend'); my $suspend_until = $query->param('suspend_until') || undef; my $reserve_id = $query->param('reserve_id'); -if ( ( $op eq 'cud-suspend' || $op eq 'cud-unsuspend' ) && $reserve_id ) { +if ( $op eq 'cud-suspend' ) { my $patron = Koha::Patrons->find($borrowernumber); my $hold = $patron->holds->find($reserve_id); - ToggleSuspend( $reserve_id, $suspend_until ) - if $hold && $hold->is_cancelable_from_opac; + $hold->suspend_hold($suspend_until) if $hold && $hold->is_cancelable_from_opac; +} elsif ( $op eq 'cud-unsuspend' ) { + my $patron = Koha::Patrons->find($borrowernumber); + my $hold = $patron->holds->find($reserve_id); + $hold->resume if $hold && $hold->is_cancelable_from_opac; } elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) { SuspendAll( diff --git a/reserve/request.pl b/reserve/request.pl index 5d0887764d0..b19fa3b868b 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -33,7 +33,7 @@ use List::MoreUtils qw( uniq ); use Date::Calc qw( Date_to_Days ); use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); -use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest ); +use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority CanBookBeReserved GetMaxPatronHoldsForRecord CanItemBeReserved IsAvailableForItemLevelRequest ); use C4::Items qw( get_hostitemnumbers_of ); use C4::Koha qw( getitemtypeimagelocation ); use C4::Serials qw( CountSubscriptionFromBiblionumber ); @@ -120,10 +120,15 @@ elsif ( $op eq 'cud-setLowestPriority' ) { my $reserve_id = $input->param('reserve_id'); ToggleLowestPriority($reserve_id); } -elsif ( $op eq 'cud-toggleSuspend' ) { +elsif ( $op eq 'cud-suspend' ) { my $reserve_id = $input->param('reserve_id'); my $suspend_until = $input->param('suspend_until'); - ToggleSuspend( $reserve_id, $suspend_until ); + my $hold = Koha::Holds->find($reserve_id); + $hold->suspend_hold($suspend_until) if $hold; +} elsif ( $op eq 'cud-unsuspend' ) { + my $reserve_id = $input->param('reserve_id'); + my $hold = Koha::Holds->find($reserve_id); + $hold->resume() if $hold; } elsif ( $op eq 'cud-cancel_bulk' ) { my $cancellation_reason = $input->param("cancellation-reason"); diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 4c78b4c480b..b899c10ad18 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 74; +use Test::More tests => 72; use Test::Exception; use MARC::Record; @@ -15,7 +15,7 @@ use MARC::Record; use C4::Biblio; use C4::Calendar; use C4::Items; -use C4::Reserves qw( AddReserve CalculatePriority ModReserve ToggleSuspend AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve ); +use C4::Reserves qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve ); use C4::Circulation qw( CanBookBeRenewed ); use Koha::Biblios; @@ -160,14 +160,6 @@ ModReserve({ # call without reserve_id $hold = Koha::Holds->find( $reserve_id ); ok( $hold->priority eq '3', "Test ModReserve, priority changed correctly" ); -ToggleSuspend( $reserve_id ); -$hold = Koha::Holds->find( $reserve_id ); -ok( ! $hold->suspend, "Test ToggleSuspend(), no date" ); - -ToggleSuspend( $reserve_id, '2012-01-01' ); -$hold = Koha::Holds->find( $reserve_id ); -is( $hold->suspend_until, '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" ); - AutoUnsuspendReserves(); $hold = Koha::Holds->find( $reserve_id ); ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" ); -- 2.34.1