diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2638515d8..aaf728848 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -25,6 +25,7 @@ - fixed: Invitation EMails Escape Characters - fixed: EMS Formatting (Badge Page) - fixed: Thingy fields list on view screen tab + - fixed: Importing data into Thingy that has newlines embedded in fields 7.5.18 - fixed: Collateral Image Manager broken in Firefox 3 diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 9f93aa0a9..cf374e388 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -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 }); } } diff --git a/lib/WebGUI/Text.pm b/lib/WebGUI/Text.pm index 4569de3e7..158fd9b7c 100644 --- a/lib/WebGUI/Text.pm +++ b/lib/WebGUI/Text.pm @@ -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 + =back =cut