Bugzilla – Attachment 158417 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: Refactor after using template id instead of name
Bug-18138-Refactor-after-using-template-id-instead.patch (text/plain), 6.01 KB, created by
Katrin Fischer
on 2023-11-05 00:30:58 UTC
(
hide
)
Description:
Bug 18138: Refactor after using template id instead of name
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-11-05 00:30:58 UTC
Size:
6.01 KB
patch
obsolete
>From 244e8f251000396c952cc2e2fbb0a999b8913846 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <glasklas@gmail.com> >Date: Fri, 17 Sep 2021 16:07:13 +0200 >Subject: [PATCH] Bug 18138: Refactor after using template id instead of name > >Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org> >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > cataloguing/addbiblio.pl | 15 +++++++++------ > svc/bib | 12 +++++++----- > ...EditBiblioMarcModificationTemplatePreference.t | 13 ++++++++----- > 3 files changed, 24 insertions(+), 16 deletions(-) > >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index 8912610657..f74d64634a 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -45,8 +45,10 @@ use C4::ClassSource qw( GetClassSources ); > use C4::ImportBatch qw( GetImportRecordMarc ); > use C4::Charset qw( SetMarcUnicodeFlag ); > use C4::MarcModificationTemplates; >+use Koha::MarcModificationTemplates; > use Koha::BiblioFrameworks; > use Koha::DateUtils qw( dt_from_string ); >+use Carp; > > use Koha::Biblios; > use Koha::ItemTypes; >@@ -59,7 +61,6 @@ 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'); >@@ -667,16 +668,18 @@ 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(); >+ >+ my $template_id = C4::Context->preference("SaveBiblioMarcModificationTemplate"); >+ if ($template_id) { >+ my $template = Koha::MarcModificationTemplates->find($template_id); > if ($template) { >- ModifyRecordWithTemplate($template->{'template_id'}, $record); >+ ModifyRecordWithTemplate($template_id, $record); > } > else { >- warn "No MARC modification template exists with name \"$marc_modification_template_name\""; >+ croak "No MARC modification template exists with id \"$template_id\""; > } > } >+ > if ( $is_a_modif ) { > my $member = Koha::Patrons->find($loggedinuser); > ModBiblio( >diff --git a/svc/bib b/svc/bib >index 8a281da04f..9bfe5d2b2d 100755 >--- a/svc/bib >+++ b/svc/bib >@@ -26,9 +26,11 @@ use C4::Auth qw( check_api_auth ); > use C4::Biblio qw( GetFrameworkCode ); > use C4::Items; > use C4::MarcModificationTemplates; >+use Koha::MarcModificationTemplates; > use XML::Simple; > use Koha::Biblios; > use List::MoreUtils qw(firstval); >+use Carp; > > my $query = CGI->new; > binmode STDOUT, ':encoding(UTF-8)'; >@@ -126,14 +128,14 @@ 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(); >+ my $template_id = C4::Context->preference("SaveBiblioMarcModificationTemplate"); >+ if ($id) { >+ my $template = Koha::MarcModificationTemplates->find($template_id); > if ($template) { >- ModifyRecordWithTemplate($template->{'template_id'}, $record); >+ ModifyRecordWithTemplate($template_id, $record); > } > else { >- warn "No MARC modification template exists with name \"$marc_modification_template_name\""; >+ croak "No MARC modification template exists with id \"$template_id\""; > } > } > >diff --git a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t b/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t >index f9d69a6427..0d53ca6c98 100755 >--- a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t >+++ b/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t >@@ -23,6 +23,7 @@ require HTTP::Request; > use MARC::Record; > use XML::Simple; > use C4::MarcModificationTemplates; >+use Koha::MarcModificationTemplates; > use C4::Biblio qw(AddBiblio ModBiblioMarc GetMarcBiblio); > > eval{ >@@ -47,10 +48,12 @@ 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 $template_id = AddModificationTemplate('TEST'); >+ my $template = Koha::MarcModificationTemplate->new({ name => 'TEST' })->store; >+ >+ ok($template, 'MARC modification template successfully created'); > my $add_template_action_result = AddModificationTemplateAction( >- $template_id, >+ $template->id, > 'update_field', # Action > 0, > 250, # Field >@@ -88,7 +91,7 @@ subtest 'Templates applied using simple and advanced MARC Editor' => sub { > 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'); >+ C4::Context->set_preference('SaveBiblioMarcModificationTemplate', $template->id); > > my $agent = Test::WWW::Mechanize->new(autocheck => 1); > >@@ -149,6 +152,6 @@ EOF > > # Clean up > DelBiblio($biblionumber); >- DelModificationTemplate($template_id); >+ $template->delete; > 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