/[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 141 - (show annotations)
Fri May 30 22:46:53 2008 UTC (11 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 1960 byte(s)
When run with

./bin/import-ldap.pl --strix

it will import just organization which have strix site (which assume that
you allready imported strix sites before running this command)
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 Jifty->web->request(Jifty::Request->new);
15 Jifty->web->response(Jifty::Response->new);
16
17 my $limit = 0;
18 my @models;
19 my $strix;
20
21 GetOptions(
22 'limit=i', => \$limit,
23 'model=s', => \@models,
24 'strix+', => \$strix,
25 ) or die "$0: $!";
26
27 my $ldap = A3C::LDAP->new;
28
29 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 if ( $strix ) {
47 my $strix_sites = A3C::Model::StrixSiteCollection->new;
48 $strix_sites->unlimit;
49 my $o_nr = 1;
50 while ( my $site = $strix_sites->next ) {
51 Jifty->log->info( 'sync organization ', $o_nr++, '/', $strix_sites->count, ' ', $site->site );
52 sync_org( $site->site );
53 }
54 exit;
55 }
56
57 if ( @models ) {
58
59 Jifty->log->info( 'syncing: ', join(',', @models) );
60
61 foreach my $model ( @models ) {
62 my $collection = $ldap->collection( $model, limit => $limit );
63 Jifty->log->info( 'found ', $collection->count, ' entries for ', $model );
64 }
65 } else {
66
67 my $person_oc = $ldap->objectClass->{person};
68 my $org_oc = $ldap->objectClass->{organization};
69
70 Jifty->log->info( "syncing all $org_oc organizations and $person_oc persons" );
71
72 my $orgs = $ldap->collection( $org_oc , limit => $limit );
73
74 my $o_nr = 1;
75
76 my $value_from = $ldap->link->{value_from};
77
78 while ( my $o = $orgs->next ) {
79 Jifty->log->info( 'sync organization ', $o_nr++, '/', $orgs->count, ' ', $o->name );
80 if ( ! $o->can( $value_from ) ) {
81 warn "can't find $value_from in ",dump( $o->as_hash );
82 next;
83 }
84 my $org_uid = $o->$value_from || warn "can't find org_uid in $value_from in ",dump( $o->as_hash );
85 sync_org( $org_uid );
86 }
87 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26