From 3376e0d2189504cea220f2eb151d949e9a0835c8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Oct 2021 11:11:26 +0200 Subject: [PATCH] Bug 27526: Correct NULL vs empty string when editing When an item is edit we must keep the NULL values in DB if the input have been left empty. It also fixes the "barcode cannot be unique" error when an item does not have a barcode. Signed-off-by: Jonathan Druart --- cataloguing/additem.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 6ca575b4fc..e1787ee49a 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -420,6 +420,7 @@ if ($op eq "additem") { # FIXME Handle non existent item my $olditemlost = $item->itemlost; my @columns = Koha::Items->columns; + my $new_values = $item->unblessed; for my $c ( @columns ) { if ( $c eq 'more_subfields_xml' ) { my @more_subfields_xml = $input->multi_param("items.more_subfields_xml"); @@ -434,16 +435,22 @@ if ($op eq "additem") { # used in the framework $marc->append_fields(MARC::Field->new('999', ' ', ' ', @unlinked_item_subfields)); $marc->encoding("UTF-8"); - $item->more_subfields_xml($marc->as_xml("USMARC")); + $new_values->{more_subfields_xml} = $marc->as_xml("USMARC"); next; } $item->more_subfields_xml(undef); } else { - my @v = $input->multi_param("items.".$c); + my @v = map { ( defined $_ && $_ eq '' ) ? undef : $_ } $input->multi_param( "items." . $c ); next unless @v; - $item->$c(join ' | ', uniq @v); + + if ( scalar(@v) == 1 && not defined $v[0] ) { + delete $new_values->{$c}; + } else { + $new_values->{$c} = join ' | ', @v; + } } } + $item = $item->set_or_blank($new_values); # check that the barcode don't exist already if ( -- 2.39.5