From d30bc545fb07a5f874e29ccfe157f2aa53ec8b7e 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 --- 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 138fceab44..41e93a4a0e 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 ); @@ -55,6 +56,7 @@ use Koha::BiblioFrameworks; 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'); @@ -858,6 +860,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 ) { 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..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 59db857ca6..5f7abdc0c2 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -586,6 +586,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'), ('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'), +('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