X-Git-Url: http://git.rot13.org/?p=ferlib2koha.git;a=blobdiff_plain;f=ferlib2koha.pl;h=34b65024c8167996c26fea74134defc8ea886b2a;hp=cb396832ec2045b36a5c833c1fcb3c37774b3c87;hb=HEAD;hpb=93b4c19166a70f6346a35442896db92b26eb638d diff --git a/ferlib2koha.pl b/ferlib2koha.pl old mode 100755 new mode 100644 index cb39683..34b6502 --- a/ferlib2koha.pl +++ b/ferlib2koha.pl @@ -425,16 +425,32 @@ select from nacdob }; -=for later - if ( $row->{categorycode} eq 'D' && ! $row->{email} ) { - my $email = lc unac_string( 'utf-8', $row->{firstname} . '.' . $row->{surname} . '@fer.hr' ); - if ( my $nick = lookup($u, 'users', 'email', 'nick', $email, undef) ) { - $row->{email} = $email; - $row->{userid} = $nick; - $row->{cardnumber} = lookup($u, 'users', 'email', 'jmbag', $email, 'X-' . $row->{cardnumber}); - warn "# FIXED nick $nick $email $row->{cardnumber}\n"; - } - } -=cut +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;