Bugzilla – Attachment 158414 Details for
Bug 18138
Use MARC modification template when adding/updating bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18138: Use MARC modification template when adding/updating bibliographic records
Bug-18138-Use-MARC-modification-template-when-addi.patch (text/plain), 13.75 KB, created by
Katrin Fischer
on 2023-11-05 00:30:46 UTC
(
hide
)
Description:
Bug 18138: Use MARC modification template when adding/updating bibliographic records
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-11-05 00:30:46 UTC
Size:
13.75 KB
patch
obsolete
>From 67286486cca60e34f2ad3f555af14509e4d64d0d Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >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 <phil@chetcolibrary.org> >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > 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 a11711afd3..8912610657 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'); >@@ -665,6 +667,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 50ab4e1521..6e7cd55f0c 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -652,6 +652,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> 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 <style> tag.','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 5a6346ed46..653bb37fff 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 >@@ -217,6 +217,11 @@ Cataloging: > 1: Strip > 0: "Don't strip" > - leading and trailing whitespace characters (including spaces, tabs, line breaks and carriage returns) and inner newlines from data fields when cataloguing bibliographic and authority records. The leader and control fields will not be affected. >+ - >+ - Apply the MARC modification template with name >+ - pref: SaveBiblioMarcModificationTemplate >+ class: short >+ - on records saved using the staff client simple MARC editor, advanced editor or HTTP API. > Display: > - > - 'Separate main entry and subdivisions with ' >diff --git a/svc/bib b/svc/bib >index 0667c0de4b..8a281da04f 100755 >--- a/svc/bib >+++ b/svc/bib >@@ -25,8 +25,10 @@ use CGI qw ( -utf8 ); > use C4::Auth qw( check_api_auth ); > use C4::Biblio qw( GetFrameworkCode ); > use C4::Items; >+use C4::MarcModificationTemplates; > use XML::Simple; > use Koha::Biblios; >+use List::MoreUtils qw(firstval); > > my $query = CGI->new; > binmode STDOUT, ':encoding(UTF-8)'; >@@ -124,6 +126,17 @@ sub update_bib { > } > } > >+ 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\""; >+ } >+ } >+ > C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode ); > my $biblio = Koha::Biblios->find( $biblionumber ); > my $new_record = $biblio->metadata->record({ embed_items => scalar $query->url_param('items') }); >diff --git a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t b/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t >new file mode 100644 >index 0000000000..12c10d904b >--- /dev/null >+++ b/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t >@@ -0,0 +1,154 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+use Modern::Perl; >+use Test::More tests => 1; >+use Test::MockModule; >+use Test::Warn; >+use Test::WWW::Mechanize; >+require HTTP::Request; >+use MARC::Record; >+use XML::Simple; >+use C4::MarcModificationTemplates; >+use C4::Biblio; >+ >+eval{ >+ use C4::Context; >+}; >+if ($@) { >+ plan skip_all => "Tests skip. You must have a working Context\n"; >+} >+ >+my $koha_conf = $ENV{KOHA_CONF}; >+my $koha_conf_xml = XMLin($koha_conf); >+ >+my $user = $ENV{KOHA_USER} || $koha_conf_xml->{config}->{user}; >+my $password = $ENV{KOHA_PASS} || $koha_conf_xml->{config}->{pass}; >+my $intranet = $ENV{KOHA_INTRANET_URL}; >+ >+if (not defined $intranet) { >+ plan skip_all => "Tests skipped. You must set environment variable KOHA_INTRANET_URL to run tests\n"; >+} >+ >+subtest 'Templates applied using simple and advanced MARC Editor' => sub { >+ plan tests => 13; >+ >+ # Create "Test" MARC modification template >+ my $template_id = AddModificationTemplate('TEST'); >+ ok($template_id, 'MARC modification template successfully created'); >+ my $add_template_action_result = AddModificationTemplateAction( >+ $template_id, >+ 'update_field', # Action >+ 0, >+ 250, # Field >+ 'a', # Subfield >+ '251 bottles of beer on the wall', # Value >+ '', >+ '', >+ '', >+ '', >+ '', >+ '', >+ '', >+ '', >+ '', >+ '', >+ 0, >+ '' >+ ); >+ ok($add_template_action_result, 'MARC modification template action successfully created'); >+ my $record = MARC::Record->new(); >+ $record->leader(' nam a22 7a 4500'); >+ $record->append_fields( >+ MARC::Field->new('001', '12345'), >+ MARC::Field->new('003', 'TEST'), >+ MARC::Field->new('245', '1', '0', 'a' => 'TEST'), >+ MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall'), >+ # @FIXME: Create test item type? Not super safe to rely on existing 'BK' type >+ MARC::Field->new('942', '','', 'c' => 'BK'), >+ ); >+ my ($biblionumber) = AddBiblio($record, ''); >+ >+ my $saved_record = GetMarcBiblio({ biblio => $biblionumber, embed_items => 0 }); >+ my $saved_record_250_field = $saved_record->field('250'); >+ isa_ok($saved_record_250_field, 'MARC::Field', 'Field with tag 250 has been saved'); >+ is($saved_record_250_field->subfield('a'), '250 bottles of beer on the wall', 'Field 250a has the same value passed to AddBiblio'); >+ >+ my $old_template_preference = C4::Context->preference('SaveBiblioMarcModificationTemplate'); >+ C4::Context->set_preference('SaveBiblioMarcModificationTemplate', 'TEST'); >+ >+ my $agent = Test::WWW::Mechanize->new(autocheck => 1); >+ >+ $agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'Connect to intranet'); >+ $agent->form_name('loginform'); >+ $agent->field('password', $password); >+ $agent->field('userid', $user); >+ $agent->field('branch', ''); >+ $agent->click_ok('', 'Login to staff client'); >+ >+ $agent->get_ok("$intranet/cgi-bin/koha/mainpage.pl", 'Load main page'); #FIXME: Remove? >+ $agent->get_ok("$intranet/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber", 'Load bibliographic record in simple MARC editor'); >+ $agent->submit_form_ok( >+ { >+ form_id => 'f', >+ button => '', >+ }, >+ 'Save bibliographic record using simple MARC editor' >+ ); >+ >+ $saved_record = GetMarcBiblio({ biblio => $biblionumber, embed_items => 0 }); >+ $saved_record_250_field = $saved_record->field('250'); >+ is($saved_record_250_field->subfield('a'), '251 bottles of beer on the wall', 'Field with tag 250 has been modified by MARC modification template'); >+ >+ # FIXME: Don't really need to to this, but could be useful so >+ # test below does not succed by accident >+ $saved_record->delete_fields($saved_record_250_field); >+ $saved_record->insert_fields_ordered(MARC::Field->new('250', '','', 'a' => '250 bottles of beer on the wall')); >+ $biblionumber = ModBiblioMarc($saved_record, $biblionumber); >+ ok($biblionumber, 'Field with tag 250 has been restored to original value'); >+ >+ # @FIXME: Leader record status n or c? >+ my $record_xml = <<'EOF'; >+<?xml version="1.0" standalone='yes'?> >+ <record xmlns="http://www.loc.gov/MARC21/slim"> >+ <leader> cam a22 7a 4500</leader> >+ <controlfield tag="001">12345</controlfield> >+ <controlfield tag="003">TEST</controlfield> >+ <datafield tag="245" ind1="1" ind2="0"> >+ <subfield code="a">TEST</subfield> >+ </datafield> >+ <datafield tag="250" ind1=" " ind2=" "> >+ <subfield code="a">250 bottles of beer on the wall</subfield> >+ </datafield> >+ <datafield tag="942" ind1=" " ind2=" "> >+ <subfield code="c">BK</subfield> >+ <subfield code="2">ddc</subfield> >+ </datafield></record> >+EOF >+ my $headers = HTTP::Headers->new( >+ Content_Type => 'text/xml', >+ ); >+ my $request = HTTP::Request->new('POST', "$intranet/cgi-bin/koha/svc/bib/$biblionumber", $headers, $record_xml); >+ my $response = $agent->request($request); >+ >+ is($response->code, '200', 'Emulate save in advanced MARC editor, Koha REST API responded with 200 for update biblio request'); >+ like($response->decoded_content, qr/251 bottles of beer on the wall/, 'Field with tag 250 has been modified by MARC modification template'); >+ >+ # Clean up >+ DelBiblio($biblionumber); >+ DelModificationTemplate($template_id); >+ C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $old_template_preference); >+}; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18138
:
61442
|
61443
|
61734
|
82783
|
86617
|
110266
|
110269
|
110270
|
110272
|
118439
|
118440
|
118441
|
118442
|
118443
|
118444
|
118824
|
120709
|
123125
|
123127
|
123128
|
123129
|
123130
|
123131
|
123132
|
123133
|
123137
|
124466
|
124467
|
124468
|
124469
|
124470
|
124471
|
124472
|
124473
|
124474
|
124475
|
124476
|
124477
|
124478
|
124484
|
124485
|
124486
|
124492
|
124493
|
124991
|
125157
|
148004
|
148005
|
148006
|
148007
|
148008
|
148009
|
157183
|
157184
|
157185
|
157186
|
157187
|
157188
|
157189
|
157190
|
157485
|
157486
|
157487
|
157488
|
157489
|
157490
|
157491
| 158414 |
158415
|
158416
|
158417
|
158418
|
158419
|
158420
|
158421
|
162612
|
162613