Fixed: Thingy importing with newlines embedded in CSV fields
This commit is contained in:
parent
bba4753beb
commit
c80a966f91
3 changed files with 31 additions and 9 deletions
|
|
@ -2054,16 +2054,15 @@ sub www_import {
|
|||
my $lineNumber = 0;
|
||||
my @data = ();
|
||||
|
||||
while (my $line = <$importFile>) {
|
||||
while ( my $row = WebGUI::Text::readCSV($importFile) ) {
|
||||
if ($lineNumber == 0 && $session->form->process('ignoreFirstLine')){
|
||||
$lineNumber++;
|
||||
$error->info("Skipping first line");
|
||||
next;
|
||||
}
|
||||
$error->info("Reading line $lineNumber: $line");
|
||||
$error->info("Reading line $lineNumber: @{ $row }");
|
||||
$lineNumber++;
|
||||
chomp($line);
|
||||
@data = WebGUI::Text::splitCSV($line);
|
||||
@data = @{ $row };
|
||||
|
||||
# check for duplicates
|
||||
my $fieldNumber = 0;
|
||||
|
|
@ -2086,7 +2085,7 @@ sub www_import {
|
|||
$query .= " limit 1";
|
||||
($foundDuplicateId) = $session->db->quickArray($query);
|
||||
if ($foundDuplicateId){
|
||||
$error->info("found duplicate record: ".$foundDuplicateId." for data: ".$line);
|
||||
$error->info("found duplicate record: ".$foundDuplicateId." for data: ". @{ $row });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ use Text::CSV_XS;
|
|||
use base 'Exporter';
|
||||
|
||||
our @EXPORT_OK = qw(
|
||||
joinCSV splitCSV
|
||||
joinCSV readCSV splitCSV
|
||||
|
||||
);
|
||||
|
||||
our %EXPORT_TAGS = (
|
||||
"csv" => [qw( joinCSV splitCSV )],
|
||||
"csv" => [qw( joinCSV readCSV splitCSV )],
|
||||
|
||||
);
|
||||
|
||||
|
|
@ -45,6 +45,11 @@ WebGUI::Text - Routines for manipulating text.
|
|||
use WebGUI::Text qw(:csv);
|
||||
my $string = joinCSV(@array);
|
||||
my @array = splitCSV($string);
|
||||
|
||||
while(my $row = readCSV($fileHandle) {
|
||||
my @fields = @{ $row };
|
||||
doSomethingWith(@fields);
|
||||
}
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
@ -79,6 +84,20 @@ sub joinCSV {
|
|||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 readCSV ( $fileHandle )
|
||||
|
||||
Reads a record from the passed filehandle and returns an arrayref of the columns read.
|
||||
|
||||
=cut
|
||||
|
||||
sub readCSV {
|
||||
my $fileHandle = shift;
|
||||
my $row = $csv->getline($fileHandle);
|
||||
return $row;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 splitCSV ( $string )
|
||||
|
|
@ -105,12 +124,11 @@ sub splitCSV {
|
|||
|
||||
=item *
|
||||
|
||||
splitCSV doesn't properly handle quoted fields with no text inside (...,"",...)
|
||||
None known.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over 4
|
||||
|
|
@ -119,6 +137,10 @@ splitCSV doesn't properly handle quoted fields with no text inside (...,"",...)
|
|||
|
||||
RFC 4180 (http://tools.ietf.org/html/rfc4180)
|
||||
|
||||
=item *
|
||||
|
||||
L<Text::CSV_XS>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue