[LON-CAPA-cvs] cvs: loncom /interface groupboards.pm loncoursegroups.pm /lonnet/perl lonnet.pm /misc refresh_courseids_db.pl rat map.pm

raeburn raeburn at source.lon-capa.org
Sat Jul 21 17:20:25 EDT 2012


raeburn		Sat Jul 21 21:20:25 2012 EDT

  Modified files:              
    /loncom/interface	groupboards.pm loncoursegroups.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /rat	map.pm 
    /loncom/misc	refresh_courseids_db.pl 
  Log:
  - course's environment now has: internal.contentchange to store timestamp
    of when folders/composite pages uploaded to main content area of a  
    course last changed.
  - map::storemap() includes additional (third) arg -- if true, will cause
    update to internal.contentchange in course's environment.db
  - internal.contentchange is also updated by nightly run of refresh_courseids.db
    in case course modification occurred on pre-2.11 server.
  - internal.contentchange is stored for 10 mins in memcached, via &get_coursechange()
    routine in lonnet.pm
  
  
-------------- next part --------------
Index: loncom/interface/groupboards.pm
diff -u loncom/interface/groupboards.pm:1.14 loncom/interface/groupboards.pm:1.15
--- loncom/interface/groupboards.pm:1.14	Fri Feb 13 17:20:29 2009
+++ loncom/interface/groupboards.pm	Sat Jul 21 21:20:06 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Group Bulletin Boards Manager
 #
-# $Id: groupboards.pm,v 1.14 2009/02/13 17:20:29 bisitz Exp $
+# $Id: groupboards.pm,v 1.15 2012/07/21 21:20:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -251,7 +251,7 @@
             $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl.
                                                    ':false:normal:res';
             push(@LONCAPA::map::order,$newidx);
