Commit 4a3e07de authored by eseyman%linagora.com's avatar eseyman%linagora.com

Bug 337947: Fix strange syntax in contrib/syncLDAP.pl

Patch By Emmanuel Seyman <eseyman@linagora.com> r=LpSolit, a=LpSolit
parent dc9ca5af
...@@ -79,13 +79,13 @@ my %ldap_users; ...@@ -79,13 +79,13 @@ my %ldap_users;
### ###
# Get current bugzilla users # Get current bugzilla users
### ###
my $bugzilla_users = $dbh->selectall_hashref( my %bugzilla_users = %{ $dbh->selectall_hashref(
'SELECT login_name AS new_login_name, realname, disabledtext ' . 'SELECT login_name AS new_login_name, realname, disabledtext ' .
'FROM profiles', 'new_login_name'); 'FROM profiles', 'new_login_name') };
foreach my $login_name (keys %$bugzilla_users) { foreach my $login_name (keys %bugzilla_users) {
# remove whitespaces # remove whitespaces
$bugzilla_users->{$login_name}{'realname'} =~ s/^\s+|\s+$//g; $bugzilla_users{$login_name}{'realname'} =~ s/^\s+|\s+$//g;
} }
### ###
...@@ -131,26 +131,26 @@ if(! $mesg->count) { ...@@ -131,26 +131,26 @@ if(! $mesg->count) {
exit; exit;
} }
my $val = $mesg->as_struct; my %val = %{ $mesg->as_struct };
while( my ($key, $value) = each(%$val) ) { while( my ($key, $value) = each(%val) ) {
my $login_name = @$value{Bugzilla->params->{"LDAPmailattribute"}}; my @login_name = @{ $value->{Bugzilla->params->{"LDAPmailattribute"}} };
my $realname = @$value{"cn"}; my @realname = @{ $value->{"cn"} };
# no mail entered? go to next # no mail entered? go to next
if(! defined $login_name) { if(! @login_name) {
print "$key has no valid mail address\n"; print "$key has no valid mail address\n";
next; next;
} }
# no cn entered? use uid instead # no cn entered? use uid instead
if(! defined $realname) { if(! @realname) {
$realname = @$value{Bugzilla->params->{"LDAPuidattribute"}}; @realname = @{ $value->{Bugzilla->params->{"LDAPuidattribute"}} };
} }
my $login = shift @$login_name; my $login = shift @login_name;
my $real = shift @$realname; my $real = shift @realname;
$ldap_users{$login} = { realname => $real }; $ldap_users{$login} = { realname => $real };
} }
...@@ -164,10 +164,10 @@ my %update_users; ...@@ -164,10 +164,10 @@ my %update_users;
my %create_users; my %create_users;
print "Bugzilla-Users: \n" unless $quiet; print "Bugzilla-Users: \n" unless $quiet;
while( my ($key, $value) = each(%$bugzilla_users) ) { while( my ($key, $value) = each(%bugzilla_users) ) {
print " " . $key . " '" . @$value{'realname'} . "' " . @$value{'disabledtext'} ."\n" unless $quiet==1; print " " . $key . " '" . $value->{'realname'} . "' " . $value->{'disabledtext'} ."\n" unless $quiet==1;
if(!exists $ldap_users{$key}){ if(!exists $ldap_users{$key}){
if(@$value{'disabledtext'} eq '') { if($value->{'disabledtext'} eq '') {
$disable_users{$key} = $value; $disable_users{$key} = $value;
} }
} }
...@@ -175,13 +175,13 @@ while( my ($key, $value) = each(%$bugzilla_users) ) { ...@@ -175,13 +175,13 @@ while( my ($key, $value) = each(%$bugzilla_users) ) {
print "\nLDAP-Users: \n" unless $quiet; print "\nLDAP-Users: \n" unless $quiet;
while( my ($key, $value) = each(%ldap_users) ) { while( my ($key, $value) = each(%ldap_users) ) {
print " " . $key . " '" . @$value{'realname'} . "'\n" unless $quiet==1; print " " . $key . " '" . $value->{'realname'} . "'\n" unless $quiet==1;
if(!defined $bugzilla_users->{$key}){ if(!defined $bugzilla_users{$key}){
$create_users{$key} = $value; $create_users{$key} = $value;
} }
else { else {
my $bugzilla_user_value = $bugzilla_users->{$key}; my $bugzilla_user_value = $bugzilla_users{$key};
if(@$bugzilla_user_value{'realname'} ne @$value{'realname'}) { if($bugzilla_user_value->{'realname'} ne $value->{'realname'}) {
$update_users{$key} = $value; $update_users{$key} = $value;
} }
} }
...@@ -190,9 +190,9 @@ while( my ($key, $value) = each(%ldap_users) ) { ...@@ -190,9 +190,9 @@ while( my ($key, $value) = each(%ldap_users) ) {
print "\nDetecting email changes: \n" unless $quiet; print "\nDetecting email changes: \n" unless $quiet;
while( my ($create_key, $create_value) = each(%create_users) ) { while( my ($create_key, $create_value) = each(%create_users) ) {
while( my ($disable_key, $disable_value) = each(%disable_users) ) { while( my ($disable_key, $disable_value) = each(%disable_users) ) {
if(@$create_value{'realname'} eq @$disable_value{'realname'}) { if($create_value->{'realname'} eq $disable_value->{'realname'}) {
print " " . $disable_key . " => " . $create_key ."'\n" unless $quiet==1; print " " . $disable_key . " => " . $create_key ."'\n" unless $quiet==1;
$update_users{$disable_key} = { realname => @$create_value{'realname'}, $update_users{$disable_key} = { realname => $create_value->{'realname'},
new_login_name => $create_key }; new_login_name => $create_key };
delete $create_users{$create_key}; delete $create_users{$create_key};
delete $disable_users{$disable_key}; delete $disable_users{$disable_key};
...@@ -203,21 +203,21 @@ while( my ($create_key, $create_value) = each(%create_users) ) { ...@@ -203,21 +203,21 @@ while( my ($create_key, $create_value) = each(%create_users) ) {
if($quiet == 0) { if($quiet == 0) {
print "\nUsers to disable: \n"; print "\nUsers to disable: \n";
while( my ($key, $value) = each(%disable_users) ) { while( my ($key, $value) = each(%disable_users) ) {
print " " . $key . " '" . @$value{'realname'} . "'\n"; print " " . $key . " '" . $value->{'realname'} . "'\n";
} }
print "\nUsers to update: \n"; print "\nUsers to update: \n";
while( my ($key, $value) = each(%update_users) ) { while( my ($key, $value) = each(%update_users) ) {
print " " . $key . " '" . @$value{'realname'} . "' "; print " " . $key . " '" . $value->{'realname'} . "' ";
if(defined @$value{'new_login_name'}) { if(defined $value->{'new_login_name'}) {
print "has changed email to " . @$value{'new_login_name'}; print "has changed email to " . $value->{'new_login_name'};
} }
print "\n"; print "\n";
} }
print "\nUsers to create: \n"; print "\nUsers to create: \n";
while( my ($key, $value) = each(%create_users) ) { while( my ($key, $value) = each(%create_users) ) {
print " " . $key . " '" . @$value{'realname'} . "'\n"; print " " . $key . " '" . $value->{'realname'} . "'\n";
} }
print "\n\n"; print "\n\n";
...@@ -258,10 +258,10 @@ if($readonly == 0) { ...@@ -258,10 +258,10 @@ if($readonly == 0) {
if($noupdate == 0) { if($noupdate == 0) {
while( my ($key, $value) = each(%update_users) ) { while( my ($key, $value) = each(%update_users) ) {
if(defined @$value{'new_login_name'}) { if(defined $value->{'new_login_name'}) {
$sth_update_login->execute(@$value{'new_login_name'}, $key); $sth_update_login->execute($value->{'new_login_name'}, $key);
} else { } else {
$sth_update_realname->execute(@$value{'realname'}, $key); $sth_update_realname->execute($value->{'realname'}, $key);
} }
} }
print "done!\n" unless $quiet; print "done!\n" unless $quiet;
...@@ -275,7 +275,7 @@ if($readonly == 0) { ...@@ -275,7 +275,7 @@ if($readonly == 0) {
while( my ($key, $value) = each(%create_users) ) { while( my ($key, $value) = each(%create_users) ) {
Bugzilla::User->create({ Bugzilla::User->create({
login_name => $key, login_name => $key,
realname => @$value{'realname'}, realname => $value->{'realname'},
cryptpassword => '*'}); cryptpassword => '*'});
} }
print "done!\n" unless $quiet; print "done!\n" unless $quiet;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment