--- rat/lonuserstate.pm 2003/04/30 21:13:57 1.58 +++ rat/lonuserstate.pm 2003/10/22 16:52:14 1.62 @@ -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.58 2003/04/30 21:13:57 albertel Exp $ +# $Id: lonuserstate.pm,v 1.62 2003/10/22 16:52:14 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,10 +68,45 @@ my $errtext; # variable with all errors 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/; + unless ($hash{'version_'.$uri}) { + $hash{'version_'.$uri}=$version; + } + } + return $uri; +} + +# -------------------------------------------------------------- Put in version + +sub putinversion { + my $uri=shift; + if ($hash{'version_'.$uri}) { + my $version=$hash{'version_'.$uri}; + if ($version eq 'current') { return $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; } + $hash{'version_'.$_}=$versions{$_}; + } +} # --------------------------------------------------------- Loads map from disk @@ -85,7 +120,7 @@ sub loadmap { $hash{'map_id_'.$lpc}=$uri; # Determine and check filename - my $fn=&Apache::lonnet::filelocation('',$uri); + my $fn=&Apache::lonnet::filelocation('',&putinversion($uri)); my $ispage=($fn=~/\.page$/); @@ -119,13 +154,18 @@ sub loadmap { $hash{'kind_'.$rid}='res'; $hash{'title_'.$rid}=$token->[2]->{'title'}; - my $turi=$token->[2]->{'src'}; - $Apache::lonnet::titlecache{ - &Apache::lonnet::symbclean( - &Apache::lonnet::declutter($uri).'___'. - $token->[2]->{'id'}.'___'. - &Apache::lonnet::declutter($turi))}= - $token->[2]->{'title'}; + my $turi=&versiontrack($token->[2]->{'src'}); + if ($token->[2]->{'version'}) { + unless ($hash{'version_'.$turi}) { + $hash{'version_'.$turi}=$1; + } + } + &Apache::lonnet::do_cache(\%Apache::lonnet::titlecache, + &Apache::lonnet::symbclean( + &Apache::lonnet::declutter($uri).'___'. + $token->[2]->{'id'}.'___'. + &Apache::lonnet::declutter($turi)), + $token->[2]->{'title'}); unless ($ispage) { $turi=~/\.(\w+)$/; my $embstyle=&Apache::loncommon::fileembstyle($1); @@ -493,8 +533,9 @@ sub readmap { %parmhash=(); $errtext=''; $pc=0; + &processversionfile(%cenv); 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; @@ -504,10 +545,12 @@ sub readmap { &accinit($uri,$short,$fn); &pickrandom(); } -# ------------------------------------------------------------ Version tracking -# if (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) { -# &Apache::lonnet::logthis('Will be version tracking'); -# } +# ------------------------------------------------------- Put versions into src + foreach (keys %hash) { + if ($_=~/^src\_/) { + $hash{$_}=&putinversion($hash{$_}); + } + } unless ((untie(%hash)) && (untie(%parmhash))) { &Apache::lonnet::logthis("WARNING: ". "Could not untie coursemap $fn for $uri.");