[LON-CAPA-cvs] cvs: modules /msu localenroll.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 11 Mar 2004 22:00:04 -0000


raeburn		Thu Mar 11 17:00:04 2004 EDT

  Modified files:              
    /modules/msu	localenroll.pm 
  Log:
  Protection against receipt of bad data from SQL queries of LONCAPA_ClassList table in RO_ClassList database on esdb1.ais.msu.edu.
  There have been instances where SQL queries have returned a single record with no data, instead of either zero records or real student data. localenroll:fetchenrollment() will now try 5 times for each course to get good data before moving on to the next course.
  
  
Index: modules/msu/localenroll.pm
diff -u modules/msu/localenroll.pm:1.5 modules/msu/localenroll.pm:1.6
--- modules/msu/localenroll.pm:1.5	Wed Jan  7 22:38:08 2004
+++ modules/msu/localenroll.pm	Thu Mar 11 17:00:04 2004
@@ -14,7 +14,15 @@
   if ($dbflag) {
      foreach my $crs (sort keys %{$affiliatesref}) {
          my $xmlstem =  $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_";
-         $$replyref{$crs} = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
+         my $pilotcount = 0;
+         my $blankcount = 1;
+         my $maxtries = 5;
+         my $numtries = 0;
+         while ( ($numtries < $maxtries) && ($blankcount > 0) ) {
+             ($pilotcount,$blankcount) = &write_class_data ($dbh,$xmlstem,\@{$$affiliatesref{$crs}});
+             $numtries ++;
+         }
+         $$replyref{$crs} = $pilotcount;
      }
      &disconnect_DB($dbh);
   }
@@ -59,7 +67,8 @@
 
 sub write_class_data {
   my ($dbh,$xmlstem,$coursesref) = @_;
-  my $stucount = 0;
+  my $pilotcount = 0;
+  my $blankcount = 0;
   foreach my $class (@{$coursesref}) {
       if ($class =~ m/^([suf]s\d{2})(\w{2,3})(\d{3,4}\w?)(\d{3})$/) {
           my $xmlfile = $xmlstem.$class."_classlist.xml";
@@ -71,22 +80,23 @@
           my $sth = $dbh->prepare("SELECT Pid,Pilot_Id,Student_Name FROM LONCAPA_ClassList WHERE Term_Code = '$1' AND Subj_Code = '$2' AND Crse_Code = '$3' AND Sctn_Code = '$4'  ORDER BY Student_Name");
           $sth->execute();
           while ( my($pid,$pilot,$name)  = $sth->fetchrow_array ) {
-              $stucount ++;
-              $name =~ s/^\s//g;
-              $name =~ s/\s$//g;
-              my ($last,$given,$first,$middle);
-              $last = substr($name,0,index($name,","));
-              $given = substr($name,index($name,",")+1);
-              $given =~ s/^\s//g;
-              if ($given =~ m/\w\s\w/) {
-                  $first = substr($given,0,index($given," "));
-                  $middle = substr($given,index($given," ")+1);
-                  $middle =~ s/\s//g;
-              } else {
-                  $first = $given;
-              }
-              $first =~ s/\s$//g;
-              print FILE qq| <student username="$pilot">
+              if ($pilot =~ m/^\w{1,8}$/) {
+                  $pilotcount ++;
+                  $name =~ s/^\s//g;
+                  $name =~ s/\s$//g;
+                  my ($last,$given,$first,$middle);
+                  $last = substr($name,0,index($name,","));
+                  $given = substr($name,index($name,",")+1);
+                  $given =~ s/^\s//g;
+                  if ($given =~ m/\w\s\w/) {
+                      $first = substr($given,0,index($given," "));
+                      $middle = substr($given,index($given," ")+1);
+                      $middle =~ s/\s//g;
+                  } else {
+                      $first = $given;
+                  }
+                  $first =~ s/\s$//g;
+                  print FILE qq| <student username="$pilot">
   <autharg>MSU.EDU</autharg>
   <authtype>krb4</authtype>
   <email>$pilot\@msu.edu</email>
@@ -100,6 +110,9 @@
   <studentID>$pid</studentID>
  </student>
 |;
+              } elsif ($pilot eq '') {
+                  $blankcount ++;
+              }
 # Format for startdate is YYYY:MM:DD:HH:MM:SS
 # Format forenddate is YYYY:MM:DD:HH:MM:SS
 # Authentication is one of: krb4, krb5, int or loc
@@ -111,7 +124,7 @@
           close(FILE);
       }
   }
-  return $stucount;
+  return ($pilotcount,$blankcount);
 }
 
 sub get_sections {