From a8fa74e4be62344db5ebb2900199e2fe9485e177 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Mon, 20 Mar 2017 15:09:13 +0100 Subject: [PATCH] Bug 18138: Use MARC modification template when adding/updating bibliographic records Add a preference that enables a specific marc modification template to be applied on bibliographic records saved using simple or advanced MARC editor or the HTTP API. To test: 1) Create a MARC modification template containg one or more actions. 2) Under "Global system preferences" and "Cataloging" set the "EditBiblioMarcModificationTemplate" prefernce to the name of the previously created template. 3) Edit (or create) a bibliographic record using either simple or advanced MARC editor. 4) Save the record. 5) Verify that the action(s) have been applied. Sponsored-by: Gothenburg University Library --- cataloguing/addbiblio.pl | 14 +++++++++++++- ...8138-edit-biblio-marc-modification-template-syspref.sql | 1 + .../prog/en/modules/admin/preferences/cataloguing.pref | 5 +++++ svc/bib | 13 +++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.sql diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 54950a57de..43952513e7 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -34,6 +34,7 @@ use C4::Koha; use C4::ClassSource; use C4::ImportBatch; use C4::Charset; +use C4::MarcModificationTemplates; use Koha::BiblioFrameworks; use Koha::DateUtils; @@ -45,6 +46,7 @@ use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; use URI::Escape; +use List::MoreUtils qw(firstval); if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { MARC::File::XML->default_record_format('UNIMARC'); @@ -835,7 +837,17 @@ if ( $op eq "addbiblio" ) { my $oldbibitemnum; if (C4::Context->preference("BiblioAddsAuthorities")){ BiblioAutoLink( $record, $frameworkcode ); - } + } + my $marc_modification_template_name = C4::Context->preference("EditBiblioMarcModificationTemplate"); + if ($marc_modification_template_name) { + my $template = firstval { $_->{'name'} eq $marc_modification_template_name } GetModificationTemplates(); + if ($template) { + ModifyRecordWithTemplate($template->{'template_id'}, $record); + } + else { + warn "No MARC modification template exists with name \"$marc_modification_template_name\""; + } + } if ( $is_a_modif ) { ModBiblio( $record, $biblionumber, $frameworkcode ); } diff --git a/installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.sql b/installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.sql new file mode 100644 index 0000000000..0756e581b8 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES ('EditBiblioMarcModificationTemplate', '', '', 'MARC modification template applied when saving bibliographic record in staff client or HTTP API', 'Free'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref index 1aeadf9860..64c20589af 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref @@ -125,6 +125,11 @@ Cataloging: - 'MARC21: "952$a 952$b 952$c"' - Note that the FA framework is excluded from the permission. - If the pref is empty, no fields are restricted. + - + - Apply the MARC modification template with name + - pref: EditBiblioMarcModificationTemplate + class: short + - on records saved using the staff client simple MARC editor, advanced editor or HTTP API. Display: - - 'Separate multiple displayed authors, series or subjects with ' diff --git a/svc/bib b/svc/bib index 789951b5ea..361a652627 100755 --- a/svc/bib +++ b/svc/bib @@ -26,7 +26,9 @@ use CGI qw ( -utf8 ); use C4::Auth qw/check_api_auth/; use C4::Biblio; use C4::Items; +use C4::MarcModificationTemplates; use XML::Simple; +use List::MoreUtils qw(firstval); my $query = new CGI; binmode STDOUT, ':encoding(UTF-8)'; @@ -112,6 +114,17 @@ sub update_bib { } } + my $marc_modification_template_name = C4::Context->preference("EditBiblioMarcModificationTemplate"); + if ($marc_modification_template_name) { + my $template = firstval { $_->{'name'} eq $marc_modification_template_name } GetModificationTemplates(); + if ($template) { + ModifyRecordWithTemplate($template->{'template_id'}, $record); + } + else { + warn "No MARC modification template exists with name \"$marc_modification_template_name\""; + } + } + ModBiblio( $record, $biblionumber, '' ); my $new_record = GetMarcBiblio( $biblionumber, $query->url_param('items') ); -- 2.11.0