[LON-CAPA-cvs] cvs: loncom /enrollment Autoupdate.pl

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 04 Jun 2007 14:13:10 -0000


raeburn		Mon Jun  4 10:13:10 2007 EDT

  Modified files:              
    /loncom/enrollment	Autoupdate.pl 
  Log:
  - Include permanentemail in fields to retrieve from user's environment.db
  - Get all courseIDs for domain - exclude these from users to check
  - classlists toggle in domain configuration is 1 or 0 (not yes/no)
  - is_course() was moved from loncommon to lonnet
  - include permenentemail in fields sent to modifyuser
  - write outcomes to log file
  
  
Index: loncom/enrollment/Autoupdate.pl
diff -u loncom/enrollment/Autoupdate.pl:1.8 loncom/enrollment/Autoupdate.pl:1.9
--- loncom/enrollment/Autoupdate.pl:1.8	Tue May 29 17:09:47 2007
+++ loncom/enrollment/Autoupdate.pl	Mon Jun  4 10:13:08 2007
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 # Automated Userinfo update script
-# $Id: Autoupdate.pl,v 1.8 2007/05/29 21:09:47 raeburn Exp $
+# $Id: Autoupdate.pl,v 1.9 2007/06/04 14:13:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,7 +38,7 @@
     my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoupdate.log';
     my $hostid = $perlvarref->{'lonHostID'}; 
     my @info = ('inststatus','lockedname','internalname','lastname',
-                'firstname','id');
+                'firstname','id','permanentemail');
     # Initialize language handler
     &Apache::lonlocal::get_language_handle();
     # find out which users we need to examine
@@ -62,6 +62,8 @@
         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,'.','.','',undef,undef,'.');
         # get user information
         my (%instusers,%instids);
         next if (&localenroll::allusers_info($dom,\%instusers,\%instids) ne 'ok');
@@ -72,6 +74,7 @@
         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'}) {
@@ -106,14 +109,14 @@
                     foreach my $field (@fields) { 
                         if ($userhash{$field} ne $instusers{$uname}{$field}) {
                             $changed = 1;
-                            if ($settings->{'classlists'} eq 'yes') { 
+                            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) {
@@ -121,9 +124,10 @@
                         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);
+                        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') {
-                            if ($settings->{'classlists'} eq 'yes') {
+                            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,
@@ -131,12 +135,19 @@
                                     foreach my $item (%roleshash) {
                                         my ($cnum,$cdom,$role) = split(/:/,$item);
                                         my ($start,$end) = split(/:/,$roleshash{$item});
-                                        if (&Apache::loncommon::is_course($cdom,$cnum)) {
+                                        if (&Apache::lonnet::is_course($cdom,$cnum)) {
                                             my $result = &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 {
@@ -164,7 +175,7 @@
                 print $fh (&mt('Possible username change to [_1] detected for [_2] in domain [_3].',$altnames,$uname,$dom)."\n");
             }
         }
-        print $fh ("-- ".&Apache::lonlocal::locallocaltime(time).' '.&mt('Autoupdate messages end')."\n*******************\n\n");
+        print $fh ("-- \n".&Apache::lonlocal::locallocaltime(time).' '.&mt('Autoupdate messages end')."\n*******************\n\n");
         close($fh);
     }
 
@@ -179,10 +190,7 @@
             if ($depth < 4) {
                 &descend_tree($dir.'/'.$item,$depth,$alldomusers);
             } else {
-                if (-e $dir.'/'.$item.'/environment.db') {
-                    
-                    $$alldomusers{$item} = '';
-                }
+                $$alldomusers{$item} = '';
             }
         }
     }