[LON-CAPA-cvs] cvs: rat / lonuserstate.pm
www
lon-capa-cvs@mail.lon-capa.org
Wed, 22 Oct 2003 16:10:56 -0000
www Wed Oct 22 12:10:56 2003 EDT
Modified files:
/rat lonuserstate.pm
Log:
Just saving my work on consistent versioning, several things need fixing.
Index: rat/lonuserstate.pm
diff -u rat/lonuserstate.pm:1.60 rat/lonuserstate.pm:1.61
--- rat/lonuserstate.pm:1.60 Fri Sep 19 14:20:35 2003
+++ rat/lonuserstate.pm Wed Oct 22 12:10:56 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Construct and maintain state and binary representation of course for user
#
-# $Id: lonuserstate.pm,v 1.60 2003/09/19 18:20:35 albertel Exp $
+# $Id: lonuserstate.pm,v 1.61 2003/10/22 16:10:56 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -68,10 +68,46 @@
my $retfurl; # variable with the very first URL in the course
my %randompick; # randomly picked resources
my %randompickseed; # optional seed for randomly picking resources
-my %actualversion; # version of resource as loaded now
-my %setversion; # forced version of resource
-my %lastversion; # version when CC came in last
-my $versionmode; # how versioning is handled in this course
+
+# ----------------------------------- Remove version from URL and store in hash
+
+sub versiontrack {
+ my $uri=shift;
+ if ($uri=~/\.(\d+)\.\w+$/) {
+ my $version=$1;
+ $uri=~s/\.\d+\.(\w+)$/\.$1/;
+ $hash{'version_'.$uri}=$version;
+ }
+ return $uri;
+}
+
+# -------------------------------------------------------------- Put in version
+
+sub putinversion {
+ my $uri=shift;
+ if ($hash{'version_'.$uri}) {
+ my $version=$hash{'version_'.$uri};
+ $uri=~s/\.(\w+)$/\.$version\.$1/;
+ }
+ return $uri;
+}
+
+# ----------------------------------------- Processing versions file for course
+
+sub processversionfile {
+ my %cenv=shift;
+ my %versions=&Apache::lonnet::dump('resourceversions',
+ $cenv{'domain'},
+ $cenv{'num'});
+ foreach (keys %versions) {
+ if ($_=~/^error\:/) { return; }
+ if ($versions{$_} eq 'current') {
+ delete $hash{'version_'.$_};
+ } else {
+ $hash{'version_'.$_}=$versions{$_};
+ }
+ }
+}
# --------------------------------------------------------- Loads map from disk
@@ -119,7 +155,12 @@
$hash{'kind_'.$rid}='res';
$hash{'title_'.$rid}=$token->[2]->{'title'};
- my $turi=$token->[2]->{'src'};
+# Rip out the version and store it separately
+ my $turi=&versiontrack($token->[2]->{'src'});
+# If there is an explicit version parameter, use that one
+ if ($token->[2]->{'version'}) {
+ $hash{'version_'.$turi}=$1;
+ }
&Apache::lonnet::do_cache(\%Apache::lonnet::titlecache,
&Apache::lonnet::symbclean(
&Apache::lonnet::declutter($uri).'___'.
@@ -494,7 +535,7 @@
$errtext='';
$pc=0;
my $furi=&Apache::lonnet::clutter($uri);
- $hash{'src_0.0'}=$furi;
+ $hash{'src_0.0'}=&versiontrack($furi);
$hash{'title_0.0'}=&Apache::lonnet::metadata($uri,'title');
$hash{'ids_'.$furi}='0.0';
$hash{'is_map_0.0'}=1;
@@ -505,9 +546,12 @@
&pickrandom();
}
# ------------------------------------------------------------ Version tracking
-# if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
-# &Apache::lonnet::logthis('Will be version tracking');
-# }
+ &processversionfile(%cenv);
+ foreach (keys %hash) {
+ if ($_=~/^src\_/) {
+ $hash{$_}=&putinversion($hash{$_});
+ }
+ }
unless ((untie(%hash)) && (untie(%parmhash))) {
&Apache::lonnet::logthis("<font color=blue>WARNING: ".
"Could not untie coursemap $fn for $uri.</font>");