From 65d5ad70b65189177622c4886f2718a0130cdbae Mon Sep 17 00:00:00 2001 From: Mason James Date: Wed, 20 Sep 2017 12:57:52 +1200 Subject: [PATCH] Bug 18927: Use fully qualified subroutine names in C4::Items rebuild_zebra.pl fails in some conditions (perl version?) I do not recreate but it has been reported that reindex fails with: error retrieving biblio 94540 at /usr/share/koha/bin/migration_tools/rebuild_zebra.pl line 683, line 751. To fix it we can use fully qualified subroutine names for: GetMarcFromKohaField GetMarcBiblio GetBiblionumberFromItemnumber TransformKohaToMarc GetFrameworkCode Test plan: Confirm the rebuild_zebra script still works correctly after this patch Signed-off-by: Lee Jamison Signed-off-by: Marcel de Rooy --- C4/Items.pm | 38 ++++++++++++++++----------- misc/migration_tools/rebuild_zebra.pl | 10 ++++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index a313257964..0f0465e2af 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -248,8 +248,10 @@ sub AddItemFromMarc { my $dbh = C4::Context->dbh; # parse item hash from MARC - my $frameworkcode = GetFrameworkCode( $biblionumber ); - my ($itemtag,$itemsubfield)=GetMarcFromKohaField("items.itemnumber",$frameworkcode); + my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); + my ($itemtag,$itemsubfield)=C4::Biblio::GetMarcFromKohaField("items.itemnumber",$frameworkcode); + + my $localitemmarc=MARC::Record->new; $localitemmarc->append_fields($source_item_marc->field($itemtag)); @@ -284,7 +286,8 @@ sub AddItem { my $biblionumber = shift; my $dbh = @_ ? shift : C4::Context->dbh; - my $frameworkcode = @_ ? shift : GetFrameworkCode($biblionumber); + my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode($biblionumber); + my $unlinked_item_subfields; if (@_) { $unlinked_item_subfields = shift; @@ -377,7 +380,8 @@ sub AddItemBatchFromMarc { $record = $record->clone(); # loop through the item tags and start creating items my @bad_item_fields = (); - my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",''); + my ($itemtag, $itemsubfield) = C4::Biblio::GetMarcFromKohaField("items.itemnumber",''); + my $item_sequence_num = 0; ITEMFIELD: foreach my $item_field ($record->field($itemtag)) { $item_sequence_num++; @@ -512,8 +516,8 @@ sub ModItemFromMarc { my $itemnumber = shift; my $dbh = C4::Context->dbh; - my $frameworkcode = GetFrameworkCode($biblionumber); - my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); + my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); + my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); my $localitemmarc = MARC::Record->new; $localitemmarc->append_fields( $item_marc->field($itemtag) ); @@ -565,7 +569,8 @@ sub ModItem { } my $dbh = @_ ? shift : C4::Context->dbh; - my $frameworkcode = @_ ? shift : GetFrameworkCode( $biblionumber ); + my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode( $biblionumber ); + my $unlinked_item_subfields; if (@_) { @@ -688,7 +693,7 @@ sub DelItem { my $deleted = _koha_delete_item( $itemnumber ); # get the MARC record - my $record = GetMarcBiblio($biblionumber); + my $record = C4::Biblio::GetMarcBiblio($biblionumber); ModZebra( $biblionumber, "specialUpdate", "biblioserver" ); #search item field code @@ -1645,7 +1650,8 @@ references on array of itemnumbers. sub get_hostitemnumbers_of { my ($biblionumber) = @_; - my $marcrecord = GetMarcBiblio($biblionumber); + my $marcrecord = C4::Biblio::GetMarcBiblio($biblionumber); + my (@returnhostitemnumbers,$tag, $biblio_s, $item_s); my $marcflavor = C4::Context->preference('marcflavour'); @@ -1820,8 +1826,9 @@ sub Item2Marc { defined($itemrecord->{$_}) && $itemrecord->{$_} ne '' ? ("items.$_" => $itemrecord->{$_}) : () } keys %{ $itemrecord } }; - my $itemmarc = TransformKohaToMarc($mungeditem); - my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",GetFrameworkCode($biblionumber)||''); + + my $itemmarc = C4::Biblio::TransformKohaToMarc($mungeditem); + my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber",C4::Biblio::GetFrameworkCode($biblionumber)||''); my $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($mungeditem->{'items.more_subfields_xml'}); if (defined $unlinked_item_subfields and $#$unlinked_item_subfields > -1) { @@ -2413,7 +2420,7 @@ sub _marc_from_item_hash { my $item_marc = MARC::Record->new(); foreach my $item_field ( keys %{$mungeditem} ) { - my ( $tag, $subfield ) = GetMarcFromKohaField( $item_field, $frameworkcode ); + my ( $tag, $subfield ) = C4::Biblio::GetMarcFromKohaField( $item_field, $frameworkcode ); next unless defined $tag and defined $subfield; # skip if not mapped to MARC field my @values = split(/\s?\|\s?/, $mungeditem->{$item_field}, -1); foreach my $value (@values){ @@ -2648,7 +2655,8 @@ sub _SearchItems_build_where_fragment { # items.more_subfields_xml, depending on the MARC field. my $xpath; my $sqlfield; - my ($itemfield) = GetMarcFromKohaField('items.itemnumber'); + my ($itemfield) = C4::Biblio::GetMarcFromKohaField('items.itemnumber'); + if ($marcfield eq $itemfield) { $sqlfield = 'more_subfields_xml'; $xpath = '//record/datafield/subfield[@code="' . $marcsubfield . '"]'; @@ -2850,8 +2858,8 @@ sub PrepareItemrecordDisplay { my ( $bibnum, $itemnum, $defaultvalues, $frameworkcode ) = @_; my $dbh = C4::Context->dbh; - $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum; - my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); + $frameworkcode = C4::Biblio::GetFrameworkCode($bibnum) if $bibnum; + my ( $itemtagfield, $itemtagsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); my $tagslib = &GetMarcStructure( 1, $frameworkcode ); # return nothing if we don't have found an existing framework. diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index b32f8ba6ad..040f45c135 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -175,8 +175,8 @@ my $kohadir = C4::Context->config('intranetdir'); my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') // 'dom'; my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') // 'dom'; -my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber",""); -my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber",""); +my ($biblionumbertagfield,$biblionumbertagsubfield) = C4::Biblio::GetMarcFromKohaField("biblio.biblionumber",""); +my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = C4::Biblio::GetMarcFromKohaField("biblioitems.biblioitemnumber",""); my $marcxml_open = q{ @@ -498,7 +498,8 @@ sub export_marc_records_from_sth { unless $as_usmarc; my $i = 0; - my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",''); + my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber",''); + while (my ($record_number) = $sth->fetchrow_array) { print "." if ( $verbose_logging ); print "\r$i" unless ($i++ %100 or !$verbose_logging); @@ -705,7 +706,8 @@ sub get_raw_marc_record { $fetch_sth->finish(); return unless $marc; } else { - eval { $marc = GetMarcBiblio($record_number, 1); }; + eval { $marc = C4::Biblio::GetMarcBiblio($record_number, 1); }; + if ($@ || !$marc) { # here we do warn since catching an exception # means that the bib was found but failed -- 2.39.5