[Koha-patches] [PATCH] Bug 11811 - tools/import_borrowers.pl doesn't support utf-8 encoded CSV

Dobrica Pavlinusic dpavlin at rot13.org
Tue Feb 25 12:45:58 CET 2014


Decode utf-8 characters in CSV file

Test scenario:
1. go to Tools > Import patrons
2. download sample CSV file
3. create few patrons with utf-8 chars
4. import patrons and verify then utf-8 characters are correct
---
 tools/import_borrowers.pl |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl
index 5f65c97..aa26bce 100755
--- a/tools/import_borrowers.pl
+++ b/tools/import_borrowers.pl
@@ -48,12 +48,9 @@ use C4::Members::AttributeTypes;
 use C4::Members::Messaging;
 
 use Text::CSV;
-# Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals:
-# ė
-# č
+use utf8;
 
 use CGI;
-# use encoding 'utf8';    # don't do this
 
 my (@errors, @feedback);
 my $extended = C4::Context->preference('ExtendedPatronAttributes');
@@ -115,6 +112,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
 
     # use header line to construct key to column map
     my $borrowerline = <$handle>;
+    utf8::decode($borrowerline);
     my $status = $csv->parse($borrowerline);
     ($status) or push @errors, {badheader=>1,line=>$., lineraw=>$borrowerline};
     my @csvcolumns = $csv->fields();
@@ -138,6 +136,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
     my $date_re = C4::Dates->new->regexp('syspref');
     my  $iso_re = C4::Dates->new->regexp('iso');
     LINE: while ( my $borrowerline = <$handle> ) {
+        utf8::decode($borrowerline);
         my %borrower;
         my @missing_criticals;
         my $patron_attributes;
-- 
1.7.2.5



More information about the Koha-patches mailing list