|
From: Chris W. <la...@us...> - 2001-10-25 12:09:02
|
Update of /cvsroot/openinteract/SPOPS/SPOPS/LDAP
In directory usw-pr-cvs1:/tmp/cvs-serv14807
Modified Files:
MultiDatasource.pm
Log Message:
override fetch_by_dn to work with multiple datasources
Index: MultiDatasource.pm
===================================================================
RCS file: /cvsroot/openinteract/SPOPS/SPOPS/LDAP/MultiDatasource.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** MultiDatasource.pm 2001/10/23 14:21:42 1.8
--- MultiDatasource.pm 2001/10/25 12:08:57 1.9
***************
*** 45,50 ****
my ( $class, $id, $p ) = @_;
- my $R = OpenInteract::Request->instance;
-
# If passed in a handle, we will always use only that
--- 45,48 ----
***************
*** 52,77 ****
return $class->SUPER::fetch( $id, $p );
}
-
- my $ds_list = $class->CONFIG->{datasource};
-
- # If only one datasource is specified in the configuration, then
- # use it
! unless ( ref $ds_list eq 'ARRAY' and scalar @{ $ds_list } ) {
! DEBUG && _w( 1, "No datasources in configuration for ($class).",
! "Using SPOPS::LDAP->fetch()" );
! return $class->SUPER::fetch( $id, $p );
! }
! # Otherwise step through the datasource listing and try to
! # retrieve each one in turn
! foreach my $ds ( @{ $ds_list } ) {
! $R->scrib( 1, "Trying to use datasource ($ds) for class ($class)" );
$p->{connect_key} = $ds;
-
- # Trap security errors; if we don't fetch an object, we'll
- # just return undef.
-
my $object = eval { $class->SUPER::fetch( $id, $p ) };
if ( $object ) {
--- 50,62 ----
return $class->SUPER::fetch( $id, $p );
}
! my @ds_list = $class->_get_datasource_list( 'fetch', $id, $p );
! # Step through the datasource listing and try to retrieve each one
! # in turn
! foreach my $ds ( @ds_list ) {
! DEBUG && _w( 1, "(fetch) Trying to use datasource ($ds) for class ($class)" );
$p->{connect_key} = $ds;
my $object = eval { $class->SUPER::fetch( $id, $p ) };
if ( $object ) {
***************
*** 84,87 ****
--- 69,93 ----
+ sub fetch_by_dn {
+ my ( $class, $dn, $p ) = @_;
+ if ( $p->{ldap} ) {
+ return $class->SUPER::fetch_by_dn( $dn, $p );
+ }
+ my @ds_list = $class->_get_datasource_list( 'fetch_by_dn', $dn, $p );
+
+ # Step through the datasource listing and try to retrieve each one
+ # in turn
+
+ foreach my $ds ( @ds_list ) {
+ DEBUG && _w( 1, "(fetch_by_dn) Trying to use datasource ($ds) for class ($class)" );
+ $p->{connect_key} = $ds;
+ my $object = eval { $class->SUPER::fetch_by_dn( $dn, $p ) };
+ if ( $object ) {
+ $object->{_datasource} = $ds;
+ return $object
+ }
+ }
+ }
+
sub fetch_group_all {
my ( $class, $p ) = @_;
***************
*** 90,101 ****
return $class->SUPER::fetch_group( $p );
}
! my $ds_list = $class->CONFIG->{datasource};
! unless ( ref $ds_list eq 'ARRAY' and scalar @{ $ds_list } ) {
! DEBUG && _w( 1, "No datasources in configuration for ($class).",
! "Using SPOPS::LDAP->fetch_group()" );
! return $class->SUPER::fetch_group( $p );
! }
my @all_objects = ();
! foreach my $ds ( @{ $ds_list } ) {
$p->{connect_key} = $ds;
DEBUG && _w( 1, "Trying to fetch from datasource ($ds)" );
--- 96,102 ----
return $class->SUPER::fetch_group( $p );
}
! my @ds_list = $class->_get_datasource_list( 'fetch_group', $p );
my @all_objects = ();
! foreach my $ds ( @ds_list ) {
$p->{connect_key} = $ds;
DEBUG && _w( 1, "Trying to fetch from datasource ($ds)" );
***************
*** 127,130 ****
--- 128,153 ----
$p->{ldap} ||= $self->global_datasource_handle( $self->{_datasource} );
return $self->SUPER::remove( $p );
+ }
+
+
+ # Retrieve a datasource list from the class configuration. If it
+ # doesn't work (no list or the list is empty), run a specified method
+ # in the parent class.
+
+ sub _get_datasource_list {
+ my ( $class, $method, @args ) = @_;
+ my $ds_list = $class->CONFIG->{datasource};
+
+ # If there are not multiple datasources specified, then bounce
+ # back to the SPOPS::LDAP-version of th method we were trying to
+ # call in the first place.
+
+ unless ( ref $ds_list eq 'ARRAY' and scalar @{ $ds_list } ) {
+ DEBUG && _w( 1, "No datasources in configuration for ($class).",
+ "Using SPOPS::LDAP->$method()" );
+ my $full_method = "SUPER::$method";
+ return $class->$full_method( @args );
+ }
+ return @{ $ds_list };
}
|