[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm

raeburn raeburn@source.lon-capa.org
Fri, 19 Dec 2008 20:51:36 -0000


raeburn		Fri Dec 19 20:51:36 2008 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  - Check that navmap object could be created to avoid ISE.
    - Log to lonnet.log if navmap object undefined.
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.168 loncom/interface/lonhelper.pm:1.169
--- loncom/interface/lonhelper.pm:1.168	Thu Dec 11 14:55:15 2008
+++ loncom/interface/lonhelper.pm	Fri Dec 19 20:51:35 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.168 2008/12/11 14:55:15 bisitz Exp $
+# $Id: lonhelper.pm,v 1.169 2008/12/19 20:51:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3648,10 +3648,16 @@
         $paramlevel = 'general';
     } elsif ($vars->{GRANULARITY} eq 'map') {
         my $navmap = Apache::lonnavmaps::navmap->new();
-        my $res = $navmap->getByMapPc($vars->{RESOURCE_ID});
-        my $title = $res->compTitle();
-        $symb = $res->symb();
-        $resourceString .= '<li>'.&mt('for the map named [_1]',"<b>$title</b>").'</li>';
+        if (defined($navmap)) {
+             my $res = $navmap->getByMapPc($vars->{RESOURCE_ID});
+             my $title = $res->compTitle();
+             $symb = $res->symb();
+             $resourceString .= '<li>'.&mt('for the map named [_1]',"<b>$title</b>").'</li>';
+        } else {
+            $resourceString .= '<li>'.&mt('for the map ID [_1] (name unavailable)','<b>'.$vars->{RESOURCE_ID}.'</b>').'</li>';
+            &Apache::lonnet::logthis('Retrieval of map title failed in lonhelper.pm - could not create navmap object for course.');
+
+        }
 	if ($vars->{TARGETS} eq 'course') {
 	    $level = 13; # general course, see lonparmset.pm perldoc
 	} elsif ($vars->{TARGETS} eq 'section') {
@@ -3664,13 +3670,18 @@
         $affectedResourceId = $vars->{RESOURCE_ID};
         $paramlevel = 'map';
     } else {
-        my $navmap = Apache::lonnavmaps::navmap->new();
-        my $res = $navmap->getById($vars->{RESOURCE_ID});
         my $part = $vars->{RESOURCE_ID_part};
 	if ($part ne 'All Parts' && $part) { $parm_name=~s/^0/$part/; } else { $part=&mt('All Parts'); }
-        $symb = $res->symb();
-        my $title = $res->compTitle();
-        $resourceString .= '<li>'.&mt('for the resource named [_1] part [_2]',"<b>$title</b>","<b>$part</b>").'</li>';
+        my $navmap = Apache::lonnavmaps::navmap->new();
+        if (defined($navmap)) {
+            my $res = $navmap->getById($vars->{RESOURCE_ID});
+            $symb = $res->symb();
+            my $title = $res->compTitle();
+            $resourceString .= '<li>'.&mt('for the resource named [_1] part [_2]',"<b>$title</b>","<b>$part</b>").'</li>';
+        } else {
+            $resourceString .= '<li>'.&mt('for the resource ID [_1] (name unavailable) part [_2]','<b>'.$vars->{RESOURCE_ID}.'</b>',"<b>$part</b>").'</li>';
+            &Apache::lonnet::logthis('Retrieval of resource title failed in lonhelper.pm - could not create navmap object for course.');
+        }
 	if ($vars->{TARGETS} eq 'course') {
 	    $level = 10; # general course, see lonparmset.pm perldoc
 	} elsif ($vars->{TARGETS} eq 'section') {