From 73b88761ef8b4801dddb2a8117dcaab4b98a9545 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 17 Apr 2009 23:16:00 +0000 Subject: [PATCH 1/1] implement multiple values by keeping dn and repeating rows with changed attributes, implement organizationalunit and group with same attributes as Active Directory --- lib/LDAP/Koha.pm | 38 +++++++++++++++++++++++++++++++------- sql/group.sql | 11 +++++++++++ sql/organizationalunit.sql | 13 ++++--------- 3 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 sql/group.sql diff --git a/lib/LDAP/Koha.pm b/lib/LDAP/Koha.pm index 672aa1f..fccc38f 100644 --- a/lib/LDAP/Koha.pm +++ b/lib/LDAP/Koha.pm @@ -25,7 +25,7 @@ our $database = 'koha'; our $user = 'unconfigured-user'; our $passwd = 'unconfigured-password'; -our $max_results = 15; # 100; # FIXME +our $max_results = 1500; # 100; # FIXME our $objectclass = 'HrEduPerson'; @@ -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"; + + if ( $dn ne $last_dn ) { + + if ( $entry ) { + #$entry->changetype( 'modify' ); + warn "### entry ",$entry->dump( \*STDERR ); + push @entries, $entry; + undef $entry; + } - #$entry->changetype( 'modify' ); + $entry = Net::LDAP::Entry->new; + $entry->dn( $dn ); - warn "### entry ",$entry->dump( \*STDERR ); + $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 ); } diff --git a/sql/group.sql b/sql/group.sql new file mode 100644 index 0000000..b34ebf2 --- /dev/null +++ b/sql/group.sql @@ -0,0 +1,11 @@ +select + concat('cn=',c.categorycode,',ou=groups') as dn, + 'group' as objectClass, + 'groups' as ou, + c.categorycode as cn, + description as description, + + concat('uid=',replace(userid,'@ffzg.hr',''),',ou=',c.categorycode,',dc=ffzg,dc=hr') as members +from categories c +join borrowers b on b.categorycode = c.categorycode +where length(userid) > 0 diff --git a/sql/organizationalunit.sql b/sql/organizationalunit.sql index 24dbfc9..7f010fc 100644 --- a/sql/organizationalunit.sql +++ b/sql/organizationalunit.sql @@ -1,12 +1,7 @@ select - concat('ou=',categorycode) as dn, - 'top - organizationalUnit' as objectClass, - categorycode as ou, - description as description, + 'ou=groups' as dn, + 'organizationalunit' as objectClass, + 'groups' as ou, + 'Groups from Koha' as description - -- fake objectGUID since we don't have primary key - crc32(categorycode) as objectGUID - -from categories -- 2.20.1