From 69701f20405f41f42ed244c01196162f31ea0b26 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 12 Mar 2017 22:56:19 -0300 Subject: [PATCH] Bug 18254: Remove call to GetItemsByBiblioitemnumber call from additem.pl The code from additem to delete all the items of a bibliographic record is very ackward. This patch simplifies the algorithm and make the code more readable. Test plan: Remove all the items of a bibliographic records If at least 1 item is checked out you should get an error. No change with the current behavior is expected. Signed-off-by: Alex Buckley --- cataloguing/additem.pl | 55 +++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 669fa4a..f49d254 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -644,41 +644,28 @@ if ($op eq "additem") { #------------------------------------------------------------------------------- } elsif ($op eq "delallitems") { #------------------------------------------------------------------------------- - my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber); - my $errortest=0; - my $itemfail; - foreach my $biblioitem (@biblioitems) { - my $items = &GetItemsByBiblioitemnumber( $biblioitem->{biblioitemnumber} ); - - foreach my $item (@$items) { - $error =&DelItemCheck( $biblionumber, $item->{itemnumber} ); - $itemfail =$item; - if($error == 1){ - next - } - else { - push @errors,$error; - $errortest++ - } - } - if($errortest > 0){ - $nextop="additem"; - } - else { - my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); - my $views = { C4::Search::enabled_staff_search_views }; - if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { - print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); - } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { - print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); - } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) { - print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); - } else { - print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid"); - } - exit; + my $itemnumbers = C4::Items::GetItemnumbersForBiblio( $biblionumber ); + foreach my $itemnumber ( @$itemnumbers ) { + $error = C4::Items::DelItemCheck( $biblionumber, $itemnumber ); + next if $error == 1; # Means ok + push @errors,$error; + } + if ( @errors ) { + $nextop="additem"; + } else { + my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); + my $views = { C4::Search::enabled_staff_search_views }; + if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { + print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); + } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { + print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); + } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) { + print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); + } else { + print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid"); } - } + exit; + } #------------------------------------------------------------------------------- } elsif ($op eq "saveitem") { #------------------------------------------------------------------------------- -- 2.1.4