fix single filter queries
[virtual-ldap] / lib / LDAP / Koha.pm
index 672aa1f..05532ea 100644 (file)
@@ -25,7 +25,7 @@ our $database = 'koha';
 our $user     = 'unconfigured-user';
 our $passwd   = 'unconfigured-password';
 
-our $max_results = 15; # 100; # FIXME
+our $max_results = 3000; # FIXME must be enough for all users
 
 our $objectclass = 'HrEduPerson';
 
@@ -177,12 +177,12 @@ sub search {
                                        }
                                }
 
-                               $sql_where .= ' ' . join( " $filter ", @limits );
-
                        } else {
                                __ldap_search_to_sql( $filter, $reqData->{'filter'}->{$filter} );
                        }
 
+                       $sql_where .= ' ' . join( " $filter ", @limits );
+
                }
 
                if ( $sql_where ) {
@@ -197,21 +197,45 @@ sub search {
 
                warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} );
 
+               my $last_dn = '?';
+               my $entry;
+
                while (my $row = $sth->fetchrow_hashref) {
 
                        my ( $dn, $attributes ) = _dn_attributes( $row, $base );
 
-                       my $entry = Net::LDAP::Entry->new;
-                       $entry->dn( $dn );
-                       $entry->add( %$attributes );
+                       warn "# dn $last_dn ... $dn\n";
 
-                       #$entry->changetype( 'modify' );
+                       if ( $dn ne $last_dn ) {
 
-                       warn "### entry ",$entry->dump( \*STDERR );
+                               if ( $entry ) {
+                                       #$entry->changetype( 'modify' );
+                                       warn "### entry ",$entry->dump( \*STDERR );
+                                       push @entries, $entry;
+                                       undef $entry;
+                               }
+
+                               $entry = Net::LDAP::Entry->new;
+                               $entry->dn( $dn );
+
+                               $entry->add( %$attributes );
+
+                       } else {
+                               foreach my $n ( keys %$attributes ) {
+                                       my $v = $attributes->{$n};
+                                       warn "# attr $n = $v\n";
+                                       $entry->add( $n, $v ) if $entry->get_value( $n ) ne $v;
+                               }
+                       }
+
+
+                       $last_dn = $dn;
 
-                       push @entries, $entry;
                }
 
+               warn "### last entry ",$entry->dump( \*STDERR );
+               push @entries, $entry;
+
        } else {
                warn "UNKNOWN request: ",dump( $reqData );
        }