X-Git-Url: http://git.rot13.org/?p=virtual-ldap;a=blobdiff_plain;f=lib%2FLDAP%2FKoha.pm;h=38e4428ef489179d0d22ab6fa9fa1cd17df232f3;hp=fccc38f99894ae987601cce436fab4b245125df1;hb=b3ce3ad0c105c022cc9b048a5f93c7eaaa0f4931;hpb=73b88761ef8b4801dddb2a8117dcaab4b98a9545 diff --git a/lib/LDAP/Koha.pm b/lib/LDAP/Koha.pm index fccc38f..38e4428 100644 --- a/lib/LDAP/Koha.pm +++ b/lib/LDAP/Koha.pm @@ -25,9 +25,10 @@ our $database = 'koha'; our $user = 'unconfigured-user'; our $passwd = 'unconfigured-password'; -our $max_results = 1500; # 100; # FIXME +our $max_results = $ENV{MAX_RESULTS} || 3000; # FIXME must be enough for all users +our $objectclass_default = 'hrEduPerson'; -our $objectclass = 'HrEduPerson'; +our $objectclass; $SIG{__DIE__} = sub { warn "!!! DIE ", @_; @@ -156,6 +157,7 @@ sub search { my $sql_where = ''; @values = (); + $objectclass = ''; foreach my $filter ( keys %{ $reqData->{'filter'} } ) { @@ -177,22 +179,34 @@ sub search { } } - $sql_where .= ' ' . join( " $filter ", @limits ); - } else { __ldap_search_to_sql( $filter, $reqData->{'filter'}->{$filter} ); } + $sql_where .= ' ' . join( " $filter ", @limits ) if @limits; + } + $objectclass ||= $objectclass_default; + + my $sql_select = read_file( lc "sql/$objectclass.sql" ); if ( $sql_where ) { - $sql_where = " where $sql_where"; + if ( $sql_select !~ m{where}i ) { + $sql_where = " where $sql_where"; + } else { + $sql_where = " and $sql_where"; + } } - my $sql_select = read_file( lc "sql/$objectclass.sql" ); - warn "# SQL:\n$sql_select\n", $sql_where ? $sql_where : '-- no where', "\n# DATA: ",dump( @values ); - my $sth = $dbh->prepare( $sql_select . $sql_where . " LIMIT $max_results" ); # XXX remove limit? + my $sql + = $sql_select + . $sql_where + . ( $objectclass =~ m{person}i ? " LIMIT $max_results" : '' ) # add limit just for persons + ; + + warn "# SQL:\n$sql\n# DATA: ",dump( @values ); + my $sth = $dbh->prepare( $sql ); $sth->execute( @values ); warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} ); @@ -233,8 +247,10 @@ sub search { } - warn "### last entry ",$entry->dump( \*STDERR ); - push @entries, $entry; + if ( $entry ) { + warn "### last entry ",$entry->dump( \*STDERR ); + push @entries, $entry; + } } else { warn "UNKNOWN request: ",dump( $reqData );