/[A3C]/lib/A3C/LDAP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/LDAP.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 44 by dpavlin, Sun Mar 30 21:59:34 2008 UTC revision 53 by dpavlin, Tue Apr 1 17:32:59 2008 UTC
# Line 104  sub count { Line 104  sub count {
104    
105  =head2 as_collection_of  =head2 as_collection_of
106    
107    my $connection = $ldap->collection('Organization', $limit);    my $connection = $ldap->collection(
108            # name of model to use
109            'Organization',
110            # optional params
111            limit => $limit,
112            filter => '(uid=foobar)',
113      );
114    
115  =cut  =cut
116    
# Line 114  my $collection2filter = { Line 120  my $collection2filter = {
120  };  };
121    
122  sub collection {  sub collection {
123          my ( $self, $model, $limit ) = @_;          my $self = shift;
124            my $model = shift or die "no model?";
125            my $args = {@_};
126    
127          $limit ||= 0;   # unlimited by default          $args->{limit} ||= 0;   # unlimited by default
128    
129          my $filter = $collection2filter->{$model};          my $filter = $collection2filter->{$model};
130          die "unknown model $model" unless $filter;          die "unknown model $model" unless $filter;
131    
132            # add user filter
133            $filter = '(&' . $filter . $args->{filter} . ')' if $args->{filter};
134    
135          $self->search(          $self->search(
136                  base => $self->base,                  base => $self->base,
137                  filter => $filter,                  filter => $filter,
138                  sizelimit => $limit,                  sizelimit => $args->{limit},
139          );          );
140    
141          Jifty->log->info("searching LDAP for $model with $filter limit $limit returned ", $self->count, " results");          Jifty->log->info(
142                    "searching LDAP for $model with $filter ",
143                    $args->{limit} ? 'limit ' . $args->{limit} : '',
144                    'returned ', $self->count, ' results'
145            );
146    
147          my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection";          my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection";
148          my $collection = $class->new() or die "can't $class->new";          my $collection = $class->new() or die "can't $class->new";
# Line 182  sub ldap2model { Line 197  sub ldap2model {
197          my ( $id, $message ) = $model->load_or_create( %$data, %$additional );          my ( $id, $message ) = $model->load_or_create( %$data, %$additional );
198    
199          if ( $id ) {          if ( $id ) {
200                  Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id );                  Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id, ' ', $model->name );
201          } else {          } else {
202                  Jifty->log->error( ref($model), " ", $message );                  Jifty->log->error( ref($model), " ", $message );
203          }          }

Legend:
Removed from v.44  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26