Apache-Sling
view release on metacpan or search on metacpan
lib/Apache/Sling/LDAPSynch.pm view on Meta::CPAN
scope => 'sub',
filter => "$search",
attrs => $attrs
)->as_struct;
}
#}}}
#{{{sub init_synch_cache
sub init_synch_cache {
my ($class) = @_;
if ( !${ $class->{'Content'} }
->check_exists( $class->{'CachePath'} . q(/) . $class->{'CacheFile'} ) )
{
my ( $tmp_cache_file_handle, $tmp_cache_file_name ) =
File::Temp::tempfile();
my %synch_cache;
print {$tmp_cache_file_handle}
Data::Dumper->Dump( [ \%synch_cache ], [qw( synch_cache )] )
or croak q(Unable to print initial data dump of synch cache to file!);
close $tmp_cache_file_handle
or croak
q(Problem closing temporary file handle when initializing synch cache);
${ $class->{'Content'} }
->upload_file( $tmp_cache_file_name, $class->{'CachePath'},
$class->{'CacheFile'} )
or croak q(Unable to initialize LDAP synch cache file!);
unlink $tmp_cache_file_name
or croak
q(Problem clearing up temporary file after init of synch cache!);
}
return 1;
}
#}}}
#{{{sub get_synch_cache
sub get_synch_cache {
my ($class) = @_;
$class->init_synch_cache();
if ( !${ $class->{'Content'} }
->check_exists( $class->{'CachePath'} . q(/) . $class->{'CacheFile'} ) )
{
croak q(No synch cache file present - initialization must have failed!);
}
${ $class->{'Content'} }
->view_file( $class->{'CachePath'} . q(/) . $class->{'CacheFile'} )
or croak q(Problem viewing synch cache file);
my $synch_cache;
my $success = eval ${ $class->{'Content'} }->{'Message'};
if ( !defined $success ) {
croak q{Error parsing synchronized cache dump.};
}
return $synch_cache;
}
#}}}
#{{{sub update_synch_cache
sub update_synch_cache {
my ( $class, $synch_cache ) = @_;
my ( $tmp_cache_file_handle, $tmp_cache_file_name ) =
File::Temp::tempfile();
print {$tmp_cache_file_handle}
Data::Dumper->Dump( [$synch_cache], [qw( synch_cache )] )
or croak q(Unable to print data dump of synch cache to file!);
close $tmp_cache_file_handle
or croak
q(Problem closing temporary file handle when updating synch cache);
${ $class->{'Content'} }
->upload_file( $tmp_cache_file_name, $class->{'CachePath'},
$class->{'CacheFile'} )
or croak q(Unable to update LDAP synch cache file!);
my $time = time;
${ $class->{'Content'} }
->upload_file( $tmp_cache_file_name, $class->{'CacheBackupPath'},
"cache$time.txt" )
or croak q(Unable to create LDAP synch cache backup file!);
unlink $tmp_cache_file_name
or croak
q(Problem clearing up temporary file after updating synch cache!);
return 1;
}
#}}}
#{{{sub get_synch_user_list
sub get_synch_user_list {
my ($class) = @_;
if ( !${ $class->{'Content'} }
->check_exists( $class->{'CachePath'} . q(/) . $class->{'UserList'} ) )
{
croak q(No user list file present - you need to create one!);
}
${ $class->{'Content'} }
->view_file( $class->{'CachePath'} . q(/) . $class->{'UserList'} )
or croak q(Problem viewing synch user list);
my $synch_user_list;
my $success = eval ${ $class->{'Content'} }->{'Message'};
if ( !defined $success ) {
croak q{Error parsing synchronized user list dump.};
}
return $synch_user_list;
}
#}}}
#{{{sub update_synch_user_list
sub update_synch_user_list {
my ( $class, $synch_user_list ) = @_;
my ( $tmp_user_list_file_handle, $tmp_user_list_file_name ) =
File::Temp::tempfile();
print {$tmp_user_list_file_handle}
Data::Dumper->Dump( [$synch_user_list], [qw( synch_user_list )] )
or croak q(Unable to print data dump of synch user list to file!);
close $tmp_user_list_file_handle
or croak
q(Problem closing temporary file handle when writing synch user list);
${ $class->{'Content'} }
->upload_file( $tmp_user_list_file_name, $class->{'CachePath'},
$class->{'UserList'} )
or croak
q(Unable to upload LDAP synch user list file into sling instance!);
Apache::Sling::Print::print_result( ${ $class->{'Content'} } );
my $time = time;
${ $class->{'Content'} }
->upload_file( $tmp_user_list_file_name, $class->{'CacheBackupPath'},
"user_list$time.txt" )
or croak q(Unable to create LDAP synch user list backup file!);
unlink $tmp_user_list_file_name
or croak
q(Problem clearing up temporary file after updating synch user list!);
return 1;
}
#}}}
#{{{sub download_synch_user_list
sub download_synch_user_list {
my ( $class, $user_list_file ) = @_;
my $synch_user_list = $class->get_synch_user_list;
foreach my $user ( sort keys %{$synch_user_list} ) {
if ( open my $out, '>>', $user_list_file ) {
flock $out, LOCK_EX;
print {$out} $user . "\n"
or croak
q(Problem printing when downloading synchronized user list!);
flock $out, LOCK_UN;
close $out
or croak
q(Problem closing file handle when downloading synchronized user list!);
}
else {
croak q(Could not open file to download synchronized user list to!);
}
}
$class->{'Message'} =
"Successfully downloaded user list to $user_list_file!";
return 1;
}
#}}}
#{{{sub upload_synch_user_list
sub upload_synch_user_list {
my ( $class, $user_list_file ) = @_;
my %user_list_hash;
( run in 1.115 second using v1.01-cache-2.11-cpan-13bb782fe5a )