# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
-# use warnings; almost?
+#use warnings; FIXME - Bug 2505
use Digest::MD5 qw(md5_base64);
use C4::Debug;
use C4::Context;
use C4::Members qw(AddMember changepassword);
+use C4::Members::Attributes;
+use C4::Members::AttributeTypes;
use C4::Utils qw( :all );
+use List::MoreUtils qw( any );
use Net::LDAP;
use Net::LDAP::Filter;
my $base = $ldap->{base} or die ldapserver_error('base');
$ldapname = $ldap->{user} ;
$ldappassword = $ldap->{pass} ;
-our %mapping = %{$ldap->{mapping}} || (); # or die ldapserver_error('mapping');
+our %mapping = %{$ldap->{mapping}}; # FIXME dpavlin -- don't die because of || (); from 6eaf8511c70eb82d797c941ef528f4310a15e9f9
my @mapkeys = keys %mapping;
$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys ( total ): ", join ' ', @mapkeys, "\n";
@mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
$debug and warn "LDAP bind failed as kohauser $principal_name: ". description($res);
return 0;
}
+
+ # FIXME dpavlin -- we really need $userldapentry leater on even if using auth_by_bind!
+ my $search = search_method($db, $userid) or return 0; # warnings are in the sub
+ $userldapentry = $search->shift_entry;
+
} else {
my $search = search_method($db, $userid) or return 0; # warnings are in the sub
$userldapentry = $search->shift_entry;
($cardnumber eq $c2) or warn "update_local returned cardnumber '$c2' instead of '$cardnumber'";
} else { # C1, D1
# maybe update just the password?
+ return(1, $cardnumber); # FIXME dpavlin -- don't destroy ExtendedPatronAttributes
}
} elsif ($config{replicate}) { # A2, C2
$borrowernumber = AddMember(%borrower) or die "AddMember failed";
- } else {
+ } else {
return 0; # B2, D2
}
- return(1, $cardnumber);
+ 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 = map{{code=>$_,value=>$borrower{$_}}}@attributes;
+ my $extended_patron_attributes = [] unless $extended_patron_attributes;
+ 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);
+ }
+return(1, $cardnumber);
}
# Pass LDAP entry object and local cardnumber (userid).