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 |
|
|
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"; |
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 |
} |
} |