Bugzilla – Attachment 114343 Details for
Bug 26894
Marc Modification Templates treat subfield 0 as no subfield set when moving fields
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26894: Handle subfield 0 and delete empty fields
Bug-26894-Handle-subfield-0-and-delete-empty-field.patch (text/plain), 4.36 KB, created by
Fridolin Somers
on 2020-12-11 14:05:57 UTC
(
hide
)
Description:
Bug 26894: Handle subfield 0 and delete empty fields
Filename:
MIME Type:
Creator:
Fridolin Somers
Created:
2020-12-11 14:05:57 UTC
Size:
4.36 KB
patch
obsolete
>From f67dbe936d7fbd8cdcfdaf14b7c1b1836c47eca8 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 2 Nov 2020 12:05:47 +0000 >Subject: [PATCH] Bug 26894: Handle subfield 0 and delete empty fields >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch corrects handling of subfield 0 when copying/moving. Before these >patches copying from subfield 0 would copy the entire field. > >We also correct an error that if moving a single subfield, we can leave behind empty >fields with no subfields. They should be deleted. > >To test: >1 - Define a new MARC Modification template with actions: > Delete field 100$0 > Add new field 100$0 with value Test > Update existing or add new field 100$0 with value TestUpdated > Move field 100$0 to 600$0 > Copy field 600$0 to 100$0 > Copy and replace field 245$0 to 700$0 >2 - Define a new record like: > LDR 00334nam a22001217a 4500 > 003 ff > 005 20201102111604.0 > 008 201102b xxu||||| |||| 00| 0 eng d > 040 _ _ â¡cvsd > 100 1 _ â¡012345â¡aKnuth, Donal Ervinâ¡d1938 > 245 _ _ â¡012345â¡aThe aty of computer programmingâ¡cDonald E. Knuth > 650 _ 0 â¡042â¡aComputer programmingâ¡9462 >3 - Modify this record using the template above >4 - Note that entier 245 is copied to 700, same for 600 field >5 - Apply patch >6 - Now only subfields 0 are copied > >Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> >--- > Koha/SimpleMARC.pm | 9 +++++---- > t/db_dependent/MarcModificationTemplates.t | 17 ++++++++--------- > 2 files changed, 13 insertions(+), 13 deletions(-) > >diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm >index 2867dc1cd6..8b2fc651c4 100644 >--- a/Koha/SimpleMARC.pm >+++ b/Koha/SimpleMARC.pm >@@ -141,8 +141,8 @@ sub copy_and_replace_field { > if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; } > > >- if ( not $fromSubfieldName or $fromSubfieldName eq '' >- or not $toSubfieldName or $toSubfieldName eq '' >+ if ( !defined $fromSubfieldName or $fromSubfieldName eq '' >+ or !defined $toSubfieldName or $toSubfieldName eq '' > ) { > _copy_move_field( > { record => $record, >@@ -480,9 +480,9 @@ sub move_field { > my $regex = $params->{regex}; > my $field_numbers = $params->{field_numbers} // []; > >- if ( not $fromSubfieldName >+ if ( !defined $fromSubfieldName > or $fromSubfieldName eq '' >- or not $toSubfieldName >+ or !defined $toSubfieldName > or $toSubfieldName eq '' ) { > _copy_move_field( > { record => $record, >@@ -564,6 +564,7 @@ sub _delete_subfield { > > foreach my $field ( @fields ) { > $field->delete_subfield( code => $subfieldName ); >+ $record->delete_field( $field ) unless $field->subfields(); > } > } > >diff --git a/t/db_dependent/MarcModificationTemplates.t b/t/db_dependent/MarcModificationTemplates.t >index 7fcd222ea5..fa148f9771 100755 >--- a/t/db_dependent/MarcModificationTemplates.t >+++ b/t/db_dependent/MarcModificationTemplates.t >@@ -700,6 +700,11 @@ sub expected_record_0 { > my $record = MARC::Record->new; > $record->leader('03174nam a2200445 a 4500'); > my @fields = ( >+ MARC::Field->new( >+ 100, '1', ' ', >+ a => 'Knuth, Donald Ervin', >+ d => '1938', >+ ), > MARC::Field->new( > 245, '1', '4', > 0 => '12345', >@@ -713,9 +718,7 @@ sub expected_record_0 { > 9 => '462', > ), > MARC::Field->new( >- 600, '1', ' ', >- a => 'Knuth, Donald Ervin', >- d => '1938', >+ 600, ' ', ' ', > 0 => 'TestUpdated', > ), > MARC::Field->new( >@@ -723,9 +726,7 @@ sub expected_record_0 { > 0 => 'TestUpdated', > ), > MARC::Field->new( >- 100, '1', ' ', >- a => 'Knuth, Donald Ervin', >- d => '1938', >+ 100, ' ', ' ', > 0 => 'TestUpdated', > ), > MARC::Field->new( >@@ -733,10 +734,8 @@ sub expected_record_0 { > 0 => 'TestUpdated', > ), > MARC::Field->new( >- 700, '1', '4', >+ 700, ' ', ' ', > 0 => '12345', >- a => 'The art of computer programming', >- c => 'Donald E. Knuth.', > ), > ); > $record->append_fields(@fields); >-- >2.29.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 26894
:
112827
|
114343
|
115076