OpenInteract2/Manage/Website/CleanOrphanedUsers.pm

filter: Statementstmt 36.1% 13 / 36 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 3 totaltotal 33.3% 17 / 51 CC 6 SCAR 31.6
CC
6
Cov
31%
run_task
42.0
get_brief_description
2.0
BEGIN
1.0
CRAP 23.5
« OpenInteract2/Context.pm ↑ Summary OpenInteract2/Datasource/LDAP.pm »
1 package OpenInteract2::Manage::Website::CleanOrphanedUsers;
2  
3 # $Id: CleanOrphanedUsers.pm,v 1.2 2005/03/03 03:36:20 lachoy Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage::Website );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 87 $OpenInteract2::Manage::Website::CleanOrphanedUsers::VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
10  
11 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
12 87 return 'clean_users';
13 }
14  
15 0 ▶sub get_brief_description {
Subroutine get_brief_description: not called CC=1 SCAR=6.9
Pod undocumented
16 0 return "Remove users who created themselves via the wizard but did " .
17 "not login within the time alloted.";
18 }
19  
20 0 ▶sub run_task {
Subroutine run_task: not called CC=6 SCAR=37.4
Pod undocumented
21 0 my ( $self ) = @_;
22 0 my $users = OpenInteract2::User->fetch_group({
23 where => 'removal_date IS NOT NULL',
24 order => 'removal_date DESC',
25 });
26 0 my $now = CTX->create_date();
27 0 my @to_remove = ();
28 0 foreach my $user ( @{ $users } ) {
29 0 ▶ if ( $user->{removal_date} < $now ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user->{"removal_date"} < $now) 0 0 0
30 0 push @to_remove, $user;
31 }
32 }
33 0 my $total = scalar @to_remove;
34 0 my ( $success, $failed ) = ( 0, 0 );
35 0 my @errors = ();
36 0 foreach my $user ( @to_remove ) {
37 0 eval { $user->remove({ skip_security => 1 }) };
38 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
39 0 $failed++;
40 0 push @errors, "$@";
41 }
42 else {
43 0 $success++;
44 }
45 }
46 0 ▶ if ( $success == $total ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($success == $total) { } 0 0 0
47 0 $self->_ok( 'clean users',
48 "All available users ($total) removed" );
49 }
50 else {
51 0 my $msg = "$total users to delete, $success ok, $failed failed; errors:\n" .
52 join( "\n", @errors );
53 0 $self->_fail( 'clean users', $msg );
54  
55 }
56 }
57  
58 87 OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ );
59  
60 87 1;
61  
62 __END__
« OpenInteract2/Context.pm ↑ Summary OpenInteract2/Datasource/LDAP.pm »