From 43b16a3ef391a9657b2da1bc8329eb4da7fd3b2e 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" preference to the name of the previously created template. 3) Edit (or create) a bibliographic record using either the simple or advanced MARC editor. 4) Save the record. 5) Verify that the action(s) have been applied. Sponsored-by: Gothenburg University Library Signed-off-by: Phil Ringnalda --- cataloguing/addbiblio.pl | 12 ++ ...lio-marc-modification-template-syspref.sql | 1 + installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/cataloguing.pref | 5 + svc/bib | 13 ++ ...BiblioMarcModificationTemplatePreference.t | 154 ++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_18138-edit-biblio-marc-modification-template-syspref.sql create mode 100644 t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 23a2fa45a3..34e0e640e0 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -44,6 +44,7 @@ use MARC::Record; use C4::ClassSource qw( GetClassSources ); use C4::ImportBatch qw( GetImportRecordMarc ); use C4::Charset qw( SetMarcUnicodeFlag ); +use C4::MarcModificationTemplates; use Koha::BiblioFrameworks; use Koha::DateUtils qw( dt_from_string ); @@ -58,6 +59,7 @@ use Koha::UI::Form::Builder::Biblio; use MARC::File::USMARC; use MARC::File::XML; use URI::Escape qw( uri_escape_utf8 ); +use List::MoreUtils qw(firstval); if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { MARC::File::XML->default_record_format('UNIMARC'); @@ -659,6 +661,16 @@ if ( $op eq "addbiblio" ) { # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate) if ( !$duplicatebiblionumber or $confirm_not_duplicate ) { my $oldbibitemnum; + my $marc_modification_template_name = C4::Context->preference("SaveBiblioMarcModificationTemplate"); + 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 ) { my $member = Koha::Patrons->find($loggedinuser); ModBiblio( 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..07bf6fce9a --- /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 ('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff client or HTTP API', 'Free'); diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index ce27c5f61a..6ef87b42ca 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -649,6 +649,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('RoutingListNote','To change this note edit RoutingListNote system preference.','70|10','Define a note to be shown on all routing lists','Textarea'), ('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'), ('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'), +('SaveBiblioMarcModificationTemplate', '', NULL, 'MARC modification template applied when saving bibliographic record in staff client or HTTP API', 'Free'), ('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'), ('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'), ('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded