[LON-CAPA-cvs] cvs: modules /msu localenroll.pm
raeburn
raeburn at source.lon-capa.org
Fri Jan 14 13:21:17 EST 2022
raeburn Fri Jan 14 18:21:17 2022 EDT
Modified files:
/modules/msu localenroll.pm
Log:
- Integration with MSU campus information systems
- Log counts for (a) total number of users from ldap, (b) number of LC
users in ldap, (c) number of users from ldap not in LC.
- SQL results from RO_ClassList and RO_CLIFMS ordered by Term_Seq_Id so
that first, middle and last names used are for latest semester
- For active students name information will be from RO_ClassList, for all
others it will be from ldap (if available).
- If first name contains multiple words with more than 1 character, omit
middle name
- If first name contains one or more ? (i.e., a character from a non-ascii
character set was used, use first name from an older record, with no ?,
if available.
-------------- next part --------------
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.87 modules/msu/localenroll.pm:1.88
--- modules/msu/localenroll.pm:1.87 Wed Jan 12 21:46:56 2022
+++ modules/msu/localenroll.pm Fri Jan 14 18:21:17 2022
@@ -1,6 +1,6 @@
# functions to glue school database system into Lon-CAPA for
# automated enrollment
-# $Id: localenroll.pm,v 1.87 2022/01/12 21:46:56 raeburn Exp $
+# $Id: localenroll.pm,v 1.88 2022/01/14 18:21:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -223,6 +223,10 @@
$middle =~ s/\s+$//;
if (($first ne '') && ($first eq $middle)) {
$middle = '';
+ } elsif ($first =~ /^([\w-]+)\s+(\w+)/) {
+ if ((length($1) > 1) || (length($2) > 1)) {
+ $middle = '';
+ }
}
} elsif ($first eq '') {
$first = $given;
@@ -1356,15 +1360,15 @@
}
sub allusers_info {
- my ($dom,$instusers,$instids,$lc_users) = @_;
- my $outcome;
- &query_ldap($instusers,$lc_users);
+ my ($dom,$instusers,$instids,$lc_users,$counts) = @_;
+ my ($outcome,%ldap_users);
+ &query_ldap(\%ldap_users,$lc_users,'','','',undef,$counts);
my (%dbh,%dbflag,%srchtables,%affiliation_by_table);
my @connected = &userinfo_searchtables(\%dbh,\%dbflag,\%srchtables,
\%affiliation_by_table);
if (@connected) {
$outcome = &query_user_tables(\%dbflag,\%dbh,\%srchtables,\%affiliation_by_table,
- $instusers,$instids,$lc_users);
+ $instusers,$instids,$lc_users,\%ldap_users,$counts);
foreach my $conn (@connected) {
if ($dbflag{$conn}) {
&disconnect_DB($dbh{$conn});
@@ -1420,10 +1424,10 @@
}
sub query_ldap {
- my ($instusers,$lc_users,$srchby,$srchterm,$srchtype,$types) = @_;
+ my ($instusers,$lc_users,$srchby,$srchterm,$srchtype,$types,$counts) = @_;
my $outcome;
if ($srchby eq '') {
- $outcome = &ldap_dump($instusers,$lc_users);
+ $outcome = &ldap_dump($instusers,$lc_users,$counts);
} else {
my $ldapfilter;
if ($srchby eq 'uname') {
@@ -1463,7 +1467,7 @@
}
}
if ($ldapfilter ne '') {
- $outcome = &ldap_search($ldapfilter,$instusers,$types);
+ $outcome = &ldap_search($ldapfilter,$instusers,$types,$counts);
}
}
return $outcome;
@@ -1683,11 +1687,11 @@
sub query_user_tables {
my ($dbflagref,$dbhref,$srchtablesref,$affiliation_by_tableref,$instusers,
- $instids,$lcusersref) = @_;
+ $instids,$lcusersref,$ldap_users,$counts) = @_;
return unless ((ref($dbflagref) eq 'HASH') && (ref($dbhref) eq 'HASH') &&
(ref($srchtablesref) eq 'HASH') &&(ref($instusers) eq 'HASH') &&
- (ref($instids) eq 'HASH'));
- my ($outcome,$total,%users,%multipids);
+ (ref($instids) eq 'HASH') && (ref($ldap_users) eq 'HASH'));
+ my ($outcome,$total,%users,%multipids,%ldap_checked);
if (ref($lcusersref) eq 'HASH') {
%users = %{$lcusersref};
$total = scalar(keys(%users));
@@ -1698,7 +1702,7 @@
if (ref($affiliation_by_tableref) eq 'HASH') {
%table_to_key = %{$affiliation_by_tableref};
}
- my @order = ('hr','ro','cs');
+ my @order = ('ro','cs','hr');
foreach my $key (@order) {
if ($dbflagref->{$key}) {
foreach my $table (@{$srchtablesref->{$key}}) {
@@ -1707,9 +1711,9 @@
$statement = "SELECT MSUNetID,Pid,FirstName,LastName,Person_Type FROM $table";
} elsif ($key eq 'ro') {
if ($table eq 'RO_CLIFMS') {
- $statement = "SELECT DISTINCT MSUNetId,Emp_Id,PID,Name,Record_Type FROM $table WHERE (Record_Type = '1' OR Record_Type = 'PI')";
+ $statement = "SELECT DISTINCT MSUNetId,Emp_Id,PID,Name,Record_Type,Term_Seq_Id FROM $table WHERE (Record_Type = '1' OR Record_Type = 'PI') ORDER BY MSUNetId,Term_Seq_Id";
} else {
- $statement = "SELECT DISTINCT Pilot_Id,Pid,Student_Preferred_First_Name,Student_Name FROM $table";
+ $statement = "SELECT DISTINCT Pilot_Id,Pid,Student_Preferred_First_Name,Student_Name,Term_Seq_Id FROM $table ORDER BY Pilot_Id,Term_Seq_Id Desc";
}
} elsif ($key eq 'cs') {
$statement = "SELECT DISTINCT CAMPUS_ID,EMPLID,INSTR_UNIV_NAME,INSTR_ROLE FROM $table";
@@ -1747,7 +1751,7 @@
$name =~ s/^\s+//;
$name =~ s/\s+$//;
($last,$given) = split(/,/,$name,2);
- if ($rest[2] eq 'PI') {
+ if ($rest[1] eq 'PI') {
$type = 'Faculty';
}
}
@@ -1773,6 +1777,10 @@
$middle =~ s/\s+$//;
if (($first ne '') && ($first eq $middle)) {
$middle = '';
+ } elsif ($first =~ /^([\w-]+)\s+(\w+)/) {
+ if ((length($1) > 1) || (length($2) > 1)) {
+ $middle = '';
+ }
}
if (($middle ne '') && ($type ne 'Student') & ($middle !~ /\s/) && (length($first) > 1)) {
$middle = substr($middle, 0, 1);
@@ -1802,6 +1810,14 @@
$last =~ s/^(Mc)(\w)/$1\u$2/;
}
}
+ unless ((($key eq 'ro') && ($table eq 'RO_ClassList')) || ($ldap_checked{$uname})) {
+ unless (ref($instusers->{$uname}) eq 'HASH') {
+ if (ref($ldap_users->{$uname}) eq 'HASH') {
+ $instusers->{$uname} = $ldap_users->{$uname};
+ $ldap_checked{$uname} = 1;
+ }
+ }
+ }
if (ref($instusers->{$uname}) eq 'HASH') {
unless ($type eq '') {
if (ref($instusers->{$uname}{'inststatus'}) eq 'ARRAY') {
@@ -1840,6 +1856,11 @@
$instusers->{$uname}{'id'} = $pid;
}
}
+ if (($first ne '') && ($first ne $instusers->{$uname}{'first'})) {
+ if (($instusers->{$uname}{'firstname'} =~ /\?+/) && ($first !~ /\?/)) {
+ $instusers->{$uname}{'firstname'} = $first;
+ }
+ }
} else {
$instusers->{$uname} = {firstname => $first,
middlename => $middle,
@@ -1848,6 +1869,9 @@
permanentemail => $uname.'@msu.edu',
inststatus => [$type],
};
+ if ($generation ne '') {
+ $instusers->{$uname}{generation} = $generation;
+ }
}
if (defined($instids->{$pid})) {
if (ref($instids->{$pid}) eq 'ARRAY') {
@@ -1870,11 +1894,32 @@
}
$outcome = 'ok';
}
+ if (keys(%{$ldap_users}) > 0) {
+ foreach my $uname (keys(%{$ldap_users})) {
+ next if ($ldap_checked{$uname});
+ next unless (ref($ldap_users->{$uname}) eq 'HASH');
+ if (ref($instusers->{$uname}) eq 'HASH') {
+ if (ref($ldap_users->{$uname}->{inststatus}) eq 'ARRAY') {
+ my $type = $ldap_users->{$uname}->{inststatus}->[0];
+ unless ($type eq '') {
+ if (ref($instusers->{$uname}{'inststatus'}) eq 'ARRAY') {
+ if (!grep(/^$type$/,@{$instusers->{$uname}{'inststatus'}})) {
+ push(@{$instusers->{$uname}{'inststatus'}},$type);
+ }
+ }
+ }
+ }
+ } else {
+ $instusers->{$uname} = $ldap_users->{$uname};
+ }
+ }
+ $outcome = 'ok';
+ }
return $outcome;
}
sub ldap_search {
- my ($ldapfilter,$instusers,$types) = @_;
+ my ($ldapfilter,$instusers,$types,$counts) = @_;
my $outcome;
my $ldap = Net::LDAP->new( 'ldap.msu.edu' );
if ($ldap) {
@@ -1890,6 +1935,7 @@
} else {
$outcome = 'ok';
}
+ my $count = 0;
foreach my $entry ($mesg->entries) {
my $uname = $entry->get_value('uid');
next if ($uname eq '');
@@ -1935,10 +1981,16 @@
undef($type);
}
}
- if (($name ne '') && ($type ne 'Student') & ($name !~ /\s/) && (length($first) > 1)) {
- $middle = substr($name, 0, 1);
- } else {
- $middle = $name;
+ $middle = $name;
+ if (($first ne '') && ($first eq $middle)) {
+ $middle = '';
+ } elsif ($first =~ /^([\w-]+)\s+(\w+)/) {
+ if ((length($1) > 1) || (length($2) > 1)) {
+ $middle = '';
+ }
+ }
+ if (($middle ne '') && ($type ne 'Student') & ($middle !~ /\s/) && (length($first) > 1)) {
+ $middle = substr($middle, 0, 1);
}
if (ref($types) eq 'ARRAY') {
if (@{$types} > 0) {
@@ -1965,15 +2017,19 @@
if ($generation ne '') {
$instusers->{$uname}{generation} = $generation;
}
+ $count ++;
}
}
+ if (ref($counts) eq 'HASH') {
+ $counts->{'ldap_search'} += $count;
+ }
$ldap->unbind;
}
return $outcome;
}
sub ldap_dump {
- my ($instusers,$lc_users) = @_;
+ my ($instusers,$lc_users,$counts) = @_;
my ($outcome,$total,%users);
if (ref($lc_users) eq 'HASH') {
%users = %{$lc_users};
@@ -1996,9 +2052,15 @@
$outcome = 'ok';
}
my $count = 0;
+ my $nouname = 0;
+ my $hasuname = 0;
foreach my $entry ($mesg->entries) {
my $uname = $entry->get_value('uid');
- next if ($total && !$users{$uname});
+ if ($total && !exists($users{$uname})) {
+ $nouname ++;
+ } else {
+ $hasuname ++;
+ }
my $id = $entry->get_value('uidNumber');
my $type = $entry->get_value('employeeType');
unless (($type eq 'Faculty') || ($type eq 'Staff')) {
@@ -2025,11 +2087,16 @@
$name =~ s/\Q$last\E$//;
}
$name =~ s/^\s+|\s+$//g;
- my $middle;
- if (($name ne '') && ($type ne 'Student') && ($name !~ /\s/) && (length($first) > 1)) {
- $middle = substr($name, 0, 1);
- } else {
- $middle = $name;
+ my $middle = $name;
+ if (($first ne '') && ($first eq $middle)) {
+ $middle = '';
+ } elsif ($first =~ /^([\w-]+)\s+(\w+)/) {
+ if ((length($1) > 1) || (length($2) > 1)) {
+ $middle = '';
+ }
+ }
+ if (($middle ne '') && ($type ne 'Student') && ($middle !~ /\s/) && (length($first) > 1)) {
+ $middle = substr($middle, 0, 1);
}
foreach my $item ($first,$middle) {
next if ($item eq '');
@@ -2059,6 +2126,11 @@
}
$count ++;
}
+ if (ref($counts) eq 'HASH') {
+ $counts->{'ldap_dump'} = $count;
+ $counts->{'ldap_nouname'} = $nouname;
+ $counts->{'ldap_hasuname'} = $hasuname;
+ }
$ldap->unbind;
}
return $outcome;
More information about the LON-CAPA-cvs
mailing list