/[A3C]/bin/import-ldap.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /bin/import-ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations)
Sun Mar 30 00:02:18 2008 UTC (11 years, 4 months ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1542 byte(s)
move LDAP stuff in own package
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use lib 'lib';
7
8 use Jifty;
9 use A3C::LDAP;
10 use Data::Dump qw/dump/;
11 use Getopt::Long;
12
13 BEGIN { Jifty->new; };
14
15 my $limit = 100;
16 GetOptions(
17 'limit=i', => \$limit,
18 );
19
20 # perform a search
21 my $mesg = A3C::LDAP->search(
22 base => "dc=skole,dc=hr",
23 # filter => "(&(sn=Barr) (o=Texas Instruments))",
24 filter => "(objectClass=hrEduPerson)",
25 sizelimit => $limit, # 0 = off
26 );
27
28 if ( $mesg->code ) {
29 Jifty->log->error( $mesg->code, ": ", $mesg->error );
30 }
31
32 Jifty->log->info( "found ", $mesg->count, " entries" );
33
34 sub ldap2model {
35 my ( $model, $entry, $additional ) = @_;
36 my $data;
37
38 my @columns = map { $_->name } $model->columns;
39 #warn "# columns = ",dump( @columns );
40
41 foreach my $attr ( $entry->attributes ) {
42 if ( grep(/^\Q$attr\E$/, @columns ) ) {
43 $data->{$attr} = $entry->get_value( $attr );
44 # } elsif ( $attr !~ m/^(objectClass)$/i ) {
45 # Jifty->log->error(ref($model)," doesn't have $attr");
46 }
47 }
48
49 Jifty->log->debug( ref($model), ' = ', dump( $data ) );
50
51 my ( $id, $message ) = $model->load_or_create( %$data, %$additional );
52
53 if ( $id ) {
54 Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id );
55 } else {
56 Jifty->log->error( ref($model), " ", $message );
57 }
58 }
59
60 #foreach my $entry ( $mesg->entries ) {
61 while ( my $entry = $mesg->shift_entry ) {
62
63 # $entry->dump;
64
65 my $organization = A3C::Model::Organization->new;
66 ldap2model( $organization, $entry );
67
68 my $user = A3C::Model::User->new;
69 ldap2model( $user, $entry, { organization => $organization } );
70
71 }
72

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26