Bug 11807 : Add support for categorycode conversions when updating an user using...
authorFrédérick <frederick.capovilla@libeo.com>
Wed, 19 Feb 2014 17:02:41 +0000 (12:02 -0500)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Fri, 1 Apr 2016 19:23:42 +0000 (19:23 +0000)
To test

1/ Apply both patches

2/ This patch lets you easily configure mappings for categorycode values.
These mapping will be used when updating the user's account after a successful LDAP login.

Here is an example configuration :

<config>
  <ldapserver id="ldapserver>
    <mapping>
      <categorycode is="usertype">STU</categorycode>
      ...
    </mapping>

    <categorycode_mapping>
      <categorycode value="STU">STUDENT</categorycode>
      <categorycode value="EMP">EMPLOYEE</categorycode>
    </categorycode_mapping>
  </ldapserver>
</config>

3/ With this configuration, LDAP users with the usertype value "EMP" on the LDAP server should have the "EMPLOYEE" categorycode in Koha.

Signed-off-by: Chris <chris@bigballofwax.co.nz>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
C4/Auth_with_ldap.pm

index 14db437..324783a 100644 (file)
@@ -27,6 +27,7 @@ use C4::Members qw(AddMember changepassword);
 use C4::Members::Attributes;
 use C4::Members::AttributeTypes;
 use C4::Members::Messaging;
+use C4::Dates;
 use C4::Auth qw(checkpw_internal);
 use Koha::AuthUtils qw(hash_password);
 use List::MoreUtils qw( any );
@@ -65,6 +66,15 @@ $debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ",
 @mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
 $debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (populated): ", join ' ', @mapkeys, "\n";
 
+my %categorycode_conversions;
+my $default_categorycode;
+if(defined $ldap->{categorycode_mapping}) {
+    $default_categorycode = $ldap->{categorycode_mapping}->{default};
+    foreach my $cat (@{$ldap->{categorycode_mapping}->{categorycode}}) {
+        $categorycode_conversions{$cat->{value}} = $cat->{content};
+    }
+}
+
 my %config = (
        anonymous => ($ldapname and $ldappassword) ? 0 : 1,
     replicate => defined($ldap->{replicate}) ? $ldap->{replicate} : 1,  #    add from LDAP to Koha database for new user
@@ -256,6 +266,18 @@ sub ldap_entry_2_hash {
                . substr($borrower{ 'surname' },0,1)
                . " ");
 
+    # Date and categorycode conversions
+    $borrower{'dateexpiry'} = C4::Dates->new($borrower{'dateexpiry'},'sql')->output('iso') if $borrower{'dateexpiry'};
+    $borrower{'dateofbirth'} = C4::Dates->new($borrower{'dateofbirth'},'sql')->output('iso') if $borrower{'dateofbirth'};
+    $borrower{'dateenrolled'} = C4::Dates->new($borrower{'dateenrolled'},'sql')->output('iso') if $borrower{'dateenrolled'};
+
+    if(defined $categorycode_conversions{$borrower{categorycode}}) {
+        $borrower{categorycode} = $categorycode_conversions{$borrower{categorycode}};
+    }
+    elsif($default_categorycode) {
+        $borrower{categorycode} = $default_categorycode;
+    }
+
        # 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 = ?");