From a91aa9c23625cd4039d520dff2296af6b78bb70e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Mar 2017 12:28:13 -0300 Subject: [PATCH] [SIGNED-OFF] Bug 18277: Remove GetBiblionumberFromItemnumber - Easy ones To retrieve a biblionumber from an itemnumber, we can use: Koha::Item->biblio->biblionumber This is only what this patchset does. Doing that we will be able to get rid of the C4::Biblio::GetBiblionumberFromItemnumber subroutine. Test plan: - Acquisition module: cancel a receipt - Export a record to CSV - Modify items in a batch Item's info should be correct Other changes with be checked by QA team, by reading the code. Signed-off-by: Josef Moravec --- C4/Acquisition.pm | 13 +++++++------ C4/Items.pm | 3 ++- C4/Record.pm | 4 +++- Koha/REST/V1/Hold.pm | 13 +++++++------ cataloguing/additem.pl | 4 +++- opac/opac-reserve.pl | 3 ++- tools/batchMod.pl | 6 +++++- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 2bb97a9..62c7384 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -31,6 +31,7 @@ use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Acquisition::Order; use Koha::Acquisition::Booksellers; use Koha::Biblios; +use Koha::Items; use Koha::Number::Price; use Koha::Libraries; @@ -1606,17 +1607,17 @@ sub CancelReceipt { my @affects = split q{\|}, C4::Context->preference("AcqItemSetSubfieldsWhenReceiptIsCancelled"); if ( @affects ) { for my $in ( @itemnumbers ) { - my $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber( $in ); - my $frameworkcode = GetFrameworkCode($biblionumber); - my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $frameworkcode ); - my $item = C4::Items::GetMarcItem( $biblionumber, $in ); + my $item = Koha::Items->find( $in ); + my $biblio = $item->biblio; + my ( $itemfield ) = GetMarcFromKohaField( 'items.itemnumber', $biblio->frameworkcode ); + my $item_marc = C4::Items::GetMarcItem( $biblio->biblionumber, $in ); for my $affect ( @affects ) { my ( $sf, $v ) = split q{=}, $affect, 2; - foreach ( $item->field($itemfield) ) { + foreach ( $item_marc->field($itemfield) ) { $_->update( $sf => $v ); } } - C4::Items::ModItemFromMarc( $item, $biblionumber, $in ); + C4::Items::ModItemFromMarc( $item_marc, $biblio->biblionumber, $in ); } } } diff --git a/C4/Items.pm b/C4/Items.pm index 6378249..c3fd04f 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -669,7 +669,8 @@ sub DelItem { my $biblionumber = $params->{biblionumber}; unless ($biblionumber) { - $biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); + my $item = Koha::Items->find( $itemnumber ); + $biblionumber = $item->biblio->biblionumber; } # If there is no biblionumber for the given itemnumber, there is nothing to delete diff --git a/C4/Record.pm b/C4/Record.pm index abc0075..e36e035 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -34,6 +34,7 @@ use C4::XSLT (); use YAML; #marcrecords2csv use Template; use Text::CSV::Encoded; #marc2csv +use Koha::Items; use Koha::SimpleMARC qw(read_field); use Koha::XSLT_Handler; use Koha::CsvProfiles; @@ -427,7 +428,8 @@ sub marc2csv { my $firstpass = 1; if ( @$itemnumbers ) { for my $itemnumber ( @$itemnumbers) { - my $biblionumber = GetBiblionumberFromItemnumber $itemnumber; + my $item = Koha::Items->find( $itemnumber ); + my $biblionumber = $item->biblio->biblionumber; $output .= marcrecord2csv( $biblionumber, $id, $firstpass, $csv, $fieldprocessing, [$itemnumber] ); $firstpass = 0; } diff --git a/Koha/REST/V1/Hold.pm b/Koha/REST/V1/Hold.pm index d72e5df..f876b0a 100644 --- a/Koha/REST/V1/Hold.pm +++ b/Koha/REST/V1/Hold.pm @@ -22,6 +22,7 @@ use Mojo::Base 'Mojolicious::Controller'; use C4::Biblio; use C4::Reserves; +use Koha::Items; use Koha::Patrons; use Koha::Holds; use Koha::DateUtils; @@ -65,18 +66,18 @@ sub add { }, 400); } + my $biblio; if ($itemnumber) { - my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber); - if ($biblionumber and $biblionumber != $item_biblionumber) { + my $item = Koha::Items->find( $itemnumber ); + $biblio = $item->biblio; + if ($biblionumber and $biblionumber != $biblio->biblionumber) { return $c->$cb({ error => "Item $itemnumber doesn't belong to biblio $biblionumber" }, 400); } - $biblionumber ||= $item_biblionumber; + $biblionumber ||= $biblio->biblionumber; } - my $biblio = C4::Biblio::GetBiblio($biblionumber); - my $can_reserve = $itemnumber ? CanItemBeReserved( $borrowernumber, $itemnumber ) @@ -98,7 +99,7 @@ sub add { my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber, $biblionumber, undef, $priority, undef, $expirationdate, undef, - $biblio->{title}, $itemnumber); + $biblio->title, $itemnumber); unless ($reserve_id) { return $c->$cb({ diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 1ee8d82..35c753d 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -31,6 +31,7 @@ use C4::Circulation; use C4::Koha; use C4::ClassSource; use Koha::DateUtils; +use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; use List::MoreUtils qw/any/; @@ -807,9 +808,10 @@ foreach my $field (@fields) { if ( C4::Context->preference('EasyAnalyticalRecords') ) { foreach my $hostitemnumber (@hostitemnumbers){ + my $item = Koha::Items->find( $hostitemnumber ); if ($this_row{itemnumber} eq $hostitemnumber){ $this_row{hostitemflag} = 1; - $this_row{hostbiblionumber}= GetBiblionumberFromItemnumber($hostitemnumber); + $this_row{hostbiblionumber}= $item->biblio->biblionumber; last; } } diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 7de7b97..f728475 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -244,7 +244,8 @@ if ( $query->param('place_reserve') ) { #item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber if ( $itemNum ne '' ) { - my $hostbiblioNum = GetBiblionumberFromItemnumber($itemNum); + my $item = Koha::Items->find( $itemNum ); + my $hostbiblioNum = $item->biblio->biblionumber; if ( $hostbiblioNum ne $biblioNum ) { $biblioNum = $hostbiblioNum; } diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 1dc2174..7c87c7f 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -37,6 +37,7 @@ use List::MoreUtils qw/uniq/; use Koha::Biblios; use Koha::DateUtils; +use Koha::Items; use Koha::ItemTypes; my $input = new CGI; @@ -121,7 +122,10 @@ if ($op eq "action") { $items_display_hashref=BuildItemsData(@itemnumbers); } else { # Else, we only display the barcode - my @simple_items_display = map {{ itemnumber => $_, barcode => (GetBarcodeFromItemnumber($_) or ""), biblionumber => (GetBiblionumberFromItemnumber($_) or "") }} @itemnumbers; + my @simple_items_display = map { + my $itemnumber = $_; + my $item = Koha::Items->find($itemnumber); + { itemnumber => $itemnumber, barcode => ($item->barcode || q||), biblionumber => $item->biblio->biblionumber }} @itemnumbers; $template->param("simple_items_display" => \@simple_items_display); } -- 2.1.4