X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=ferlib2koha.pl;h=34b65024c8167996c26fea74134defc8ea886b2a;hb=fed2025c561519c329823003c56216334082754e;hp=47e1a3ca335fdc36278bfecdde92fc4c70a46e60;hpb=d1fd39af0b56b57072c17aa269540ae21d82e295;p=ferlib2koha.git diff --git a/ferlib2koha.pl b/ferlib2koha.pl index 47e1a3c..34b6502 100755 --- a/ferlib2koha.pl +++ b/ferlib2koha.pl @@ -4,14 +4,15 @@ use strict; use DBI; use Data::Dump qw/dump/; use Algorithm::CheckDigits; +use Text::Unaccent; -# sudo apt-get install libdbd-sqlite3-perl libdbd-csv-perl +# sudo apt-get install libdbd-sqlite3-perl libdbd-csv-perl libtext-unaccent-perl $|++; my $import = { borrowers => $ENV{FULL} || 0, - issues => $ENV{FULL} || 1, + issues => $ENV{FULL} || 0, reserves => $ENV{FULL} || 0, barcode => $ENV{FULL} || 0, }; @@ -26,15 +27,25 @@ sub lookup { my ( $dbh, $t, $k, $v, $s, $default ) = @_; my $hash; my $key = "$t $k $v"; + my $max = $v =~ s/max\((\w+)\)/$1/; if ( exists $lookup->{$key} ) { $hash = $lookup->{$key}; } else { warn "# select $k,$v from $t"; my $sth = $dbh->prepare( "select $k,$v from $t" ); $sth->execute; + my @non_unique; while (my $row = $sth->fetchrow_hashref() ) { + if ( ! $max && exists $hash->{ $row->{$k} } ) { + push @non_unique, $row->{$k}; + next; + } $hash->{ $row->{$k} } = $row->{$v}; } + if ( @non_unique ) { + warn "# remove non-unique ", dump(@non_unique); + delete $hash->{$_} foreach @non_unique; + } $lookup->{$key} = $hash; warn "# lookup $key = ",dump($hash); } @@ -107,12 +118,29 @@ sub borrowers { insert 'borrowers' => $row; + my $borrowernumber = $k->{mysql_insertid}; + insert 'borrower_attributes' => { - borrowernumber => $k->{mysql_insertid}, + borrowernumber => $borrowernumber, code => 'JMBG', attribute => $jmbg, } if $jmbg; + foreach my $id ( 6,1,4,5,2 ) { + + insert 'borrower_message_preferences' => { + borrowernumber => $borrowernumber, + message_attribute_id => $id, + days_in_advance => $id == 2 ? 0 : undef, + }; + + insert 'borrower_message_transport_preferences' => { + borrower_message_preference_id => $k->{mysql_insertid}, + message_transport_type => 'email', + } if $id == 4; + + } + } } @@ -132,6 +160,8 @@ delete from borrowers; alter table borrowers auto_increment = 1; delete from borrower_attributes; alter table borrower_attributes auto_increment = 1; +delete from borrower_message_preferences where borrowernumber is not null ; +alter table borrower_message_preferences auto_increment = 1; }; @@ -322,7 +352,7 @@ sub reserves { $row->{itemnumber} ? 'W' : undef; $row->{borrowernumber} = lookup($k, 'borrowers', 'cardnumber' => 'borrowernumber', $row->{borrowernumber}); - $row->{biblionumber} = lookup($k, 'biblioitems', 'collectionvolume' => 'biblionumber', $row->{biblionumber}); + $row->{biblionumber} = lookup($k, 'biblioitems', 'collectionvolume' => 'max(biblionumber)', $row->{biblionumber}); $row->{itemnumber} = lookup($k, 'items', 'barcode' => 'itemnumber', $row->{itemnumber}); insert $table => $row; @@ -371,6 +401,56 @@ while( my $row = $sth->fetchrow_hashref ) { } # import->{barcode} +sub aqbooksellers { + my ($sql) = @_; + my $sth = $f->prepare($sql); + $sth->execute; + + $insert = undef; + while (my $row = $sth->fetchrow_hashref ) { + insert 'aqbooksellers' => $row; + } +} + +sql $k => qq{ +delete from aqbooksellers; +alter table aqbooksellers auto_increment = 1; +}; +aqbooksellers qq{ +select + ozn_nacdob as notes, + opis_nacdob as name, + 'HRK' as currency +from nacdob +}; + +my $sth = $k->prepare(qq{ +select + borrowernumber, + firstname, + surname, + cardnumber +from borrowers +where categorycode = 'D' and email is null +group by firstname,surname +having count(*) = 1 -- update only unique users +}); +my $update_borrower = $k->prepare(qq{ +update borrowers +set email = ?, userid = ?, cardnumber = ? +where borrowernumber = ? +}); +$sth->execute; +while (my $row = $sth->fetchrow_hashref) { + my $email = lc unac_string( 'utf-8', $row->{firstname} . '.' . $row->{surname} . '@fer.hr' ); + if ( my $nick = lookup($u, 'users', 'email', 'nick', $email, undef) ) { + my $cardnumber = lookup($u, 'users', 'email', 'jmbag', $email, undef) || next; + warn "# FIXED nick $row->{borrowernumber} $nick $email $cardnumber\n"; +eval { + $update_borrower->execute( $email, $nick, $cardnumber, $row->{borrowernumber} ); +}; + } +} $k->commit;