projects
/
koha.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'bug_10230' into 3.14-master
[koha.git]
/
C4
/
ImportExportFramework.pm
diff --git
a/C4/ImportExportFramework.pm
b/C4/ImportExportFramework.pm
old mode 100755
(executable)
new mode 100644
(file)
index
7f29e51
..
72873f2
--- a/
C4/ImportExportFramework.pm
+++ b/
C4/ImportExportFramework.pm
@@
-31,7
+31,7
@@
use C4::Debug;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN {
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN {
- $VERSION = 3.0
3
; # set version for version checking
+ $VERSION = 3.0
7.00.049
; # set version for version checking
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
@@
-322,6
+322,7
@@
sub _export_table_csv
my $data;
while (my $hashRef = $sth->fetchrow_hashref) {
for (@fields) {
my $data;
while (my $hashRef = $sth->fetchrow_hashref) {
for (@fields) {
+ $hashRef->{$_} =~ s/[\r\n]//g;
$$strCSV .= '"' . $hashRef->{$_} . '",';
}
chop $$strCSV;
$$strCSV .= '"' . $hashRef->{$_} . '",';
}
chop $$strCSV;
@@
-514,7
+515,7
@@
sub _createTmpDir
mkdir $tempdir;
};
if ($@) {
mkdir $tempdir;
};
if ($@) {
- return
undef
;
+ return;
} else {
return $tempdir;
}
} else {
return $tempdir;
}
@@
-546,27
+547,28
@@
sub createODS
$tempdir = _createTmpDir($tmp);
}
if ($tempdir) {
$tempdir = _createTmpDir($tmp);
}
if ($tempdir) {
+ my $fh;
# populate tempdir directory with the ods elements
eval {
# populate tempdir directory with the ods elements
eval {
- if (open(
OUT, ">
$tempdir/content.xml")) {
- print
OUT
$strContent;
- close(
OUT
);
+ if (open(
$fh, '>', "
$tempdir/content.xml")) {
+ print
{$fh}
$strContent;
+ close(
$fh
);
}
}
- if (open(
OUT, ">
$tempdir/mimetype")) {
- print
OUT
'application/vnd.oasis.opendocument.spreadsheet';
- close(
OUT
);
+ if (open(
$fh, '>', "
$tempdir/mimetype")) {
+ print
{$fh}
'application/vnd.oasis.opendocument.spreadsheet';
+ close(
$fh
);
}
}
- if (open(
OUT, ">
$tempdir/meta.xml")) {
- print
OUT
_getMeta($lang);
- close(
OUT
);
+ if (open(
$fh, '>', "
$tempdir/meta.xml")) {
+ print
{$fh}
_getMeta($lang);
+ close(
$fh
);
}
}
- if (open(
OUT, ">
$tempdir/styles.xml")) {
- print
OUT
ODS_STYLES_STR;
- close(
OUT
);
+ if (open(
$fh, '>', "
$tempdir/styles.xml")) {
+ print
{$fh}
ODS_STYLES_STR;
+ close(
$fh
);
}
}
- if (open(
OUT, ">
$tempdir/settings.xml")) {
- print
OUT
ODS_SETTINGS_STR;
- close(
OUT
);
+ if (open(
$fh, '>', "
$tempdir/settings.xml")) {
+ print
{$fh}
ODS_SETTINGS_STR;
+ close(
$fh
);
}
mkdir($tempdir.'/META-INF/');
mkdir($tempdir.'/Configurations2/');
}
mkdir($tempdir.'/META-INF/');
mkdir($tempdir.'/Configurations2/');
@@
-578,9
+580,10
@@
sub createODS
mkdir($tempdir.'/Configurations2/menubar/');
mkdir($tempdir.'/Configurations2/progressbar/');
mkdir($tempdir.'/Configurations2/toolbar/');
mkdir($tempdir.'/Configurations2/menubar/');
mkdir($tempdir.'/Configurations2/progressbar/');
mkdir($tempdir.'/Configurations2/toolbar/');
- if (open(OUT, "> $tempdir/META-INF/manifest.xml")) {
- print OUT ODS_MANIFEST_STR;
- close(OUT);
+
+ if (open($fh, '>', "$tempdir/META-INF/manifest.xml")) {
+ print {$fh} ODS_MANIFEST_STR;
+ close($fh);
}
};
if ($@) {
}
};
if ($@) {
@@
-603,13
+606,13
@@
sub createODS
my $ok = 0;
# read ods file and return as a string
if (-f "$tempdir/new.ods") {
my $ok = 0;
# read ods file and return as a string
if (-f "$tempdir/new.ods") {
- if (open (
MYFILE
, "$tempdir/new.ods")) {
- binmode
MYFILE
;
+ if (open (
$fh, '<'
, "$tempdir/new.ods")) {
+ binmode
$fh
;
my $buffer;
my $buffer;
- while (read (
MYFILE
, $buffer, 65536)) {
+ while (read (
$fh
, $buffer, 65536)) {
$$strODSRef .= $buffer;
}
$$strODSRef .= $buffer;
}
- close(
MYFILE
);
+ close(
$fh
);
$ok = 1;
}
}
$ok = 1;
}
}
@@
-761,7
+764,7
@@
sub _parseSQLLine
my $line;
my $numLines = 0;
while (<$dom>) {
my $line;
my $numLines = 0;
while (<$dom>) {
-
chomp $_
;
+
s/[\r\n]+$//
;
$line = $_;
# we don't want to execute any sql statement, only the ones dealing with frameworks
next unless ($line =~ /^\s*(?i:DELETE\s+FROM|INSERT\s+INTO)\s+(?:marc_tag_structure|marc_subfield_structure)/);
$line = $_;
# we don't want to execute any sql statement, only the ones dealing with frameworks
next unless ($line =~ /^\s*(?i:DELETE\s+FROM|INSERT\s+INTO)\s+(?:marc_tag_structure|marc_subfield_structure)/);
@@
-775,7
+778,7
@@
sub _parseSQLLine
my $stmt = SQL::Statement->new($line, $parser);
my $where = $stmt->where();
if ($where && $where->op() eq '=' && $line =~ /^\s*DELETE/) {
my $stmt = SQL::Statement->new($line, $parser);
my $where = $stmt->where();
if ($where && $where->op() eq '=' && $line =~ /^\s*DELETE/) {
- $line =~ s/frameworkcode='.
+
?'/frameworkcode='$frameworkcode';/ unless ($_ =~ /frameworkcode='$frameworkcode'/);
+ $line =~ s/frameworkcode='.
*
?'/frameworkcode='$frameworkcode';/ unless ($_ =~ /frameworkcode='$frameworkcode'/);
} else {
my @arrFields;
my @arrValues;
} else {
my @arrFields;
my @arrValues;
@@
-816,7
+819,7
@@
sub _parseSQLLine
if ($error) {
$line .= ';' unless ($line =~ /;$/);
if ($line =~ /^\s*DELETE/) {
if ($error) {
$line .= ';' unless ($line =~ /;$/);
if ($line =~ /^\s*DELETE/) {
- $line =~ s/frameworkcode='.
+
?'/frameworkcode='$frameworkcode'/ unless ($_ =~ /frameworkcode='$frameworkcode'/);
+ $line =~ s/frameworkcode='.
*
?'/frameworkcode='$frameworkcode'/ unless ($_ =~ /frameworkcode='$frameworkcode'/);
} elsif ($line =~ /^\s*INSERT\s+INTO\s+(.*?)\s+\((.*?frameworkcode.*?)\)\s+VALUES\s+\((.+)\)\s*;\s*$/) {
my $table = $1;
my $fields = $2;
} elsif ($line =~ /^\s*INSERT\s+INTO\s+(.*?)\s+\((.*?frameworkcode.*?)\)\s+VALUES\s+\((.+)\)\s*;\s*$/) {
my $table = $1;
my $fields = $2;
@@
-1133,6
+1136,7
@@
sub _import_table_csv
my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_;
my $row = '';
my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_;
my $row = '';
+ my $partialRow = '';
my $numFields = @$fields;
my $fieldsNameRead = 0;
my @arrData;
my $numFields = @$fields;
my $fieldsNameRead = 0;
my @arrData;
@@
-1145,10
+1149,21
@@
sub _import_table_csv
my $pos = 0;
while (<$dom>) {
$row = $_;
my $pos = 0;
while (<$dom>) {
$row = $_;
+ # Check whether the line has an unfinished field, i.e., a field with CR/LF in its data
+ if ($row =~ /,"[^"]*[\r\n]+$/ || $row =~ /^[^"]+[\r\n]+$/) {
+ $row =~ s/[\r\n]+$//;
+ $partialRow .= $row;
+ next;
+ }
+ if ($partialRow) {
+ $row = $partialRow . $row;
+ $partialRow = '';
+ }
+ # Line OK, process it
if ($row =~ /(?:".*?",?)+/) {
@arrData = split('","', $row);
$arrData[0] = substr($arrData[0], 1) if ($arrData[0] =~ /^"/);
if ($row =~ /(?:".*?",?)+/) {
@arrData = split('","', $row);
$arrData[0] = substr($arrData[0], 1) if ($arrData[0] =~ /^"/);
-
chomp $arrData[$#arrData]
;
+
$arrData[$#arrData] =~ s/[\r\n]+$//
;
chop $arrData[$#arrData] if ($arrData[$#arrData] =~ /"$/);
if (@arrData) {
if ($arrData[0] eq '#-#' && $arrData[$#arrData] eq '#-#') {
chop $arrData[$#arrData] if ($arrData[$#arrData] =~ /"$/);
if (@arrData) {
if ($arrData[0] eq '#-#' && $arrData[$#arrData] eq '#-#') {