/[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

Annotation of /bin/import-ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations)
Thu May 15 17:38:13 2008 UTC (11 years, 3 months ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1568 byte(s)
warn when we can't find some of columns in model istead
of dieing in ugly death
1 dpavlin 5 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use lib 'lib';
7    
8     use Jifty;
9 dpavlin 36 use A3C::LDAP;
10 dpavlin 7 use Data::Dump qw/dump/;
11 dpavlin 22 use Getopt::Long;
12 dpavlin 5
13     BEGIN { Jifty->new; };
14 dpavlin 60 Jifty->web->request(Jifty::Request->new);
15     Jifty->web->response(Jifty::Response->new);
16 dpavlin 5
17 dpavlin 44 my $limit = 0;
18     my @models;
19 dpavlin 22 GetOptions(
20     'limit=i', => \$limit,
21 dpavlin 44 'model=s', => \@models,
22 dpavlin 22 );
23    
24 dpavlin 42 my $ldap = A3C::LDAP->new;
25 dpavlin 5
26 dpavlin 60 if ( @models ) {
27 dpavlin 44
28 dpavlin 60 Jifty->log->info( 'syncing: ', join(',', @models) );
29    
30     foreach my $model ( @models ) {
31     my $collection = $ldap->collection( $model, limit => $limit );
32     Jifty->log->info( 'found ', $collection->count, ' entries for ', $model );
33     }
34     } else {
35    
36 dpavlin 106 my $person_oc = $ldap->objectClass->{person};
37     my $org_oc = $ldap->objectClass->{organization};
38 dpavlin 60
39 dpavlin 106 Jifty->log->info( "syncing all $org_oc organizations and $person_oc persons" );
40 dpavlin 60
41 dpavlin 106 my $orgs = $ldap->collection( $org_oc , limit => $limit );
42    
43 dpavlin 60 my $o_nr = 1;
44    
45 dpavlin 111 my $value_from = $ldap->link->{value_from};
46    
47 dpavlin 60 while ( my $o = $orgs->next ) {
48     Jifty->log->info( 'sync organization ', $o_nr++, '/', $orgs->count, ' ', $o->name );
49 dpavlin 116 if ( ! $o->can( $value_from ) ) {
50     warn "can't find $value_from in ",dump( $o->as_hash );
51     next;
52     }
53     my $org_uid = $o->$value_from || warn "can't find org_uid in $value_from in ",dump( $o->as_hash );
54 dpavlin 60 my $action = Jifty->web->new_action(
55     class => 'SyncOrganization',
56     moniker => 'sync',
57     arguments => {
58 dpavlin 106 org_uid => $org_uid,
59 dpavlin 60 }
60     );
61     $action->run;
62     if ( $action->result->success ) {
63     Jifty->log->info( $action->result->message );
64     } else {
65     Jifty->log->error( "Can't sync ", $o->name );
66     }
67     }
68 dpavlin 5 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26