From 64405cf90671d0126200732a64f29fad2cccffb4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 Nov 2018 13:14:19 -0300 Subject: [PATCH] Bug 21749: Fix import of CSV biblio framework Bug 9701 added 2 new columns to the table marc_tag_structure which broke the import of biblio frameworks if the CSV file was generated with a previous version. Test plan: - Export a biblio framework from 17.11 - Import it into 18.05+ Signed-off-by: Tomas Cohen Arazi https://bugs.koha-community.org/show_bug.cgi?id=21740 Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens (cherry picked from commit 2d1b80d216b2bdf4eefc05f773d85f9cf14823b3) Signed-off-by: Martin Renvoize --- C4/ImportExportFramework.pm | 55 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/C4/ImportExportFramework.pm b/C4/ImportExportFramework.pm index bc02cca203..ef0b7ae852 100644 --- a/C4/ImportExportFramework.pm +++ b/C4/ImportExportFramework.pm @@ -977,40 +977,31 @@ sub _import_table_csv seek($dom, $pos, 0); return 1; } - if (scalar(@$fields) == scalar(@arrData)) { - if (!$fieldsNameRead) { - # New table, we read the field names - $fieldsNameRead = 1; - for (my $i=0; $i < @arrData; $i++) { - if ($arrData[$i] ne $fields->[$i]) { - $fieldsNameRead = 0; - last; - } - } - if ($fieldsNameRead) { - $fieldsStr = join(',', @$fields); - $dataStr = ''; - map { $dataStr .= '?,';} @$fields; - chop($dataStr) if ($dataStr); - $updateStr = ''; - map { $updateStr .= $_ . '=?,';} @$fields; - chop($updateStr) if ($updateStr); - } - } else { - # Read data - my $j = 0; - my %dataFields = (); - for (@arrData) { - if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { - $dataFields{$fields->[$j]} = $frameworkcode; - $arrData[$j] = $frameworkcode; - } else { - $dataFields{$fields->[$j]} = $_; - } - $j++ + if (!$fieldsNameRead) { + # New table, we read the field names + $fieldsNameRead = 1; + $fields = [@arrData]; + $fieldsStr = join(',', @$fields); + $dataStr = ''; + map { $dataStr .= '?,';} @$fields; + chop($dataStr) if ($dataStr); + $updateStr = ''; + map { $updateStr .= $_ . '=?,';} @$fields; + chop($updateStr) if ($updateStr); + } else { + # Read data + my $j = 0; + my %dataFields = (); + for (@arrData) { + if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { + $dataFields{$fields->[$j]} = $frameworkcode; + $arrData[$j] = $frameworkcode; + } else { + $dataFields{$fields->[$j]} = $_; } - $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); + $j++ } + $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); } $pos = tell($dom); } -- 2.39.5