Bugzilla – Attachment 171501 Details for
Bug 37868
Remove C4::Reserves::ToggleSuspend
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37868: Remove C4::Reserves::ToggleSuspend
Bug-37868-Remove-C4ReservesToggleSuspend.patch (text/plain), 10.67 KB, created by
Olivier Vezina
on 2024-09-13 20:15:52 UTC
(
hide
)
Description:
Bug 37868: Remove C4::Reserves::ToggleSuspend
Filename:
MIME Type:
Creator:
Olivier Vezina
Created:
2024-09-13 20:15:52 UTC
Size:
10.67 KB
patch
obsolete
>From a15f385083bbf5b3463e6c959691031e90bb0a84 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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) > >Signed-off-by: Olivier V <olivier.vezina@inLibro.com> >--- > 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 fa30079946..38e9bdb44c 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 26edf3bf79..dd99815cb2 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 @@ > <td> > [% IF Koha.Preference('SuspendHoldsIntranet') %] > [% UNLESS ( hold.found ) %] >- <button class="btn btn-default btn-xs toggle-suspend" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]"> >- [% IF ( hold.suspend ) %] >+ [% IF ( hold.suspend ) %] >+ <button class="btn btn-default btn-xs unsuspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]"> > <i class="fa fa-play" aria-hidden="true"></i> Unsuspend >- [% ELSE %] >+ </button> >+ [% ELSE %] >+ <button class="btn btn-default btn-xs suspend-hold" data-reserve-id="[% hold.reserve_id | html %]" data-biblionumber="[% hold.biblionumber | html %]"> > <i class="fa fa-pause" aria-hidden="true"></i> Suspend >- [% END %] >- </button> >+ </button> >+ [% END %] > > [% IF Koha.Preference('AutoResumeSuspendedHolds') %] > <label for="suspend_until_[% hold.reserve_id | html %]">[% IF ( hold.suspend ) %] on [% ELSE %] until [% END %]</label> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index 71b1c4e1a9..d18d394787 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 = $("<input />").attr({ >- type: 'hidden', >- name: 'op', >- value: 'cud-toggleSuspend' >+ action: "request.pl", >+ method: "post", > }); > let sus_bn = $("<input />").attr({ >- type: 'hidden', >- name: 'biblionumber', >- value: biblionumber >+ type: "hidden", >+ name: "biblionumber", >+ value: biblionumber, > }); > let sus_ri = $("<input />").attr({ >- type: 'hidden', >- name: 'reserve_id', >+ type: "hidden", >+ name: "reserve_id", > value: reserve_id, > }); >- let sus_su = $("<input />").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 = [ >+ $("<input />").attr({ >+ type: "hidden", >+ name: "op", >+ value: "cud-suspend", >+ }), >+ $("<input />").attr({ >+ type: "hidden", >+ name: "suspend_until", >+ value: suspend_until, >+ }), >+ ]; >+ return toggle_suspend(this, inputs); >+ }); >+ $(".unsuspend-hold").on("click", function (e) { >+ e.preventDefault(); >+ let inputs = [ >+ $("<input />").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 d004baba13..eeff53182d 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 5d0887764d..b19fa3b868 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 4c78b4c480..b899c10ad1 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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37868
:
171196
|
171501
|
172275