From 81c6172ee224f7432ec809f8a9cd17f9c4971ecc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 25 Jan 2019 13:49:37 -0300 Subject: [PATCH] Bug 21478: Make Koha::Hold->suspend reject found holds Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens (cherry picked from commit 1d5934cae52dd96d9c5b8685a5f5531c69e92df8) Signed-off-by: Martin Renvoize --- Koha/Hold.pm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 23d5d447a5..a1ef5aafa5 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -34,6 +34,8 @@ use Koha::Libraries; use Koha::Old::Holds; use Koha::Calendar; +use Koha::Exceptions::Hold; + use base qw(Koha::Object); =head1 NAME @@ -85,16 +87,28 @@ sub suspend_hold { my $date = $dt ? $dt->clone()->truncate( to => 'day' )->datetime : undef; - if ( $self->is_waiting ) { # We can't suspend waiting holds - carp "Unable to suspend waiting hold!"; - return $self; + if ( $self->is_found ) { # We can't suspend found holds + if ( $self->is_waiting ) { + Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'W' ); + } + elsif ( $self->is_in_transit ) { + Koha::Exceptions::Hold::CannotSuspendFound->throw( status => 'T' ); + } + else { + Koha::Exceptions::Hold::CannotSuspendFound->throw( + 'Unhandled data exception on found hold (id=' + . $self->id + . ', found=' + . $self->found + . ')' ); + } } $self->suspend(1); - $self->suspend_until( $date ); + $self->suspend_until($date); $self->store(); - logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper($self->unblessed) ) + logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper( $self->unblessed ) ) if C4::Context->preference('HoldsLog'); return $self; -- 2.39.5