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);
}
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(),
my $output;
# Getting the record
- my $record = GetMarcBiblio($biblio);
+ my $record = GetMarcBiblio($biblio, 1);
next unless $record;
# Getting the framework
my $frameworkcode = GetFrameworkCode($biblio);
# 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('=', $_);
foreach (@marcfields) {
my $field = $_->{field};
+ # Remove any blank char that might have unintentionally insered into the tag name
+ $field =~ s/\s+//g;
# If we have a user-supplied header, we use it
if (exists $_->{header}) {