From 7cb075406e864461e98bffc0bf78b743f866f031 Mon Sep 17 00:00:00 2001 From: KohaR2 Date: Wed, 30 Jun 2021 11:47:59 +0200 Subject: [PATCH] Bug 28639 - Embed see-from headings (from authorities) into bibliographic records at OAI repository level --- C4/Biblio.pm | 72 +++++++++++++++++++--- Koha/OAI/Server/Repository.pm | 8 ++- installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/web_services.pref | 7 +++ 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 33e07223f8..c812d2ef9d 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -99,6 +99,7 @@ use Koha::Caches; use Koha::Authority::Types; use Koha::Acquisition::Currencies; use Koha::Biblio::Metadatas; +use Koha::MetadataRecord::Authority; use Koha::Holds; use Koha::ItemTypes; use Koha::Plugins; @@ -1150,16 +1151,18 @@ sub GetMarcSubfieldStructureFromKohaField { =head2 GetMarcBiblio my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => $embeditems, - opac => $opac, - borcat => $patron_category }); + biblionumber => $biblionumber, + embed_items => $embeditems, + embed_seefromheadings => $embedseefromheadings, + opac => $opac, + borcat => $patron_category }); Returns MARC::Record representing a biblio record, or C if the biblionumber doesn't exist. -Both embed_items and opac are optional. +embed_seefromheadings, embed_items and opac are optional. If embed_items is passed and is 1, items are embedded. +If embed_seefromheading is passed and is 1, see-from headings are embedded. If opac is passed and is 1, the record is filtered as needed. =over 4 @@ -1195,10 +1198,11 @@ sub GetMarcBiblio { return; } - my $biblionumber = $params->{biblionumber}; - my $embeditems = $params->{embed_items} || 0; - my $opac = $params->{opac} || 0; - my $borcat = $params->{borcat} // q{}; + my $biblionumber = $params->{biblionumber}; + my $embeditems = $params->{embed_items} || 0; + my $embedseefromheadings = $params->{embed_seefromheadings} || 0; + my $opac = $params->{opac} || 0; + my $borcat = $params->{borcat} // q{}; if (not defined $biblionumber) { carp 'GetMarcBiblio called with undefined biblionumber'; @@ -1232,6 +1236,9 @@ sub GetMarcBiblio { opac => $opac, borcat => $borcat }) if ($embeditems); + C4::Biblio::EmbedSeeFromHeadings({ + marc_record => $record }) + if ($embedseefromheadings); return $record; } @@ -2680,6 +2687,53 @@ sub EmbedItemsInMarcBiblio { $marc->append_fields(@item_fields); } +=head2 EmbedSeeFromHeadings + + EmbedSeeFromHeadings({ + marc_record => $record }); + +Given a MARC::Record object containing a bib record, +modify it to include see-from headings. + +=cut + +sub EmbedSeeFromHeadings { + my ($params) = @_; + my $record = $params->{marc_record}; + + my ($item_tag) = GetMarcFromKohaField("items.itemnumber", ''); + $item_tag ||= ''; + + foreach my $field ( $record->fields() ) { + next if $field->is_control_field(); + next if $field->tag() eq $item_tag; + my $authid = $field->subfield('9'); + + next unless $authid; + + my $authority = Koha::MetadataRecord::Authority->get_from_authid($authid); + next unless $authority; + my $auth_marc = $authority->record; + my @seefrom = $auth_marc->field('4..'); + my @newfields; + foreach my $authfield (@seefrom) { + my $tag = substr($field->tag(), 0, 1) . substr($authfield->tag(), 1, 2); + next if MARC::Field->is_controlfield_tag($tag); + my $newfield = MARC::Field->new($tag, + 'z', + $authfield->indicator(2) || ' ', + '9' => '1'); + foreach my $sub ($authfield->subfields()) { + my ($code,$val) = @$sub; + $newfield->add_subfields( $code => $val ); + } + $newfield->delete_subfield( code => '9' ); + push @newfields, $newfield if (scalar($newfield->subfields()) > 0); + } + $record->append_fields(@newfields); + } +} + =head1 INTERNAL FUNCTIONS =head2 _koha_marc_update_bib_ids diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm index ca34ee8d00..b9236fd6a5 100644 --- a/Koha/OAI/Server/Repository.pm +++ b/Koha/OAI/Server/Repository.pm @@ -171,10 +171,12 @@ sub get_biblio_marcxml { if ( my $conf = $self->{conf} ) { $with_items = $conf->{format}->{$format}->{include_items}; } + my $embedseefromheadings = C4::Context->preference('OAI-PMH:EmbedSeeFromInBibRecord') || 0; my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => $with_items, - opac => 1 }); + biblionumber => $biblionumber, + embed_items => $with_items, + embed_seefromheadings => $embedseefromheadings, + opac => 1 }); $record ? $record->as_xml_record() : undef; } diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 73f5372133..21157f1b13 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -371,6 +371,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OAI-PMH:AutoUpdateSetEmbedItemData', '0', '', 'Embed item information when automatically updating OAI sets. Requires OAI-PMH:AutoUpdateSets syspref to be enabled', 'YesNo'), ('OAI-PMH:ConfFile','',NULL,'If empty, Koha OAI Server operates in normal mode, otherwise it operates in extended mode.','File'), ('OAI-PMH:DeletedRecord','persistent','Koha\'s deletedbiblio table will never be deleted (persistent), might be deleted (transient), or will never have any data in it (no)','transient|persistent|no','Choice'), +('OAI-PMH:EmbedSeeFromInBibRecord','0','','Embed see-from headings in bibliographic records exposed through OAI repository.','YesNo'), ('OAI-PMH:MaxCount','50',NULL,'OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries','Integer'), ('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'), ('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref index d6a5e969bd..e5993c18ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref @@ -80,6 +80,13 @@ Web services: transient: might be emptied or truncated at some point (transient) no: will never have any data in it (no) - "." + - + - pref: "OAI-PMH:EmbedSeeFromInBibRecord" + default: 0 + choices: + yes: Embed + no: "Don't embed" + - "Embed see from (non-preferred form) headings in bibliographic records exposed through OAI repository." ILS-DI: - - pref: ILS-DI -- 2.11.0