From 06150351b431064bbc9cf343b459276820d649fc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 22 Oct 2020 10:59:17 +0000 Subject: [PATCH] Bug 26781: Check for subfield defined rather than truth To recreate: 1 - Have a record with 100$0 defined 2 - Define a Marc Modification template: Delete field 100$0 3 - Perform Batch record modification, enter the record above in the list of records 4 - Preview the MARC 5 - Note the entire 100 field has been deleted, don't modify the record 6 - Apply patch 7 - Restart all the things 8 - Test the modification again 9 - This time the preview confirms only the subfield 0 deleted 10 - Modify the record 11 - Confirm the record is correctly updated Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer JD amended patch: Fix typo ony vs only Signed-off-by: Jonathan Druart (cherry picked from commit be4f0c7639a679b1ec808e6e9cf9af0fc9576e79) Signed-off-by: Lucas Gass --- Koha/SimpleMARC.pm | 2 +- t/SimpleMARC.t | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index 82c3adc6f7..2867dc1cd6 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -526,7 +526,7 @@ sub delete_field { my $subfieldName = $params->{subfield}; my $field_numbers = $params->{field_numbers} // []; - if ( not $subfieldName or $subfieldName eq '' ) { + if ( !defined $subfieldName or $subfieldName eq '' ) { _delete_field({ record => $record, field => $fieldName, field_numbers => $field_numbers }); } else { _delete_subfield({ record => $record, field => $fieldName, subfield => $subfieldName, field_numbers => $field_numbers }); diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t index 4fd8933b29..6455820fbb 100644 --- a/t/SimpleMARC.t +++ b/t/SimpleMARC.t @@ -1676,7 +1676,7 @@ subtest 'move_field' => sub { subtest 'delete_field' => sub { plan tests => 2; subtest 'delete subfield' => sub { - plan tests => 2; + plan tests => 3; my $record = new_record; $record->append_fields( MARC::Field->new( @@ -1710,6 +1710,18 @@ subtest 'delete_field' => sub { @fields_952p = read_field( { record => $record, field => '952', subfield => 'p' } ); is_deeply( \@fields_952p, [], 'Delete all 952$p' ); + + $record = new_record; + $record->append_fields( + MARC::Field->new( + 600, ' ', ' ', + a => 'Murakami, Haruki', + 0 => 'https://id.loc.gov/authorities/names/n81152393.html', + ), + ); + delete_field( { record => $record, field => '600', subfield => '0' } ); + my @fields_600 = read_field( { record => $record, field => '600' } ); + is_deeply( \@fields_600, ['Murakami, Haruki'], 'Delete all 600$0, only subfield 0 deleted' ); }; subtest 'delete field' => sub { -- 2.39.5