Revision 676b3c6effb85c8262555624af9926f765c380a5 authored by Travis Abbott on 01 November 2012, 21:02:21 UTC, committed by Travis Abbott on 01 November 2012, 21:14:01 UTC
the previous test data was asserting that the code did the wrong thing
(passed files to joinx in incorrect order due to filenames being hashed
then iterating over the keys).
1 parent df1bd18
Raw File
sync_genome_sys_user.pl

# sync genome_sys_user from ldap

#UR_DBI_NO_COMMIT=1

use Genome;
use Data::Dumper;

my @c = `ldapsearch -x`;

my @users;
my $user;

for my $c (@c) {

    next if $c =~ /^\#/;
    chomp($c);

    if ($c =~ /^$/) {
        # process/destroy user
        push @users, $user;
        undef $user;
    } else {
        my ($key, $value) = split(/\:\s+/,$c);
        $user->{$key} = $value;       
    }

}

# called email in db, mail in ldap

my $ldap_user = {};
for my $u (@users) {
    next if !$u->{'mail'};
    $ldap_user->{$u->{'mail'}} = $u;
}

my @db_users = Genome::Sys::User->fix_params_and_get();

print scalar(@db_users);
print 

my @changes;

my $db_user = {};
for my $u (@db_users) {

    my $email = $u->email();
    if (!$ldap_user->{$email}) {
        push @changes, '- ' . $email;        
        $u->delete();
    } else {
        $db_user->{$email} = $u;
    }
}

for my $mail (keys %$ldap_user) {
    my $u = $ldap_user->{$mail};

    if (!$db_user->{$mail}) {
        Genome::Sys::User->create(  
            email => $u->{'mail'},
            name => $u->{'cn'}
        );
        push @changes, '+ ' . $u->{'mail'};
    }
}

print Dumper \@changes;

UR::Context->commit();



back to top