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 <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>
This commit is contained in:
Jonathan Druart 2018-11-12 13:14:19 -03:00 committed by Nick Clemens
parent cbb90000fd
commit 2d1b80d216
1 changed files with 23 additions and 32 deletions

View 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) {
# 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]} = $_;
}
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++
}
$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);
}