fuzzy match djelatnici
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 28 Jun 2011 09:01:51 +0000 (11:01 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 28 Jun 2011 09:01:51 +0000 (11:01 +0200)
ferlib2koha.pl

index cb39683..34b6502 100755 (executable)
@@ -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;