[PATCH 05/11] [SIGNED-OFF] bug 5579: new routine to embed items in bib
Galen Charlton
gmcharlt at gmail.com
Fri Mar 4 00:41:42 CET 2011
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 <gmc at esilibrary.com>
Signed-off-by: Claire Hernandez <claire.hernandez at biblibre.com>
---
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 d8add8b..4bbe794 100644
--- 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);
@@ -2564,6 +2566,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 b2b1192..2c312f5 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 74c73a1..5be01cf 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='<record>\n';
- my $index=index($itemsxml,'<record>\n',0);
- $itemsxml=substr($itemsxml,$index+length($searchstring));
- $searchstring='</record>';
- $marcxml=substr($marcxml,0,index($marcxml,$searchstring));
- $marcxml.=$itemsxml;
+ my $searchstring = '<record>\n';
+ my $index = index($itemsxml, '<record>\n', 0);
+ $itemsxml = substr($itemsxml, $index + length($searchstring));
+ $searchstring = '</record>';
+ $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 ($@) {
--
1.7.1
More information about the Koha-patches
mailing list