From e96315556b0043f4304b4cd8fb913d36f2ad4077 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Mar 2011 18:41:42 -0500 Subject: [PATCH] bug 5579: new routine to embed items in bib Adds a new routine, C4::Biblio::EmbedItemsInMarcBiblio, to embed the items in the bib record when necessary: * cataloging/additem.pl * rebuild_zebra.pl Signed-off-by: Galen Charlton Signed-off-by: Claire Hernandez Signed-off-by: Chris Cormack --- C4/Biblio.pm | 33 +++++++++++++++++++++++++++ cataloguing/additem.pl | 3 ++- misc/migration_tools/rebuild_zebra.pl | 24 +++++++++---------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ff4a24ed38..856a74e55e 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2,6 +2,7 @@ package C4::Biblio; # Copyright 2000-2002 Katipo Communications # Copyright 2010 BibLibre +# Copyright 2011 Equinox Software, Inc. # # This file is part of Koha. # @@ -35,6 +36,7 @@ use C4::ClassSource; use C4::Charset; require C4::Heading; require C4::Serials; +require C4::Items; use vars qw($VERSION @ISA @EXPORT); @@ -2632,6 +2634,37 @@ sub GetNoZebraIndexes { return %indexes; } +=head2 EmbedItemsInMarcBiblio + + EmbedItemsInMarcBiblio($marc, $biblionumber); + +Given a MARC::Record object containing a bib record, +modify it to include the items attached to it as 9XX +per the bib's MARC framework. + +=cut + +sub EmbedItemsInMarcBiblio { + my ($marc, $biblionumber) = @_; + + my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField('items.itemnumber', GetFrameworkCode($biblionumber)); + # delete any fields already in the record that use the item tag + foreach my $field ( $marc->field($itemtag) ) { + $marc->delete_field($field); + } + + # ... and embed the current items + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); + $sth->execute($biblionumber); + my @item_fields; + while (my ($itemnumber) = $sth->fetchrow_array) { + my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber); + push @item_fields, $item_marc->field($itemtag); + } + $marc->insert_fields_ordered(@item_fields); +} + =head1 INTERNAL FUNCTIONS =head2 _DelBiblioNoZebra($biblionumber,$record,$server); diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index e2dfc02fbd..43fb19f0fa 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -494,13 +494,14 @@ if ($op eq "additem") { # now, build existiing item list my $temp = GetMarcBiblio( $biblionumber ); -my @fields = $temp->fields(); #my @fields = $record->fields(); my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code my @big_array; #---- finds where items.itemnumber is stored my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode); my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode); +C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber); +my @fields = $temp->fields(); foreach my $field (@fields) { next if ( $field->tag() < 10 ); diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 74c73a1460..5be01cff63 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -320,26 +320,22 @@ sub export_marc_records_from_sth { ? GetXmlBiblio( $record_number ) : GetAuthorityXML( $record_number ); if ($record_type eq 'biblio'){ - #CALL sub ProcessItems - my @items=GetItemsInfo($record_number,'intra',30); + my @items = GetItemsInfo($record_number, 'intra'); if (@items){ - my $record=MARC::Record->new; + my $record = MARC::Record->new; my @itemsrecord; foreach my $item (@items){ - my $record=Item2Marc($item, $record_number); + my $record = Item2Marc($item, $record_number); push @itemsrecord, $record->field($itemtag); - #if xml then print itemfield as xml - # and update marcxml - # else push field } $record->insert_fields_ordered(@itemsrecord); my $itemsxml=$record->as_xml_record(); - my $searchstring='\n'; - my $index=index($itemsxml,'\n',0); - $itemsxml=substr($itemsxml,$index+length($searchstring)); - $searchstring=''; - $marcxml=substr($marcxml,0,index($marcxml,$searchstring)); - $marcxml.=$itemsxml; + my $searchstring = '\n'; + my $index = index($itemsxml, '\n', 0); + $itemsxml = substr($itemsxml, $index + length($searchstring)); + $searchstring = ''; + $marcxml = substr($marcxml, 0, index($marcxml, $searchstring)); + $marcxml .= $itemsxml; } } if ( $marcxml ) { @@ -469,6 +465,8 @@ sub get_raw_marc_record { return; } } + # ITEM + C4::Biblio::EmbedItemsInMarcBiblio($marc, $record_number); } else { eval { $marc = GetAuthority($record_number); }; if ($@) { -- 2.39.5