From 03fdc7defe0663e610cb5fa7568d96408a5b1429 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Thu, 25 Mar 2010 10:39:01 +0100 Subject: [PATCH] Better conformance for UNIMARC Authorities Encoding Adding support for UNIMARC Authorities UNIMARC encoding place of the encoding marker is different --- C4/AuthoritiesMarc.pm | 1 + C4/Charset.pm | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index ba71a8df4f..95e0655db1 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1056,6 +1056,7 @@ sub BuildUnimarcHierarchies{ } else { my $record = GetAuthority($authid); my $found; + return unless $record; foreach my $field ($record->field('5..')){ if ($field->subfield('5') && $field->subfield('5') eq 'g'){ my $subfauthid=_get_authid_subfield($field); diff --git a/C4/Charset.pm b/C4/Charset.pm index 839a9204de..f82d19143a 100644 --- a/C4/Charset.pm +++ b/C4/Charset.pm @@ -257,7 +257,7 @@ sub MarcToUTF8Record { } else { if ($marc_flavour eq 'MARC21') { return _default_marc21_charconv_to_utf8($marc_record, $marc_flavour); - } elsif ($marc_flavour eq 'UNIMARC') { + } elsif ($marc_flavour =~/UNIMARC/) { return _default_unimarc_charconv_to_utf8($marc_record, $marc_flavour); } else { return _default_marc21_charconv_to_utf8($marc_record, $marc_flavour); @@ -318,18 +318,27 @@ sub SetMarcUnicodeFlag { my $leader = $marc_record->leader(); substr($leader, 9, 1) = 'a'; $marc_record->leader($leader); - } elsif ($marc_flavour eq "UNIMARC") { - if (my $field = $marc_record->field('100')) { - my $sfa = $field->subfield('a'); - - my $subflength = 36; - # fix the length of the field - $sfa = substr $sfa, 0, $subflength if (length($sfa) > $subflength); - $sfa = sprintf( "%-*s", 35, $sfa ) if (length($sfa) < $subflength); - - substr($sfa, 26, 4) = '50 '; - $field->update('a' => $sfa); + } elsif ($marc_flavour =~/UNIMARC/) { + my $string; + my ($subflength,$encodingposition)=($marc_flavour=~/AUTH/?(21,9):(36,22)); + $string=$marc_record->subfield( 100, "a" ); + if (length($string)==$subflength) { + $string = substr $string, 0,$subflength if (length($string)>$subflength); + } + else { + $string = POSIX::strftime( "%Y%m%d", localtime ); + $string =~ s/\-//g; + $string = sprintf( "%-*s", $subflength, $string ); + } + substr( $string, $encodingposition, 8, "frey50 " ); + if ( $marc_record->subfield( 100, "a" ) ) { + $marc_record->field('100')->update(a=>$string); + } + else { + $marc_record->insert_grouped_field( + MARC::Field->new( 100, '', '', "a" => $string ) ); } + $debug && warn "encodage: ", substr( $marc_record->subfield(100, 'a'), $encodingposition, 8 ); } else { warn "Unrecognized marcflavour: $marc_flavour"; } -- 2.39.5