@@ -, +, @@ --- C4/Auth_with_ldap.pm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) --- a/C4/Auth_with_ldap.pm +++ a/C4/Auth_with_ldap.pm @@ -233,19 +233,23 @@ sub checkpw_ldap { if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); - while ( my $attribute_type = $attribute_types->next ) { - my $code = $attribute_type->code; - unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { - next; - } - my $patron = Koha::Patrons->find($borrowernumber); - if ( $patron ) { # Should not be needed, but we are in C4::Auth LDAP... + my $patron = Koha::Patrons->find($borrowernumber); + if ( $patron ) { + my @attributes; + while ( my $attribute_type = $attribute_types->next ) { + + my $code = $attribute_type->code; + unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { + next; + } + + # "repeatable" not supported eval { - my $attribute = Koha::Patron::Attribute->new({code => $code, attribute => $borrower{$code}}); - $patron->extended_attributes([$attribute->unblessed]); + $patron->extended_attributes->search({ 'me.code' => $code })->filter_by_branch_limitations->delete; + $patron->add_extended_attribute({ code => $code, attribute => $borrower{$code} }); }; - if ($@) { # FIXME Test if Koha::Exceptions::Patron::Attribute::NonRepeatable - warn "ERROR_extended_unique_id_failed $code $borrower{$code}"; + if ($@){ + warn sprintf "ERROR update extended attribute %s %s for patron %s (%s)", $code, $borrower{$code}, $patron->borrowernumber, $@; } } } --