From caf31bb5dd08712d7faf44b2ed2455192295f79a Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 31 Mar 2011 15:14:46 +0200 Subject: [PATCH] Bug 6022: Auth_with_ldap check if categorycode is valid When importing users from LDAP, Auth_with_ldap.pm doesn't check if value for categorycode is present in categories table in Koha resulting in referential integrity error instead of using default value from koha-conf.xml Test scenario: 1. enable LDAP in koha-conf.xml using 1 and add configuration with DefaultCategoryCode 2. select/create LDAP user with category in SomeLDAPField which isn't in Koha 3. try logging in and ensure that assigned category to new user is DefaultCategoryCode Signed-off-by: Marijana Glavica Signed-off-by: Paul Poulain (cherry picked from commit 0352a8f24ac72b7dfbf84ea3c6f11e2e714708b0) Signed-off-by: Chris Nighswonger --- C4/Auth_with_ldap.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 7f56d9c598..6ecf50958d 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -228,6 +228,17 @@ sub ldap_entry_2_hash ($$) { ( substr($borrower{'firstname'},0,1) . substr($borrower{ 'surname' },0,1) . " "); + + # check if categorycode exists, if not, fallback to default from koha-conf.xml + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT categorycode FROM categories WHERE categorycode = ?"); + $sth->execute( uc($borrower{'categorycode'}) ); + unless ( my $row = $sth->fetchrow_hashref ) { + my $default = $mapping{'categorycode'}->{content}; + $debug && warn "Can't find ", $borrower{'categorycode'}, " default to: $default for ", $borrower{userid}; + $borrower{'categorycode'} = $default + } + return %borrower; } -- 2.39.5