From 08c2408a3d2df5be104304dcbd38a7af8cd63975 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Mar 2021 09:18:48 +0100 Subject: [PATCH] Bug 27968: Fix framework import if isurl has an incorrect value If isurl is set to undef in the DB, it will be exported as an empty string, which is an invalid value for isurl (int) Incorrect integer value: '' for column 'isurl' Test plan: Export framework structure in CSV and ODS, then reimport it and check that all the subfields are important correctly Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart (cherry picked from commit 01f0e04172432e28f37a94bf6df51a3fd6cdc960) Signed-off-by: Fridolin Somers (cherry picked from commit 5b4dd72d3a1772be1a7f9b0745663a2b3c6ecdf8) Signed-off-by: Andrew Fuerste-Henry --- C4/ImportExportFramework.pm | 10 +++++++++- t/db_dependent/data/frameworks/biblio_framework.csv | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/C4/ImportExportFramework.pm b/C4/ImportExportFramework.pm index ea4884f12d..9352dad201 100644 --- a/C4/ImportExportFramework.pm +++ b/C4/ImportExportFramework.pm @@ -977,6 +977,9 @@ sub _import_table_csv } elsif ($fields->[$j] eq 'frameworkcode' && $value ne $frameworkcode) { $dataFields{$fields->[$j]} = $frameworkcode; push @values, $frameworkcode; + } elsif ($fields->[$j] eq 'isurl' && defined $value && $value eq q{}) { + $dataFields{$fields->[$j]} = undef; + push @values, undef; } else { $dataFields{$fields->[$j]} = $value; push @values, $value; @@ -1094,7 +1097,12 @@ sub _getDataFields if ($ok) { $data //= ''; $data = '' if ($data eq '#'); - $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode'); + if ( $fields->[$i] eq 'frameworkcode' ) { + $data = $frameworkcode; + } + elsif ( $fields->[$i] eq 'isurl' ) { + $data = undef if defined $data && $data eq q{}; + } $dataFields->{$fields->[$i]} = $data; push @dataFieldsA, $data; $i++; diff --git a/t/db_dependent/data/frameworks/biblio_framework.csv b/t/db_dependent/data/frameworks/biblio_framework.csv index 20ae097d32..a47b1c2b2d 100644 --- a/t/db_dependent/data/frameworks/biblio_framework.csv +++ b/t/db_dependent/data/frameworks/biblio_framework.csv @@ -7,7 +7,7 @@ "#-#","#-#","#-#","#-#","#-#","#-#","#-#" "tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","kohafield","tab","authorised_value","authtypecode","value_builder","isurl","hidden","frameworkcode","seealso","link","defaultvalue","maxlength" -"000","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_leader.pl","0","0","","","","","24" +"000","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_leader.pl","","0","","","","","24" "001","@","control field","control field","0","0","","0","","","","0","0","","","","","9999" "003","@","control field","control field","0","1","","0","","","marc21_orgcode.pl","0","0","","","","","9999" "005","@","control field","control field","0","1","","0","","","marc21_field_005.pl","0","0","","","","","9999" -- 2.39.5