From 24125d4be39a3b6f19b1b0ae3f51855575a01759 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 15 Oct 2012 14:55:05 +0200 Subject: [PATCH] Bug 8919 - ExtendedPatronAttributes not populated from LDAP Current code is overly complex and assumes that C4::Members::AttributeTypes::GetAttributeTypes returns array of attribute codes which is not true. Instead it return array of hashes so none of extended attributes will be replicated from LDAP. This code correctly extracts extended attributes from borrower data provides simpler code which fills same structure. It also skips empty values (" ") which are result of mapping without any default value. This is needed to make unique extended patron values work. If not handled it would insert empty value for first user and fail for all others on uniqueness constraint. Test scenario: 1. define Patron attribute types in administration 2. define mapping from LDAP fields to attributes in koha-conf.xml 3. login as new user with LDAP fields and verify that extended attributes are replicated from LDAP Signed-off-by: Chris Cormack Passed-QA-by: Paul Poulain Signed-off-by: Jared Camins-Esakov --- C4/Auth_with_ldap.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 2f2bb27f2e..f3c1f7f39d 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -169,11 +169,13 @@ sub checkpw_ldap { return 0; # B2, D2 } if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { - my @types = C4::Members::AttributeTypes::GetAttributeTypes(); - my @attributes = grep{my $key=$_; any{$_ eq $key}@types;} keys %borrower; my $extended_patron_attributes; - @{$extended_patron_attributes} = - map { { code => $_, value => $borrower{$_} } } @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 @errors; #Check before add for (my $i; $i< scalar(@$extended_patron_attributes)-1;$i++) { -- 2.39.5