From 9a32fe85c27196de96770eea8f7a34bd24d706a6 Mon Sep 17 00:00:00 2001 From: Paul POULAIN Date: Tue, 14 Aug 2007 19:02:57 +0200 Subject: [PATCH] This commit fixes a bug in biblio encoding. things were mixed up when reporting item(s) into the biblio, to UPDATE biblioitems.marcxml, after a biblio modif (in MARC editor). So, deal carefully with this commit pls, and check it for your setups, because the patch works for me, but I'm not sure to understand well why :\ Signed-off-by: Chris Cormack --- C4/Biblio.pm | 57 +++++++++++++++++++++--------------------- cataloguing/additem.pl | 1 - 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 026e60a51b..5c69cd6816 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -20,7 +20,7 @@ package C4::Biblio; use strict; require Exporter; -use utf8; +# use utf8; use C4::Context; use MARC::Record; use MARC::File::USMARC; @@ -371,15 +371,24 @@ sub ModBiblio { # get the items before and append them to the biblio before updating the record, atm we just have the biblio my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode); my $oldRecord = GetMarcBiblio( $biblionumber ); - #$oldRecord->encoding('UTF-8'); - my @fields = $oldRecord->field( $itemtag ); - foreach (@fields){ - if ( !utf8::is_utf8( $_ ) ) { - utf8::decode( $_ ); - } + # parse each item, and, for an unknown reason, re-encode each subfield + # if you don't do that, the record will have encoding mixed + # and the biblio will be re-encoded. + # strange, I (Paul P.) searched more than 1 day to understand what happends + # but could only solve the problem this way... + my @fields = $oldRecord->field( $itemtag ); + foreach my $fielditem ( @fields ){ + my $field; + foreach ($fielditem->subfields()) { + if ($field) { + $field->add_subfields(Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1])); + } else { + $field = MARC::Field->new("$itemtag",'','',Encode::encode('utf-8',$_->[0]) => Encode::encode('utf-8',$_->[1])); + } + } + $record->append_fields($field); } - $record->append_fields( @fields ); # FIXME : encoding error... # adding biblionumber my ($tag_biblionumber, $subfield_biblionumber) = GetMarcFromKohaField('biblio.biblionumber',$frameworkcode); @@ -465,22 +474,6 @@ sub ModItemTransfer { return; } -##New sub to dotransfer in marc tables as well. Not exported -TG 10/04/2006 -# sub domarctransfer { -# my ( $dbh, $itemnumber ) = @_; -# $itemnumber =~ s /\'//g; ##itemnumber seems to come with quotes-TG -# my $sth = -# $dbh->prepare( -# "select biblionumber,holdingbranch from items where itemnumber=$itemnumber" -# ); -# $sth->execute(); -# while ( my ( $biblionumber, $holdingbranch ) = $sth->fetchrow ) { -# &ModItemInMarconefield( $biblionumber, $itemnumber, -# 'items.holdingbranch', $holdingbranch ); -# } -# return; -# } - =head2 ModBiblioframework ModBiblioframework($biblionumber,$frameworkcode); @@ -2233,11 +2226,17 @@ sub TransformHtmlToMarc { my $j=$i+1; if($tag < 10){ # no code for theses fields - my $inner_param = $params->[$j]; - $newfield = MARC::Field->new( - $tag, - $cgi->param($params->[$j+1]), - ); + # in MARC editor, 000 contains the leader. + if ($tag eq '000' ) { + $record->leader($cgi->param($params->[$j+1])) if length($cgi->param($params->[$j+1]))==24; + # between 001 and 009 (included) + } else { + $newfield = MARC::Field->new( + $tag, + $cgi->param($params->[$j+1]), + ); + } + # > 009, deal with subfields } else { while($params->[$j] =~ /_code_/){ # browse all it's subfield my $inner_param = $params->[$j]; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 64ba8af254..98ee702e68 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -68,7 +68,6 @@ my $frameworkcode = &GetFrameworkCode($biblionumber); my $tagslib = &GetMarcStructure(1,$frameworkcode); my $record = GetMarcBiblio($biblionumber); -warn "==>".$record->as_formatted; my $oldrecord = TransformMarcToKoha($dbh,$record); my $itemrecord; my $nextop="additem"; -- 2.20.1