[LON-CAPA-cvs] cvs: loncom /interface loncoursegroups.pm longroup.pm rat map.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 04 Dec 2006 14:59:58 -0000


This is a MIME encoded message

--raeburn1165244398
Content-Type: text/plain

raeburn		Mon Dec  4 09:59:58 2006 EDT

  Modified files:              
    /rat	map.pm 
    /loncom/interface	loncoursegroups.pm longroup.pm 
  Log:
  Checking for existence of allgroups_folder.sequence uses map.pm to check the file system instead of using navmap object to check current user's session.
  
  Locking added while allgroups_folder.sequence is being added, to avoid contention between two CCs adding the first group to a course at the same time.
  
  rat::loadmap() now checks for a return value of -1, as lonnet::getfile() returns -1 when the file is missing.  Not sure when the existing branch (checks for -2) is triggered.
  
  
--raeburn1165244398
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061204095958.txt"

Index: rat/map.pm
diff -u rat/map.pm:1.1 rat/map.pm:1.2
--- rat/map.pm:1.1	Thu Aug 17 18:35:51 2006
+++ rat/map.pm	Mon Dec  4 09:59:55 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # routines for modyfing .sequence and .page files
 #
-# $Id: map.pm,v 1.1 2006/08/17 22:35:51 albertel Exp $
+# $Id: map.pm,v 1.2 2006/12/04 14:59:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -475,6 +475,8 @@
     }
     if ($instr eq -2) {
         $errtext.='Map not loaded: An error occured while trying to load the map.';
+    } elsif ($instr eq '-1') {
+        $errtext.=&mt('Map not loaded: The file [_1] does not exist.',$fn);
     } elsif ($instr) {
         my $parser = HTML::TokeParser->new(\$instr);
         my $token;
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.66 loncom/interface/loncoursegroups.pm:1.67
--- loncom/interface/loncoursegroups.pm:1.66	Tue Nov 28 16:38:04 2006
+++ loncom/interface/loncoursegroups.pm	Mon Dec  4 09:59:56 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.66 2006/11/28 21:38:04 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.67 2006/12/04 14:59:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3139,7 +3139,7 @@
                                            $description,$tools,\%groupinfo,
                                            $gpterm,$ucgpterm,$crstype);
             if ($result ne 'ok') {
-                $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].<br />',$gpterm,$result));
+                $r->print(&mt('A problem occurred when creating folders for the new [_1].<br/>[_2]<br />',$gpterm,$result));
             }
             $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
         } elsif ($action eq 'modify') {
@@ -3673,28 +3673,38 @@
     if ($cdom eq '' || $cnum eq '') {
         return &mt('Error: invalid course domain or number - group folder creation failed');  
     }
-    my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
-    my $navmap = Apache::lonnavmaps::navmap->new();
+    my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
     my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
     $allgrpsmap = $crspath.'group_allfolders.sequence';
-    my $topmap = $navmap->getResourceByUrl($allgrpsmap);
-    undef($navmap);
     if ($action eq 'create') {
-    # check if group_allfolders.sequence exists.
-        if (!$topmap) {
-            my $grpstitle = &mt('[_1] [_2]s',$crstype,$ucgpterm);
-            my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
-            $topmap_url =~ s|/+|/|g;
-            if ($topmap_url =~ m|^/uploaded|) {
-                $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
-                                        'toplevelgroup',$grpstitle,$topmap_url);
+        if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
+            # check if group_allfolders.sequence exists.
+            my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
+            if ($fatal == 2) { #file does not exist;
+                my $grpstitle = &mt('[_1] [_2]s',$crstype,$ucgpterm);
+                my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
+                $topmap_url =~ s|/+|/|g;
+                if ($topmap_url =~ m|^/uploaded|) {
+                    $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
+                                            'toplevelgroup',$grpstitle,$topmap_url);
+                } else {
+                    $outcome = &mt('Non-standard course - folder for all groups not added.');
+                }
                 if ($outcome ne 'ok') {
+                    my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
+                    if ($delresult ne 'ok') {
+                        $warning = $delresult;
+                    }
                     return $outcome;
                 }
-            } else {
-                $outcome = &mt('Non-standard course - folder for all groups not added.');
-                return $outcome;
             }
+            my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
+            if ($delresult ne 'ok') {
+                $warning = $delresult ;
+            }
+        } else {
+            $outcome = &mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.');
+            return $outcome;
         }
         my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
         $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
@@ -3704,7 +3714,7 @@
                                    'grpseq',$grpfolder,$allgrpsmap,$grppage,
                                    $grptitle);
         if ($outcome ne 'ok') {
-            return $outcome;
+            return $outcome.$warning;
         }
         my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
                                        $tools,$gpterm,$ucgpterm,$now);
@@ -3715,7 +3725,7 @@
             my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
                                        '.sequence','bbseq',$disctitle,$grpmap);
             if ($outcome ne 'ok') {
-                return $outcome;
+                return $outcome.$warning;
             }
             $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
         }
@@ -3723,7 +3733,7 @@
         #modify group folder if status of discussions tools is changed
     }
     my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
-    $navmap = Apache::lonnavmaps::navmap->new();
+    my $navmap = Apache::lonnavmaps::navmap->new();
     # modify parameters
     my $parm_result;
     if ($action eq 'create') {
@@ -3737,8 +3747,39 @@
             $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
         }
     }
+    undef($navmap);
     if ($parm_result) {
-        return $parm_result;
+        return $warning.$parm_result;
+    } else {
+        return 'ok';
+    }
+}
+
+sub get_folder_lock {
+    my ($cdom,$cnum,$folder_name,$now) = @_;  
+    # get lock for folder being edited.
+    my $lockhash = {
+                  $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
+                                                     ':'.$env{'user.domain'},
+                   };
+    my $tries = 0;
+    my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
+
+    while (($gotlock ne 'ok') && $tries <3) {
+        $tries ++;
+        sleep 1;
+        $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
+    }
+    return $gotlock;
+}
+
+sub release_folder_lock {
+    my ($cdom,$cnum,$folder_name) = @_;  
+    #  remove lock
+    my @del_lock = ($folder_name."\0".'locked_folder');
+    my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
+    if ($dellockoutcome ne 'ok') {
+        return ('<br />'.&mt('Warning: failed to release lock for folder: [_1].',$folder_name).'<br />'); 
     } else {
         return 'ok';
     }
@@ -3755,7 +3796,7 @@
     if ($newmapurl !~ m|^/uploaded|) {
         $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
         return $outcome;
-    } 
+    }
     my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
     if ($fatal) {
         $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
@@ -3766,7 +3807,7 @@
                                                  ':false:normal:res';
         $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
         my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
-        if ($outtext) {
+        if ($errtext) {
             $outcome = &mt('Error storing updated parent folder')." ($parentmap):  $errtext".'<br />';
             return $outcome;
         }
@@ -3801,18 +3842,23 @@
                                         },
                         );
     my $res = $navmap->getResourceByUrl($url);
-    my $symb = $res->symb();
-    foreach my $level (keys(%hide_settings)) {
-        my $parmresult =  &Apache::lonparmset::storeparm_by_symb($symb,
+    if ($res) {
+        my $symb = $res->symb();
+        foreach my $level (keys(%hide_settings)) {
+            my $parmresult =  
+                       &Apache::lonparmset::storeparm_by_symb($symb,
                                                  '0_hiddenresource',
                                                  $hide_settings{$level}{'num'},
                                                  $hide_settings{$level}{'set'},
                                                  'string_yesno',undef,$cdom,
                                                  undef,undef,
                                                  $hide_settings{$level}{'extra'});
-        if ($parmresult) {
-            $allresults .= $level.': '.$parmresult;
+            if ($parmresult) {
+                $allresults .= $level.': '.$parmresult;
+            }
         }
+    } else {
+        $allresults = &mt('Parameters not set for [_1] because the resource was not recognized as part of the course',$url).'<br />';
     }
     return $allresults;
 }
Index: loncom/interface/longroup.pm
diff -u loncom/interface/longroup.pm:1.13 loncom/interface/longroup.pm:1.14
--- loncom/interface/longroup.pm:1.13	Tue Nov 28 14:46:00 2006
+++ loncom/interface/longroup.pm	Mon Dec  4 09:59:56 2006
@@ -81,6 +81,9 @@
 	undef(%groups);
         &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace);
     }
+    if (defined($groups{'group_allfolders'."\0".'locked_folder'})) {
+        delete($groups{'group_allfolders'."\0".'locked_folder'}); 
+    }
     return %groups;
 }
 

--raeburn1165244398--