X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FRecord.pm;h=89bde3227f04f003f4615ce0941eba49b174b07a;hb=1d62ea2c9ff7edc0bc1e202b8f5591939ee5735f;hp=c5727f3c03689276e2acf86ad7b9ad4df3d7e659;hpb=700249eb3cbf765a5a731effd21ba543b74eb334;p=koha.git diff --git a/C4/Record.pm b/C4/Record.pm index c5727f3c03..89bde3227f 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -77,7 +77,32 @@ Returns an ISO-2709 scalar sub marc2marc { my ($marc,$to_flavour,$from_flavour,$encoding) = @_; - my $error = "Feature not yet implemented\n"; + my $error; + if ($to_flavour =~ m/marcstd/) { + my $marc_record_obj; + if ($marc =~ /^MARC::Record/) { # it's already a MARC::Record object + $marc_record_obj = $marc; + } else { # it's not a MARC::Record object, make it one + eval { $marc_record_obj = MARC::Record->new_from_usmarc($marc) }; # handle exceptions + +# conversion to MARC::Record object failed, populate $error + if ($@) { $error .="\nCreation of MARC::Record object failed: ".$MARC::File::ERROR }; + } + unless ($error) { + my @privatefields; + foreach my $field ($marc_record_obj->fields()) { + if ($field->tag() =~ m/9/ && ($field->tag() != '490' || C4::Context->preference("marcflavour") eq 'UNIMARC')) { + push @privatefields, $field; + } elsif (! ($field->is_control_field())) { + $field->delete_subfield(code => '9') if ($field->subfield('9')); + } + } + $marc_record_obj->delete_field($_) for @privatefields; + $marc = $marc_record_obj->as_usmarc(); + } + } else { + $error = "Feature not yet implemented\n"; + } return ($error,$marc); } @@ -266,12 +291,19 @@ sub marc2modsxml { sub marc2endnote { my ($marc) = @_; my $marc_rec_obj = MARC::Record->new_from_usmarc($marc); - my $f260 = $marc_rec_obj->field('260'); - my $f260a = $f260->subfield('a') if $f260; + my ( $abstract, $f260a, $f710a ); + my $f260 = $marc_rec_obj->field('260'); + if ($f260) { + $f260a = $f260->subfield('a') if $f260; + } my $f710 = $marc_rec_obj->field('710'); - my $f710a = $f710->subfield('a') if $f710; - my $f500 = $marc_rec_obj->field('500'); - my $abstract = $f500->subfield('a') if $f500; + if ($f710) { + $f710a = $f710->subfield('a'); + } + my $f500 = $marc_rec_obj->field('500'); + if ($f500) { + $abstract = $f500->subfield('a'); + } my $fields = { DB => C4::Context->preference("LibraryName"), Title => $marc_rec_obj->title(), @@ -391,7 +423,7 @@ sub marcrecord2csv { # Getting the marcfields as an array my @marcfieldsarray = split('\|', $marcfieldslist); - # Separating the marcfields from the the user-supplied headers + # Separating the marcfields from the user-supplied headers my @marcfields; foreach (@marcfieldsarray) { my @result = split('=', $_);