[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonprintout.pm /lonnet/perl lonnet.pm

www lon-capa-cvs-allow@mail.lon-capa.org
Fri, 28 Mar 2008 14:52:58 -0000


www		Fri Mar 28 10:52:58 2008 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonprintout.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Saving my work, bug #5631. This might not work at all yet.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.649 loncom/interface/loncommon.pm:1.650
--- loncom/interface/loncommon.pm:1.649	Sun Mar 23 21:11:36 2008
+++ loncom/interface/loncommon.pm	Fri Mar 28 10:52:52 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.649 2008/03/24 01:11:36 www Exp $
+# $Id: loncommon.pm,v 1.650 2008/03/28 14:52:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -133,6 +133,9 @@
     do {
 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
 	$ok      = $response->is_success;
+        if (!$ok) {
+            &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
+        }
 	$retries--;
     } while (!$ok && ($retries > 0));
 
@@ -3139,7 +3142,7 @@
   }
   if (defined($target)) { $form{'grade_target'} = $target; }
   $feedurl=&Apache::lonnet::clutter($feedurl);
-  my $userview=&Apache::lonnet::ssi_body($feedurl,%form);
+  my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
   $userview=~s/\<body[^\>]*\>//gi;
   $userview=~s/\<\/body\>//gi;
   $userview=~s/\<html\>//gi;
@@ -3148,7 +3151,35 @@
   $userview=~s/\<\/head\>//gi;
   $userview=~s/action\s*\=/would_be_action\=/gi;
   $userview=&relative_to_absolute($feedurl,$userview);
-  return $userview;
+  if (wantarray) {
+     return ($userview,$response);
+  } else {
+     return $userview;
+  }
+}
+
+sub get_student_view_with_retries {
+  my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
+
+    my $ok = 0;                 # True if we got a good response.
+    my $content;
+    my $response;
+
+    # Try to get the student_view done. within the retries count:
+    
+    do {
+         ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
+         $ok      = $response->is_success;
+         if (!$ok) {
+            &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
+         }
+         $retries--;
+    } while (!$ok && ($retries > 0));
+    
+    if (!$ok) {
+       $content = '';          # On error return an empty content.
+    }
+    return ($content, $response);
 }
 
 =pod
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.523 loncom/interface/lonprintout.pm:1.524
--- loncom/interface/lonprintout.pm:1.523	Mon Mar 24 14:22:36 2008
+++ loncom/interface/lonprintout.pm	Fri Mar 28 10:52:52 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.523 2008/03/24 18:22:36 raeburn Exp $
+# $Id: lonprintout.pm,v 1.524 2008/03/28 14:52:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -158,6 +158,22 @@
 
 }
 
+sub get_student_view_with_retries {
+    my ($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv)=@_;
+
+    my ($content, $response) = &Apache::loncommon::get_student_view_with_retries($curresline,$retries,$username,$userdomain,$courseid,$target,$moreenv);
+    if (!$response->is_success) {
+        $ssi_error               = 1;
+        $ssi_last_error_resource = $curresline;
+        $ssi_last_error          = $response->code . " " . $response->message;
+
+        &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error");
+    }
+
+    return $content;
+
+}
+
 #
 #   printf_style_subst  item format_string repl
 #  
@@ -2271,7 +2287,7 @@
 
 		    &Apache::lonxml::remember_problem_counter();    
 
-		    my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
+		    my $rendered = &Apache::loncommon::get_student_view_with_retries($curresline,3,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
 
 		    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
 		       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.952 loncom/lonnet/perl/lonnet.pm:1.953
--- loncom/lonnet/perl/lonnet.pm:1.952	Mon Mar 24 01:23:19 2008
+++ loncom/lonnet/perl/lonnet.pm	Fri Mar 28 10:52:57 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.952 2008/03/24 05:23:19 raeburn Exp $
+# $Id: lonnet.pm,v 1.953 2008/03/28 14:52:57 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1693,12 +1693,21 @@
     if (! exists($form{'LONCAPA_INTERNAL_no_discussion'})) {
         $form{'LONCAPA_INTERNAL_no_discussion'}='true';
     }
-    my $output=($filelink=~/^http\:/?&externalssi($filelink):
-                                     &ssi($filelink,%form));
+    my $output='';
+    my $response;
+    if ($filelink=~/^http\:/) {
+       $output=&externalssi($filelink);
+    } else {
+       ($output,$response)=&ssi($filelink,%form);
+    }
     $output=~s|//(\s*<!--)? BEGIN LON-CAPA Internal.+?// END LON-CAPA Internal\s*(-->)?\s||gs;
     $output=~s/^.*?\<body[^\>]*\>//si;
     $output=~s/\<\/body\s*\>.*?$//si;
-    return $output;
+    if (wantarray) {
+        return ($output, $response);
+    } else {
+        return $output;
+    }
 }
 
 # --------------------------------------------------------- Server Side Include