/[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 175 - (hide annotations)
Mon Jun 16 16:49:30 2008 UTC (11 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 2003 byte(s)
make --strix option more clever

First import all hrEduOrg organizations from LDAP and then
sync organizations which have strix site
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 141 my $strix;
20    
21 dpavlin 22 GetOptions(
22     'limit=i', => \$limit,
23 dpavlin 44 'model=s', => \@models,
24 dpavlin 141 'strix+', => \$strix,
25     ) or die "$0: $!";
26 dpavlin 22
27 dpavlin 42 my $ldap = A3C::LDAP->new;
28 dpavlin 5
29 dpavlin 141 sub sync_org {
30     my $org_uid = shift;
31     my $action = Jifty->web->new_action(
32     class => 'SyncOrganization',
33     moniker => 'sync',
34     arguments => {
35     org_uid => $org_uid,
36     }
37     );
38     $action->run;
39     if ( $action->result->success ) {
40     Jifty->log->info( $action->result->message );
41     } else {
42     Jifty->log->error( "Can't sync $org_uid" );
43     }
44     }
45    
46 dpavlin 175 @models = 'hrEduOrg' if $strix;
47 dpavlin 141
48 dpavlin 60 if ( @models ) {
49 dpavlin 44
50 dpavlin 60 Jifty->log->info( 'syncing: ', join(',', @models) );
51    
52     foreach my $model ( @models ) {
53     my $collection = $ldap->collection( $model, limit => $limit );
54     Jifty->log->info( 'found ', $collection->count, ' entries for ', $model );
55     }
56     } else {
57    
58 dpavlin 106 my $person_oc = $ldap->objectClass->{person};
59     my $org_oc = $ldap->objectClass->{organization};
60 dpavlin 60
61 dpavlin 106 Jifty->log->info( "syncing all $org_oc organizations and $person_oc persons" );
62 dpavlin 60
63 dpavlin 106 my $orgs = $ldap->collection( $org_oc , limit => $limit );
64    
65 dpavlin 60 my $o_nr = 1;
66    
67 dpavlin 111 my $value_from = $ldap->link->{value_from};
68    
69 dpavlin 60 while ( my $o = $orgs->next ) {
70     Jifty->log->info( 'sync organization ', $o_nr++, '/', $orgs->count, ' ', $o->name );
71 dpavlin 116 if ( ! $o->can( $value_from ) ) {
72     warn "can't find $value_from in ",dump( $o->as_hash );
73     next;
74     }
75     my $org_uid = $o->$value_from || warn "can't find org_uid in $value_from in ",dump( $o->as_hash );
76 dpavlin 141 sync_org( $org_uid );
77 dpavlin 60 }
78 dpavlin 5 }
79 dpavlin 175
80     if ( $strix ) {
81     my $instances = A3C::Model::StrixInstanceCollection->new;
82     $instances->unlimit;
83     my $o_nr = 1;
84     while ( my $instance = $instances->next ) {
85     Jifty->log->info( 'sync organization ', $o_nr++, '/', $instances->count, ' ', $instance->instance );
86     sync_org( $instance->instance );
87     }
88     }
89    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26