-            my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1);
+            my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1,1);
             if ($fatal) {
                 $outcome = "error: failed to save discussion boards map - $errtext\n";
             } else {
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.113 loncom/interface/loncoursegroups.pm:1.114
--- loncom/interface/loncoursegroups.pm:1.113	Sun Oct 23 00:04:51 2011
+++ loncom/interface/loncoursegroups.pm	Sat Jul 21 21:20:06 2012
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.113 2011/10/23 00:04:51 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.114 2012/07/21 21:20:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1276,7 +1276,7 @@
         $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
                                          ':false:normal:res';
         $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
-        my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
+        my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1,1);
         if ($errtext) {
             $outcome='<div class="LC_error">'
                     .&mt('An error occurred when saving updated parent folder to group:'
@@ -1341,7 +1341,7 @@
                     $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
                 }
                 $#LONCAPA::map::order--;
-                my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+                my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
                 if ($errtext) {
                     $outcome='<div class="LC_error">'
                             .&mt('An error occurred when saving updated parent folder to group:')
@@ -4033,7 +4033,7 @@
         $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
                                                  ':false:normal:res';
         $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
-        my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
+        my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1,1);
         if ($errtext) {
             $outcome = '<div class="LC_error">'
                       .&mt('Error saving updated parent folder.')." ($parentmap):  $errtext"
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1180 loncom/lonnet/perl/lonnet.pm:1.1181
--- loncom/lonnet/perl/lonnet.pm:1.1180	Tue Jul 17 14:49:32 2012
+++ loncom/lonnet/perl/lonnet.pm	Sat Jul 21 21:20:12 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1180 2012/07/17 14:49:32 droeschl Exp $
+# $Id: lonnet.pm,v 1.1181 2012/07/21 21:20:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9850,6 +9850,41 @@
     &devalidate_cache_new('allslots',$hashid);
 }
 
+sub get_coursechange {
+    my ($cdom,$cnum) = @_;
+    if ($cdom eq '' || $cnum eq '') {
+        return unless ($env{'request.course.id'});
+        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    }
+    my $hashid=$cdom.'_'.$cnum;
+    my ($change,$cached)=&is_cached_new('crschange',$hashid);
+    if ((defined($cached)) && ($change ne '')) {
+        return $change;
+    } else {
+        my %crshash;
+        %crshash = &get('environment',['internal.contentchange'],$cdom,$cnum);
+        if ($crshash{'internal.contentchange'} eq '') {
+            $change = $env{'course.'.$cdom.'_'.$cnum.'.internal.created'};
+            if ($change eq '') {
+                %crshash = &get('environment',['internal.created'],$cdom,$cnum);
+                $change = $crshash{'internal.created'};
+            }
+        } else {
+            $change = $crshash{'internal.contentchange'};
+        }
+        my $cachetime = 600;
+        &do_cache_new('crschange',$hashid,$change,$cachetime);
+    }
+    return $change;
+}
+
+sub devalidate_coursechange_cache {
+    my ($cnum,$cdom)=@_;
+    my $hashid=$cnum.':'.$cdom;
+    &devalidate_cache_new('crschange',$hashid);
+}
+
 # ------------------------------------------------- Update symbolic store links
 
 sub symblist {
Index: rat/map.pm
diff -u rat/map.pm:1.13 rat/map.pm:1.14
--- rat/map.pm:1.13	Thu Feb 12 11:35:10 2009
+++ rat/map.pm	Sat Jul 21 21:20:19 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # routines for modyfing .sequence and .page files
 #
-# $Id: map.pm,v 1.13 2009/02/12 11:35:10 raeburn Exp $
+# $Id: map.pm,v 1.14 2012/07/21 21:20:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -319,11 +319,11 @@
 # ------------------------------------------------------------------- Store map
 
 sub storemap {
-    my $realfn=shift;
+    my ($realfn,$useorig,$dotimeupdate) = @_;
     my $fn=$realfn;
 # unless this is forced to work from the original file, use a temporary file
 # instead
-    unless (shift) {
+    unless ($useorig) {
 	$fn=$realfn.'.tmp';
 	unless (-e $fn) {
 	    copy($realfn,$fn);
@@ -359,7 +359,7 @@
     }
     $output=~s/http\&colon\;\/\///g;
     $env{'form.output'}=$output;
-    return &loadmap($fn,&savemap($fn,''));
+    return &loadmap($fn,&savemap($fn,'',$dotimeupdate));
 }
 
 # ------------------------------------------ Store and get parameters in global
@@ -583,7 +583,7 @@
 # ----------------------------------------------------------- Saves map to disk
 
 sub savemap {
-    my ($fn,$errtext)=@_;
+    my ($fn,$errtext,$dotimeupdate)=@_;
     my $infotext='';
     my %alltypes;
     my %allvalues;
@@ -689,6 +689,19 @@
 		$errtext.='Could not write file '.$fn.'.  Map not saved. ';
 	    }
         }
+        if ($dotimeupdate) {
+            unless ($errtext) {
+                if ($env{'request.course.id'}) {
+                    my $now = time;
+                    &Apache::lonnet::put('environment',{'internal.contentchange' => $now},
+                                         $env{'course.'.$env{'request.course.id'}.'.domain'},
+                                         $env{'course.'.$env{'request.course.id'}.'.num'});
+                    &Apache::lonnet::appenv(
+                        {'course.'.$env{'request.course.id'}.'.internal.contentchange' => $now});
+                    &Apache::lonnet::do_cache_new('crschange',$env{'request.course.id'},$now,600);
+                }
+            }
+        }
     } else {
 # -------------------------------------------- Cannot write to that file, error
         $errtext.='Map not saved: The specified path does not exist. ';
Index: loncom/misc/refresh_courseids_db.pl
diff -u loncom/misc/refresh_courseids_db.pl:1.12 loncom/misc/refresh_courseids_db.pl:1.13
--- loncom/misc/refresh_courseids_db.pl:1.12	Sat Jul 21 20:18:37 2012
+++ loncom/misc/refresh_courseids_db.pl	Sat Jul 21 21:20:25 2012
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # The LearningOnline Network
 #
-# $Id: refresh_courseids_db.pl,v 1.12 2012/07/21 20:18:37 raeburn Exp $
+# $Id: refresh_courseids_db.pl,v 1.13 2012/07/21 21:20:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -242,6 +242,20 @@
                 }
 
                 unless ($chome eq 'no_host') {
+                    if (($lastaccess->{$cid} eq '') ||
+                        ($lastaccess->{$cid} > $twodaysago)) {
+                        my $contentchange;
+                        if ($courseinfo{'internal.created'} eq '') {
+                            $contentchange = &last_map_update($cnum,$cdom);
+                        } else {
+                            unless ($courseinfo{'internal.created'} > $lastaccess->{$cid}) {
+                                $contentchange = &last_map_update($cnum,$cdom);
+                            }
+                        }
+                        if (($contentchange) && ($contentchange > $courseinfo{'internal.contentchange'})) {
+                            $changes{'internal.contentchange'} = $contentchange;
+                        }
+                    }
                     $courseshash->{$chome}{$cid} = {
                         description => $courseinfo{'description'},
                         inst_code   => $inst_code,
@@ -489,3 +503,21 @@
     return $resourcedata;
 }
 
+sub last_map_update {
+    my ($cnum,$cdom) = @_;
+    my $lastupdate = 0;
+    my $path = &LONCAPA::propath($cdom,$cnum);
+    if (-d "$path/userfiles") {
+        if (opendir(my $dirh, "$path/userfiles")) {
+            my @maps = grep(/^default_?\d*\.(?:sequence|page)$/,readdir($dirh));
+            foreach my $map (@maps) {
+                my $mtime = (stat("$path/userfiles/$map"))[9];
+                if ($mtime > $lastupdate) {
+                    $lastupdate = $mtime;
+                }
+            }
+        }
+    }
+    return $lastupdate;
+}
+


More information about the LON-CAPA-cvs mailing list