From 2e366b7229924c606bba92349feeeb85d1db9778 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 13 Sep 2014 23:54:50 -0400 Subject: [PATCH] Add check for more copies in NCIP::ILS::Evergreen->delete_copy. We now check if there are other copies on the call number before we delete it. We also fix a thinko when we were checking for additional call numbers on the bib. We had map where we needed grep. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS/Evergreen.pm | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index a2f8005..08cd2c1 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -1333,30 +1333,34 @@ sub delete_copy { 'open-ils.pcrud.retrieve.acn', $self->{session}->{authtoken}, $copy->call_number(), - {flesh => 2, flesh_fields => {acn => ['record'], bre => ['call_numbers']}} + {flesh => 2, flesh_fields => {acn => ['record','copies'], bre => ['call_numbers']}} )->gather(1); if ($acn) { - # Get the bib and deflesh the acn. - my $bib = $acn->record(); - $acn->record($bib->id()); # Check if we own the call_number. if ($acn->owning_lib() == $ou_id) { - $r = $session->request( - 'open-ils.pcrud.delete.acn', - $self->{session}->{authtoken}, - $acn - )->gather(1); - if ($r) { - # Check if we created the bib. - if ($bib->creator() == $self->{session}->{user}->id()) { + # check for additional copies on the acn. + my @copies = grep {$_->id() != $copy->id() && !$U->is_true($_->deleted())} @{$acn->copies()}; + unless (@copies) { + # Get the bib + my $bib = $acn->record(); + $r = $session->request( + 'open-ils.pcrud.delete.acn', + $self->{session}->{authtoken}, + $acn + )->gather(1); + if ($r) { + # Check if we created the bib. + if ($bib->creator() == $self->{session}->{user}->id()) { # Check for other call numbers on the bib: - my @vols = map {$_->id() != $acn->id() && !$U->is_true($_->deleted())} @{$bib->call_numbers()}; - unless (@vols) { - $r = $session->request( - 'open-ils.pcrud.delete.bre', - $self->{session}->{authtoken}, - $bib - )->gather(1); + my @vols = grep {$_->id() != $acn->id() && !$U->is_true($_->deleted())} + @{$bib->call_numbers()}; + unless (@vols) { + $r = $session->request( + 'open-ils.pcrud.delete.bre', + $self->{session}->{authtoken}, + $bib + )->gather(1); + } } } } -- 2.43.2