From 1a50b447d3d58b40d8f84e7c264f01abcb42a826 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 4 Sep 2017 12:06:56 -0300 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 Signed-off-by: Jonathan Druart (cherry picked from commit 2671eb2f93340e8fb3c794cff918d86c526cc47f) --- C4/Items.pm | 30 +++++++++++++-------------- misc/migration_tools/rebuild_zebra.pl | 8 +++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 6c2757078d..5a7a56756f 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -238,8 +238,8 @@ 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)); @@ -274,7 +274,7 @@ 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; @@ -367,7 +367,7 @@ 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++; @@ -502,8 +502,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) ); @@ -555,7 +555,7 @@ 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 (@_) { @@ -1441,7 +1441,7 @@ references on array of itemnumbers. sub get_hostitemnumbers_of { my ($biblionumber) = @_; - my $marcrecord = GetMarcBiblio($biblionumber); + my $marcrecord = C4::Biblio::GetMarcBiblio($biblionumber); return unless $marcrecord; @@ -1608,7 +1608,7 @@ sub GetMarcItem { my $itemrecord = GetItem($itemnumber); - # Tack on 'items.' prefix to column names so that TransformKohaToMarc will work. + # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work. # Also, don't emit a subfield if the underlying field is blank. @@ -1622,8 +1622,8 @@ 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) { @@ -2249,7 +2249,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){ @@ -2463,7 +2463,7 @@ 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 . '"]'; @@ -2670,8 +2670,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 ); # Note: $tagslib obtained from GetMarcStructure() in 'unsafe' mode is # a shared data structure. No plugin (including custom ones) should change diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 28ce27ccdf..2c620cfa81 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -172,8 +172,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{ @@ -497,7 +497,7 @@ sub export_marc_records_from_sth { print {$fh} $marcxml_open; 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); @@ -675,7 +675,7 @@ sub get_raw_marc_record { my $marc; if ($record_type eq 'biblio') { - 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