--- loncom/enrollment/Autoupdate.pl 2007/02/26 20:52:55 1.2 +++ loncom/enrollment/Autoupdate.pl 2007/05/29 20:43:17 1.6 @@ -1,6 +1,7 @@ #!/usr/bin/perl # # Automated Userinfo update script +# $Id: Autoupdate.pl,v 1.6 2007/05/29 20:43:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,12 +30,24 @@ use localenroll; use Apache::lonnet; use Apache::loncommon; + use Apache::lonlocal; + use LONCAPA::Configuration; use LONCAPA; - my @info = ('inststatus','lockedname','lastname','firstname','id'); + my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); + my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoupdate.log'; + my $hostid = $perlvarref->{'lonHostID'}; + my @info = ('inststatus','lockedname','internalname','lastname', + 'firstname','id'); + # 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 $primaryhost_id = &Apache::lonnet::domain($dom,'primary'); + if ($primaryhost_id ne $hostid) { + next; + } my %domconfig = &Apache::lonnet::get_dom('configuration',['autoupdate'], $dom); #only run if configured to @@ -47,6 +60,8 @@ } } next if (!$run_update); + open (my $fh,">>$logfile"); + print $fh "********************\n".localtime(time).' '.&mt('Autoupdate messages start for domain: [_1]',$dom).' --'."\n"; # get user information my (%instusers,%instids); next if (&localenroll::allusers_info($dom,\%instusers,\%instids) ne 'ok'); @@ -112,7 +127,7 @@ if ($changes{'id'} || $changes{'fullname'}) { my %roleshash = &Apache::lonnet::get_my_roles($uname, - $dom,\@types,\@roles,\@cdoms); + $dom,'userroles',\@types,\@roles,\@cdoms); foreach my $item (%roleshash) { my ($cnum,$cdom,$role) = split(/:/,$item); my ($start,$end) = split(/:/,$roleshash{$item}); @@ -136,15 +151,23 @@ } 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 "-- ".localtime(time).' '.&mt('Autoupdate messages end')."\n*******************\n\n"; + close($fh); } - sub descend_tree { my ($dir,$depth,$alldomusers) = @_; if (-d $dir) {