File:
[LON-CAPA] /
loncom /
enrollment /
Autoupdate.pl
Revision
1.11:
download - view:
text,
annotated -
select for diffs
Thu Nov 15 21:24:56 2007 UTC (16 years, 9 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_X,
version_2_6_99_1,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_99_1,
version_2_5_99_0,
HEAD
Propagating changes in ID made by Domain Coordinator to classlist.db file in any courses in which user has active or future student roles. Update name changes too.
loncommon.pm
- Pass ref to %got_rules to &user_rule_check(), so retrieval of rules only occurs once per domain. Retrieve rules for both username and ID
- &instrule_disallow_msg() takes a fourth argument ($mode) so message is different for messages generated for uploaded CSV file of users and single user modification.
loncreateuser.pm
- Propagate name changes and ID change to courses if Domain Coordinator is updating user data.
- Only display permanent e-mail on results page (no personal data changes) if one is defined.
- &print_user_modification_page() takes additional argument - $context - if domain adds the checkbox to force an ID change.
lonuserutils.pm
- check for $context was mistakenly checking $setting
- check whether Domain Coordinator wishes to change authentication for existing users should be $checkauth eq 'Yes'
- propagate name changes and ID change to courses if Domain Coordinator is updating user data, and had checked boxes for force ID change, and force course changes
- &update_classlist() moved to lonuserutils.pm from Autoupdate.pl
- &propagate_id_change() added to propagate ID and name changes to courses
- include cr (for Custom role) in option for Course roles for DC when setting filters for user lists.
- summary of filters used (displayed above tabular data) is customized to be an appropriate message for the choice of filters used in all cases.
- &Apache::lonnet::flushcourselogs() after processing adds/modifications in CSV file of users called in all contexts.
Autoupdate.pl
- &update_classlist() moved to lonuserutils.pm
#!/usr/bin/perl
#
# Automated Userinfo update script
# $Id: Autoupdate.pl,v 1.11 2007/11/15 21:24:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY 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 LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
use strict;
use lib '/home/httpd/lib/perl';
use localenroll;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::lonuserutils();
use LONCAPA::Configuration;
use LONCAPA;
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoupdate.log';
my $hostid = $perlvarref->{'lonHostID'};
if (!&Apache::lonnet::is_library($hostid)) {
exit;
}
my @info = ('inststatus','lockedname','internalname','lastname',
'firstname','id','permanentemail');
# Initialize language handler
&Apache::lonlocal::get_language_handle();
# find out which users we need to examine
my @domains = sort(&Apache::lonnet::current_machine_domains());
foreach my $dom (@domains) {
my %domconfig = &Apache::lonnet::get_dom('configuration',['autoupdate'],
$dom);
#only run if configured to
my $run_update = 0;
my $settings;
if (ref($domconfig{'autoupdate'}) eq 'HASH') {
$settings = $domconfig{'autoupdate'};
if ($settings->{'run'} eq '1') {
$run_update = 1;
}
}
next if (!$run_update);
open(my $fh,">>$logfile");
print $fh ("********************\n".localtime(time).' '.&mt('Autoupdate messages start for domain: [_1]',$dom).' --'."\n");
# get courseIDs for domain
my %courses=&Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,[$hostid],'.');
# get user information
my (%instusers,%instids);
next if (&localenroll::allusers_info($dom,\%instusers,\%instids) ne 'ok');
my (%users,%unamechg,%possnames);
my @types = ('active','future');
my @roles = ('st');
my @cdoms = ($dom);
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom;
&descend_tree($dir,0,\%users);
foreach my $uname (keys(%users)) {
next if ($courses{$dom.'_'.$uname});
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info);
my (@inststatuses);
if (!$userhash{'internalname'}) {
if (defined($instusers{$uname})) {
(my $insttypechg,@inststatuses) =
&affiliations_check(\%userhash,$instusers{$uname});
if ($insttypechg) {
my $inststatusstr = join(':',&escape(@inststatuses));
my %statushash = ( inststatus => $inststatusstr );
my $statusres = &Apache::lonnet::put('environment',\%statushash,$dom,$uname);
}
}
}
if (!$userhash{'lockedname'} && !$userhash{'internalname'}) {
if (defined($instusers{$uname})) {
my (@fields,%changes,$changed);
if (@inststatuses > 0) {
foreach my $type (@inststatuses) {
if (ref($settings->{fields}{$type}) eq 'ARRAY') {
foreach my $field (@{$settings->{fields}{$type}}) {
if (!grep(/^\Q$field\E$/,@fields)) {
push(@fields,$field);
}
}
}
}
} else {
if (ref($settings->{fields}{'default'}) eq 'ARRAY') {
@fields = @{$settings->{fields}{'default'}};
}
}
foreach my $field (@fields) {
if ($userhash{$field} ne $instusers{$uname}{$field}) {
$changed = 1;
if ($settings->{'classlists'} == 1) {
if ($field eq 'id') {
$changes{'id'} = 1;
} elsif ($field eq 'lastname' || $field eq 'firstname' || $field eq 'middlename' || $field eq 'gen') {
$changes{'fullname'} = 1;
}
}
}
}
# Make the change
if ($changed) {
my %userupdate;
foreach my $field (@fields) {
$userupdate{$field} = $instusers{$uname}{$field};
}
my $modresult = &Apache::lonnet::modifyuser($dom,$uname,$userupdate{'id'},undef,undef,$userupdate{'firstname'},$userupdate{'middlename'},$userupdate{'lastname'},$userupdate{'generation'},1,$hostid,$userupdate{'permanentemail'});
if ($modresult eq 'ok') {
print $fh "User change: $uname:$dom; New values: 1.Name: $userupdate{'firstname'} $userupdate{'middlename'} $userupdate{'lastname'} $userupdate{'generation'}; 2. StuID: $userupdate{'id'}; 3. Email: $userupdate{'permanentemail'}.\n";
if ($settings->{'classlists'} == 1) {
if ($changes{'id'} || $changes{'fullname'}) {
my %roleshash =
&Apache::lonnet::get_my_roles($uname,
$dom,'userroles',\@types,\@roles,\@cdoms);
foreach my $item (keys(%roleshash)) {
my ($cnum,$cdom,$role) = split(/:/,$item);
my ($start,$end) = split(/:/,$roleshash{$item});
if (&Apache::lonnet::is_course($cdom,$cnum)) {
my $result =
&Apache::lonuserutils::update_classlist($cdom,$cnum,$dom,$uname,\%userupdate);
if ($result eq 'ok') {
print $fh "Classlist change: $uname:$dom - class -> $cnum:$cdom\n";
} else {
print $fh "Error - $result -during classlist update for $uname:$dom in $cnum:$cdom\n";
}
}
}
}
}
} else {
print $fh "User change detected for $uname:$dom. Error during update: $modresult\n";
}
}
} else {
# check if the username has changed
if (defined($instids{$userhash{'id'}})) {
if (ref($instids{$userhash{'id'}}) eq 'ARRAY') {
foreach my $name (@{$instids{$userhash{'id'}}}) {
if (!exists($users{$name})) {
push(@{$possnames{$uname}},$name);
}
}
} else {
if (!exists($users{$instids{$userhash{'id'}}})) {
$unamechg{$uname} = $instids{$userhash{'id'}};
print $fh (&mt('Username change to [_1] detected for [_2] in domain [_3].',$unamechg{$uname},$uname,$dom)."\n");
}
}
}
}
}
}
if (keys(%possnames) > 0) {
foreach my $uname (keys(%possnames)) {
my $altnames = join(' or ',@{$possnames{$uname}});
print $fh (&mt('Possible username change to [_1] detected for [_2] in domain [_3].',$altnames,$uname,$dom)."\n");
}
}
print $fh ("-- \n".&Apache::lonlocal::locallocaltime(time).' '.&mt('Autoupdate messages end')."\n*******************\n\n");
close($fh);
}
sub descend_tree {
my ($dir,$depth,$alldomusers) = @_;
if (-d $dir) {
opendir(DIR,$dir);
my @contents = grep(!/^\./,readdir(DIR));
closedir(DIR);
$depth ++;
foreach my $item (@contents) {
if ($depth < 4) {
&descend_tree($dir.'/'.$item,$depth,$alldomusers);
} else {
$$alldomusers{$item} = '';
}
}
}
}
sub affiliations_check {
my ($userhash,$insthashref) = @_;
my (@inststatuses,$insttypechg);;
if (ref($insthashref) eq 'HASH') {
if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
@inststatuses = @{$insthashref->{'inststatus'}};
}
}
my @currstatuses = &unescape(split(/:/,$userhash->{'inststatus'}));
foreach my $status (@inststatuses) {
if (!grep/^\Q$status\E/,@currstatuses) {
$insttypechg = 1;
}
}
if (!$insttypechg) {
foreach my $status (@currstatuses) {
if (!grep/^\Q$status\E/,@inststatuses) {
$insttypechg = 1;
}
}
}
return ($insttypechg,@inststatuses);
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>