Bug 26781: Check for subfield defined rather than truth
authorNick Clemens <nick@bywatersolutions.com>
Thu, 22 Oct 2020 10:59:17 +0000 (10:59 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 25 Oct 2020 23:14:41 +0000 (00:14 +0100)
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 <chrisc@catalyst.net.nz>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
JD amended patch: Fix typo ony vs only

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/SimpleMARC.pm
t/SimpleMARC.t

index 82c3adc..2867dc1 100644 (file)
@@ -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 });
index 4fd8933..6455820 100755 (executable)
@@ -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 {