X-Git-Url: http://git.rot13.org/?p=virtual-ldap;a=blobdiff_plain;f=lib%2FLDAP%2FKoha.pm;h=0769ecb84260f69efe1fa05c7140c319bd363ab1;hp=28d0868a3810f2268d6ce4c382f4edf497e2f1c4;hb=HEAD;hpb=571831397e4527af51bcd971cbdf1e17f9807cb8 diff --git a/lib/LDAP/Koha.pm b/lib/LDAP/Koha.pm index 28d0868..0769ecb 100644 --- a/lib/LDAP/Koha.pm +++ b/lib/LDAP/Koha.pm @@ -39,16 +39,14 @@ $SIG{__DIE__} = sub { require 'config.pl' if -e 'config.pl'; -my $dbh = DBI->connect($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; - # we need reverse LDAP -> SQL mapping for where clause my $ldap_sql_mapping = { 'uid' => 'userid', - 'objectGUID' => 'borrowernumber', + 'objectGUID' => 'b.borrowernumber', 'displayName' => 'surname', 'sn' => 'surname', - 'pager' => 'a.attribute', # was: rfid_sid + 'pager' => qq{replace(replace(a.attribute, char(13),''),char(10),'')}, # was: rfid_sid }; sub __sql_column { @@ -66,7 +64,7 @@ use constant RESULT_OK => { sub new { my ($class, $sock) = @_; my $self = $class->SUPER::new($sock); - print "connection from: ", $sock->peerhost(), "\n"; + warn "# connection from: ", $sock->peerhost(); return $self; } @@ -148,7 +146,6 @@ sub _dn_attributes { sub search { my $self = shift; my $reqData = shift; - print "searching...\n"; warn "# " . localtime() . " request = ", dump($reqData); @@ -208,10 +205,14 @@ sub search { ; warn "# SQL:\n$sql\n# DATA: ",dump( @values ); + my $dbh = DBI->connect_cached($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; my $sth = $dbh->prepare( $sql ); $sth->execute( @values ); warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} ); + my $dump = dump( $reqData->{'filter'} ); + $dump =~ s/[\r\n\s]+/ /gm; + print $sth->rows, " results for $dump\n"; my $last_dn = '?'; my $entry; @@ -220,13 +221,13 @@ sub search { my ( $dn, $attributes ) = _dn_attributes( $row, $base ); - warn "# dn $last_dn ... $dn\n"; + warn "## dn $last_dn ... $dn\n" if $debug; if ( $dn ne $last_dn ) { if ( $entry ) { #$entry->changetype( 'modify' ); - warn "### entry ",$entry->dump( \*STDERR ); + warn "### entry ",$entry->dump( \*STDERR ) if $debug; push @entries, $entry; undef $entry; } @@ -241,7 +242,7 @@ sub search { } else { foreach my $n ( keys %$attributes ) { my $v = $attributes->{$n}; - warn "# attr $n = $v\n"; + warn "## attr $n = $v\n" if $debug; $entry->add( $n, $v ) if $entry->get_value( $n ) ne $v; } } @@ -252,7 +253,7 @@ sub search { } if ( $entry ) { - warn "### last entry ",$entry->dump( \*STDERR ); + warn "### last entry ",$entry->dump( \*STDERR ) if $debug; push @entries, $entry; }