From 335db10f4aa8f7586974fec9fe8873ea0ed6ed15 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 3 May 2023 15:06:18 +0000 Subject: [PATCH] Bug 31187: (follow-up) Check if input in form, not if values passed This patch updates the check to see if there was a form input present, not if a value was passed. $attr contains an item colum @form_attr contains the form inputs for the attribute @values (renamed from @v) contains the uniq values passed in to the form We want to know if permanent_location is in the form, not if it had values, to know if we should preserve the DB value To test: 1 - Apply patches 2 - Make sure permanent_location is not mapped to a marc field 3 - Batch edit an item, changing shelving location 4 - Confirm both location and permanent_location are changed --- t/db_dependent/Koha/Items/BatchUpdate.t | 13 ++++++++++++- tools/batchMod.pl | 9 +++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Koha/Items/BatchUpdate.t b/t/db_dependent/Koha/Items/BatchUpdate.t index 8c728f11ab..79d0415b3d 100755 --- a/t/db_dependent/Koha/Items/BatchUpdate.t +++ b/t/db_dependent/Koha/Items/BatchUpdate.t @@ -162,7 +162,7 @@ subtest 'permanent_location' => sub { # to allow explicitly setting a temporary location. # When mapped an empty value is submitted in the form with the key of permanent_location - plan tests => 2; + plan tests => 3; $items->batch_update( { @@ -188,6 +188,17 @@ subtest 'permanent_location' => sub { $item = $item->get_from_storage; is( $item->permanent_location, 'perm', 'Permanent location not updated when mapped, so key present, but no value passed '); + $items->batch_update( + { + new_values => { + 'location' => 'loc' + } + } + )->reset; + + $item = $item->get_from_storage; + is( $item->permanent_location, 'loc', 'Permanent location updated to location when not mapped and key not present'); + }; subtest 'regex' => sub { diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 9f2bb73507..befcd08f35 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -152,16 +152,17 @@ if ( $op eq "action" ) { }; } else { - my @v = - grep { $_ ne "" } uniq $input->multi_param($cgi_var_name); + my @form_attr = $input->multi_param($cgi_var_name); + my @values = + grep { $_ ne "" } uniq @form_attr; - next unless @v || $attr eq 'permanent_location'; + next unless @values || ( $attr eq 'permanent_location' && @form_attr ); # If permanent_location is present in the form we need to pass it forward # to indicate that the user may modify this field directly and so # it needs to be marked as 'dirty' on any update. Otherwise the object always # sets location to the permanent_location as well - $new_item_data->{$attr} = join '|', @v; + $new_item_data->{$attr} = join '|', @values; } } } -- 2.30.2