From 840bbc93341e9fa51fbb6c0777d7a4eb3b04a068 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Wed, 2 Apr 2025 11:29:45 +0000 Subject: [PATCH] Bug 35095: [POC] Bibliographic record created from local ERM title/KBart file contains only the title According to the manuals page for ERM (https://koha-community.org/manual/24.11/en/html/erm.html#create-a-new-local-title-record), a local bibliographic record with basic fields taken from ERM resource information (publication_title, print_identifier, online_identifier, date_first_issue_online, date_last_issue_online, num_first_vol_online, num_last_vol_online, title_url, first_author, coverage_depth, notes, publisher_name) could be created. However, it seems that a bibliographic record created either from a KBart file line, or from an ERM resource info entered by hand contains only the title (cf. Koha::ERM::EHoldings::Title->store). Attached is a POC how one could enrich the record. --- Koha/ERM/EHoldings/Title.pm | 73 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/Koha/ERM/EHoldings/Title.pm b/Koha/ERM/EHoldings/Title.pm index ea62ecb360..84970981e1 100644 --- a/Koha/ERM/EHoldings/Title.pm +++ b/Koha/ERM/EHoldings/Title.pm @@ -59,11 +59,14 @@ sub store { } else { # If it's not linked, we create a simple biblio and save the biblio id to the 'title' - my $marc_record = TransformKohaToMarc( + my $marc_record = + C4::Context->preference('marcflavour') eq 'MARC21' + ? $self->_make_simple_marc21_record + : TransformKohaToMarc( { 'biblio.title' => $self->publication_title, } - ); + ); my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '', { skip_record_index => 1 } ); $self->biblio_id($biblio_id); } @@ -102,6 +105,72 @@ sub resources { =head2 Internal methods + +=head3 _make_simple_marc21_record + +=cut + +sub _make_simple_marc21_record { + my $self = shift; + + my $marc_record = MARC::Record->new; + my @fields; + $marc_record->insert_fields_ordered( MARC::Field->new( '245', '0', '0', a => $self->publication_title ) ); + if ( $self->print_identifier ) { + my $standard_number = $self->print_identifier; + my $tag = $standard_number =~ s/\d/$&/g >= 10 ? '020' : '022'; + push @fields, + MARC::Field->new( $tag, ' ', ' ', a => $self->print_identifier ); + } + if ( $self->online_identifier ) { + my $standard_number = $self->print_identifier; + my $tag = $standard_number =~ s/\d/$&/g >= 10 ? '020' : '022'; + push @fields, + MARC::Field->new( $tag, ' ', ' ', a => $self->online_identifier ); + } + my $dates_online = ''; + if ( $self->date_first_issue_online ) { + $dates_online = $self->date_first_issue_online . '-'; + } + if ( $self->date_last_issue_online ) { + $dates_online .= '-' unless $dates_online; + $dates_online .= $self->date_last_issue_online; + } + if ($dates_online) { + push @fields, MARC::Field->new( '866', ' ', ' ', a => $dates_online ); + + } + my $volumes_online = ''; + if ( $self->num_first_vol_online ) { + $volumes_online = $self->num_first_vol_online . '-'; + } + if ( $self->num_last_vol_online ) { + $volumes_online .= '-' unless $volumes_online; + $volumes_online .= $self->num_last_vol_online; + } + if ($volumes_online) { + push @fields, MARC::Field->new( '863', ' ', ' ', a => $volumes_online ); + } + if ( $self->title_url ) { + push @fields, + MARC::Field->new( '856', '4', ' ', u => $self->title_url ); + } + if ( $self->first_author ) { + push @fields, + MARC::Field->new( '100', '1', ' ', a => $self->first_author ); + $marc_record->field('245')->set_indicator( '1', '1' ); + } + if ( $self->notes ) { + push @fields, MARC::Field->new( '852', ' ', ' ', z => $self->notes ); + } + if ( $self->publisher_name ) { + push @fields, + MARC::Field->new( '260', ' ', ' ', b => $self->publisher_name ); + } + $marc_record->insert_fields_ordered(@fields); + return $marc_record; +} + =head3 _type =cut -- 2.39.5