Bug 21749: Fix import of CSV biblio framework
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Nov 2018 16:14:19 +0000 (13:14 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 15 Nov 2018 12:47:36 +0000 (12:47 +0000)
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 <tomascohen@theke.io>

https://bugs.koha-community.org/show_bug.cgi?id=21740

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/ImportExportFramework.pm

index bc02cca..ef0b7ae 100644 (file)
@@ -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);
             }