From 12bcd6776f0b5619b6659c38ebf57a56ccb8badf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Mar 2017 13:04:01 -0300 Subject: [PATCH] Bug 18255: Replace GetBiblioItemByBiblioNumber with Koha::Biblio->biblioitem The subroutine GetBiblioItemByBiblioNumber considers that we have a 1-N relation between biblio and biblioitems, which is wrong (it's 1-1). So the calls can be replaced with Koha::biblio->biblioitem, it will ease the read of the code. Test plan: 1. Use the ILSDI service to display info of a bibliographic record, biblioitems fields must be displayed 2. Search for items, biblioitems info must be displayed as well in the result table --- C4/Biblio.pm | 24 ------------------------ C4/ILSDI/Services.pm | 9 ++++++--- catalogue/itemsearch.pl | 5 +++-- cataloguing/merge.pl | 2 -- serials/routing-preview.pl | 3 +-- 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 03d9a605fb..5ebbf40bb3 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -69,7 +69,6 @@ BEGIN { GetMarcBiblio GetBiblioItemData GetBiblioItemInfosOf - GetBiblioItemByBiblioNumber &GetRecordValue @@ -750,29 +749,6 @@ sub GetBiblioItemData { return ($data); } # sub &GetBiblioItemData -=head2 GetBiblioItemByBiblioNumber - -NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration. - -=cut - -sub GetBiblioItemByBiblioNumber { - my ($biblionumber) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?"); - my $count = 0; - my @results; - - $sth->execute($biblionumber); - - while ( my $data = $sth->fetchrow_hashref ) { - push @results, $data; - } - - $sth->finish; - return @results; -} - =head2 GetISBDView $isbd = &GetISBDView({ diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index a0aec9987d..61cfa83d45 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -208,9 +208,13 @@ sub GetRecords { foreach my $biblionumber ( split( / /, $cgi->param('id') ) ) { # Get the biblioitem from the biblionumber - my $biblioitem = ( GetBiblioItemByBiblioNumber( $biblionumber, undef ) )[0]; - if ( not $biblioitem->{'biblionumber'} ) { + my $biblio = Koha::Biblios->find( $biblionumber ); + my $biblioitem = $biblio->biblioitem; + if ( $biblioitem ) { + $biblioitem = $biblioitem->unblessed; + } else { $biblioitem->{code} = "RecordNotFound"; + # FIXME We should not need to process something else; next? } my $embed_items = 1; @@ -223,7 +227,6 @@ sub GetRecords { # Get most of the needed data my $biblioitemnumber = $biblioitem->{'biblioitemnumber'}; - my $biblio = Koha::Biblios->find( $biblionumber ); my $holds = $biblio->current_holds->unblessed; my $issues = GetBiblioIssues($biblionumber); my $items = GetItemsByBiblioitemnumber($biblioitemnumber); diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index 369142e1b1..517aa81935 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -233,8 +233,9 @@ if (scalar keys %params > 0) { } foreach my $item (@$results) { - $item->{biblio} = Koha::Biblios->find( $item->{biblionumber} ); - ($item->{biblioitem}) = GetBiblioItemByBiblioNumber($item->{biblionumber}); + my $biblio = Koha::Biblios->find( $item->{biblionumber} ); + $item->{biblio} = $biblio; + $item->{biblioitem} = $biblio->biblioitem->unblessed; $item->{status} = $notforloan_map->{$item->{notforloan}}; if (defined $item->{location}) { $item->{location} = $location_map->{$item->{location}}; diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index 45946716b9..e8b576a075 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -159,8 +159,6 @@ if ($merge) { # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio) my @allorders = GetOrdersByBiblionumber($biblionumber); - my @tobiblioitem = GetBiblioItemByBiblioNumber ($ref_biblionumber); - my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber }; foreach my $myorder (@allorders) { $myorder->{'biblionumber'} = $ref_biblionumber; ModOrder ($myorder); diff --git a/serials/routing-preview.pl b/serials/routing-preview.pl index 56b1a73b35..7cc3934c2b 100755 --- a/serials/routing-preview.pl +++ b/serials/routing-preview.pl @@ -67,7 +67,6 @@ my $library; if($ok){ # get biblio information.... my $biblionumber = $subs->{'bibnum'}; - my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblionumber); my @itemresults = GetItemsInfo( $biblionumber ); my $branch = @itemresults ? $itemresults[0]->{'holdingbranch'} : $subs->{branchcode}; $library = Koha::Libraries->find($branch); @@ -96,7 +95,7 @@ if($ok){ branchcode => $branch }); } else { - AddReserve($branch,$routing->{borrowernumber},$biblionumber,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title); + AddReserve($branch,$routing->{borrowernumber},$biblionumber,undef,$routing->{ranking}, undef, undef, $notes,$title); } } } -- 2.11.0