From a0ad0ae6ced5250c540840b7a0dc737d4ea4baac 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. --- cataloguing/additem.pl | 55 +++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 5d8c0d0..e8e1bc4 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -643,41 +643,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