From 591d0359e340576a490848d707ce2534bd8c71fa 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 --- C4/Auth_with_ldap.pm | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 2f2bb27..9b1c7ca 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} ) { + push @$extended_patron_attributes, { code => $code, value => $borrower{$code} }; + } + } my @errors; #Check before add for (my $i; $i< scalar(@$extended_patron_attributes)-1;$i++) { -- 1.7.2.5