Bug 21478: Make Koha::Hold->suspend reject found holds
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 25 Jan 2019 16:49:37 +0000 (13:49 -0300)
committerLucas Gass <lucas@bywatersolutions.com>
Tue, 5 Feb 2019 23:19:12 +0000 (23:19 +0000)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 1d5934cae52dd96d9c5b8685a5f5531c69e92df8)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 81c6172ee224f7432ec809f8a9cd17f9c4971ecc)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Koha/Hold.pm

index 23d5d44..a1ef5aa 100644 (file)
@@ -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;