--- bin/ldap.pl 2008/03/13 14:00:40 9 +++ bin/ldap.pl 2008/03/30 21:59:34 44 @@ -6,57 +6,27 @@ use lib 'lib'; use Jifty; -use Net::LDAP; +use A3C::LDAP; use Data::Dump qw/dump/; +use Getopt::Long; BEGIN { Jifty->new; }; -my $ldap_config = Jifty->config->app('LDAP'); -Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); - -my $ldap = Net::LDAP->new( Jifty->config->app('LDAP')->{Server} ) or die "$@"; - -# an anonymous bind -#my $mesg = $ldap->bind; -my $mesg = $ldap->bind( - DN => Jifty->config->app('LDAP')->{DN}, - password => Jifty->config->app('LDAP')->{Password}, +my $limit = 0; +my @models; +GetOptions( + 'limit=i', => \$limit, + 'model=s', => \@models, ); -# perform a search -$mesg = $ldap->search( - base => "dc=skole,dc=hr", -# filter => "(&(sn=Barr) (o=Texas Instruments))", - filter => "(objectClass=hrEduPerson)", - sizelimit => 3, # 0 = off -); - -if ( $mesg->code ) { - warn $mesg->code, ": ", $mesg->error, "\n"; -} - -Jifty->log->info( "found ", $mesg->count, " entries" ); - -foreach my $entry ( $mesg->entries ) { - - $entry->dump; - - my $data; - my $user = CAdmin::Model::User->new; - - my @columns = map { $_->name } $user->columns; - #warn "# columns = ",dump( @columns ); +@models = ( 'Organization' ) unless @models; - foreach my $attr ( $entry->attributes ) { - if ( grep(/^\Q$attr\E$/, @columns ) ) { - $data->{$attr} = $entry->get_value( $attr ); - } else { - warn "model ",ref($user)," doesn't have column $attr\n"; - } - } +my $ldap = A3C::LDAP->new; - Jifty->log->debug( dump( $data ) ); +Jifty->log->info( 'syncing: ', join(',', @models) ); - $user->load_or_create( %$data ); +foreach my $model ( @models ) { + my $collection = $ldap->collection( $model, $limit ); + Jifty->log->info( "found ", $collection->count, " entries for $model" ); }