From 3f5bcb1b1433213a67e573bc6ddf47049e8a0cc5 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 14 Jun 2011 23:17:25 +0200 Subject: [PATCH] import CSV with user data --- ferlib2koha.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ferlib2koha.pl b/ferlib2koha.pl index c672423..342d8db 100755 --- a/ferlib2koha.pl +++ b/ferlib2koha.pl @@ -8,13 +8,15 @@ use Algorithm::CheckDigits; $|++; my $import = { - borrowers => 0, + borrowers => 1, issues => 0, + barcode => 0, }; my $f = DBI->connect("dbi:SQLite:dbname=knjiznica.sqlite","","", { RaiseError => 1, AutoCommit => 0 }) || die $DBI::errstr; $f->{sqlite_unicode} = 1; my $k = DBI->connect("dbi:mysql:database=koha_fer","","", { RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => 1 }) || die $DBI::errstr; +my $u = DBI->connect("dbi:CSV:","","", { RaiseError => 1, f_ext => '.csv', csv_sep_char => '|' }) || die $DBI::errstr; our $lookup; sub lookup { @@ -80,9 +82,11 @@ sub borrowers { $row->{'B_country'} = lookup($f, 'drzava', 'ozn_drzava', 'naz_drzava', $row->{'B_country'}, $row->{B_country} ); $row->{'B_city'} = lookup($f, 'mjesto', 'post_ozn', 'naz_mjesto', $row->{'B_city'}, $row->{B_city} ); - $row->{'email'} = lookup($f, 'clanost', 'ozn_vrclan||ozn_clan', 'email', $row->{'cardnumber'}, undef); + $row->{'B_email'} = lookup($f, 'clanost', 'ozn_vrclan||ozn_clan', 'email', $row->{'cardnumber'}, undef); $row->{'emailpro'} = lookup($f, 'clanost', 'ozn_vrclan||ozn_clan', 'email_k', $row->{'cardnumber'}, undef); + $row->{'email'} = lookup($u, 'users', 'jmbag', 'email', substr($row->{cardnumber},1), undef); # $row->{B_email} || $row->{emailpro} ) + $row->{sex} =~ s/\x{17D}/F/; $row->{city} ||= '?'; # not null @@ -232,6 +236,7 @@ set onloan = date_due, datelastborrowed = issuedate }; # import->{issues} +if ( $import->{barcode} ) { my $sth = $k->prepare(qq{ select itemnumber,barcode from items }); my $sth_update = $k->prepare(qq{ update items set barcode=? where itemnumber=? }); @@ -245,4 +250,6 @@ while( my $row = $sth->fetchrow_hashref ) { $sth_update->execute( $ean->complete( sprintf('%012d', $row->{barcode}) ), $row->{itemnumber} ); } +} # import->{barcode} + $k->commit; -- 2.20.1