From 73e89ab1bf24e8b43560ac0218ac0144d81985df Mon Sep 17 00:00:00 2001 From: Srdjan Date: Wed, 5 Jun 2013 16:34:29 +1200 Subject: [PATCH 1/1] Bug 9299: rework unique attributes check on ldap login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To reproduce: - configure a ldap server and $KOHA_CONF, etc. - try to log in - you will got a software error: Can't use an undefined value as an ARRAY reference at /home/koha/src/C4/Auth_with_ldap.pm line 183. Signed-off-by: Nuño López Ansótegui Signed-off-by: Jonathan Druart --- C4/Auth_with_ldap.pm | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 6143c9f..d7a5e9a 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -170,29 +170,25 @@ sub checkpw_ldap { } else { return 0; # B2, D2 } - if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { - my $extended_patron_attributes; + if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { + my @extended_patron_attributes; foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) { - my $code = $attribute_type->{code}; - if ( exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { # skip empty values - push @$extended_patron_attributes, { code => $code, value => $borrower{$code} }; - } + my $code = $attribute_type->{code}; + if ( exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { # skip empty values + push @extended_patron_attributes, { code => $code, value => $borrower{$code} }; + } } - my @errors; - #Check before add - for (my $i; $i< scalar(@$extended_patron_attributes)-1;$i++) { - my $attr=$extended_patron_attributes->[$i]; - unless (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) { - unshift @errors, $i; - warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}"; - } - } - #Removing erroneous attributes - foreach my $index (@errors){ - @$extended_patron_attributes=splice(@$extended_patron_attributes,$index,1); - } - C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); - } + #Check before add + my @unique_attr; + foreach my $attr ( @extended_patron_attributes ) { + if (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) { + push @unique_attr, $attr; + } else { + warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}"; + } + } + C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, \@unique_attr); + } return(1, $cardnumber, $userid); } -- 1.7.10.4