--- loncom/misc/refresh_courseids_db.pl 2010/08/01 03:57:32 1.7 +++ loncom/misc/refresh_courseids_db.pl 2010/12/16 17:03:48 1.9 @@ -1,7 +1,7 @@ #!/usr/bin/perl # The LearningOnline Network # -# $Id: refresh_courseids_db.pl,v 1.7 2010/08/01 03:57:32 raeburn Exp $ +# $Id: refresh_courseids_db.pl,v 1.9 2010/12/16 17:03:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,7 +61,7 @@ use LONCAPA qw(:DEFAULT :match); exit if ($Apache::lonnet::perlvar{'lonRole'} ne 'library'); -use vars qw( %checkparms %checkresponsetypes %checkcrstypes %anonsurvey ); +use vars qw( %checkparms %checkresponsetypes %checkcrstypes %anonsurvey %randomizetry ); # Make sure this process is running from user=www my $wwwid=getpwnam('www'); @@ -78,18 +78,19 @@ open(my $fh,'>>'.$Apache::lonnet::perlva print $fh "==== refresh_courseids_db.pl Run ".localtime()."====\n"; my @domains = sort(&Apache::lonnet::current_machine_domains()); +my @ids=&Apache::lonnet::current_machine_ids(); &build_release_hashes(); $env{'allowed.bre'} = 'F'; foreach my $dom (@domains) { my %courseshash; - my @ids=&Apache::lonnet::current_machine_ids(); my %currhash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@ids,'.'); + my %lastaccess = &Apache::lonnet::courselastaccess($dom,undef,\@ids); my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; my %domdesign = &Apache::loncommon::get_domainconf($dom); my $autoassign = $domdesign{$dom.'.autoassign.co-owners'}; - &recurse_courses($dom,$dir,0,\%courseshash,\%currhash,$autoassign,$fh); + &recurse_courses($dom,$dir,0,\%courseshash,\%currhash,\%lastaccess,$autoassign,$fh); foreach my $lonhost (keys(%courseshash)) { if (ref($courseshash{$lonhost}) eq 'HASH') { if (&Apache::lonnet::courseidput($dom,$courseshash{$lonhost},$lonhost,'notime') eq 'ok') { @@ -108,7 +109,7 @@ print $fh "==== refresh_courseids.db com close($fh); sub recurse_courses { - my ($cdom,$dir,$depth,$courseshash,$currhash,$autoassign,$fh) = @_; + my ($cdom,$dir,$depth,$courseshash,$currhash,$lastaccess,$autoassign,$fh) = @_; next unless (ref($currhash) eq 'HASH'); if (-d $dir) { opendir(DIR,$dir); @@ -118,7 +119,7 @@ sub recurse_courses { foreach my $item (@contents) { if ($depth < 4) { &recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash, - $currhash,$autoassign,$fh); + $currhash,$lastaccess,$autoassign,$fh); } elsif ($item =~ /^$match_courseid$/) { my $cnum = $item; my $cid = $cdom.'_'.$cnum; @@ -151,6 +152,7 @@ sub recurse_courses { } my $chome = &Apache::lonnet::homeserver($cnum,$cdom); my $owner = $courseinfo{'internal.courseowner'}; + my $twodaysago = time - 172800; my (%roleshash,$gotcc,$reqdmajor,$reqdminor); if ($owner eq '') { %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1); @@ -176,6 +178,7 @@ sub recurse_courses { my $creator = $courseinfo{'internal.creator'}; my $creationcontext = $courseinfo{'internal.creationcontext'}; my $inst_code = $courseinfo{'internal.coursecode'}; + my $releaserequired = $courseinfo{'internal.releaserequired'}; $inst_code = '' if (!defined($inst_code)); $owner = '' if (!defined($owner)); if ($created eq '') { @@ -198,13 +201,11 @@ sub recurse_courses { my @stats = stat("$dir/$cnum/passwd"); $created = $stats[9]; } - my %lastaccess = - &Apache::lonnet::courselastaccess($cdom,$cnum); - if ($lastaccess{$cid}) { + if ($lastaccess->{$cid}) { if ($created eq '') { - $created = $lastaccess{$cid}; - } elsif ($lastaccess{$cid} < $created) { - $created = $lastaccess{$cid}; + $created = $lastaccess->{$cid}; + } elsif ($lastaccess->{$cid} < $created) { + $created = $lastaccess->{$cid}; } } unless ($created eq '') { @@ -212,24 +213,28 @@ sub recurse_courses { } } } - - $env{'request.course.id'} = $cdom.'_'.$cnum; - $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum; - &Apache::lonuserstate::readmap($cdom.'/'.$cnum); - - # check all parameters - ($reqdmajor,$reqdminor) = ¶meter_constraints($cnum,$cdom); - - # check course type - ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype, - $reqdmajor, - $reqdminor); - # check course contents - ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom, - $reqdmajor, - $reqdminor); - delete($env{'request.course.id'}); - delete($env{'request.role'}); + + if (($chome ne '') && ($lastaccess->{$cid} > $twodaysago)) { + $env{'request.course.id'} = $cdom.'_'.$cnum; + $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum; + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + + # check all parameters + ($reqdmajor,$reqdminor) = ¶meter_constraints($cnum,$cdom); + + # check course type + ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype, + $reqdmajor, + $reqdminor); + # check course contents + ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom, + $reqdmajor, + $reqdminor); + delete($env{'request.course.id'}); + delete($env{'request.role'}); + } elsif ($releaserequired) { + ($reqdmajor,$reqdminor) = split(/\./,$releaserequired); + } unless ($chome eq 'no_host') { $courseshash->{$chome}{$cid} = { @@ -377,8 +382,10 @@ sub coursecontent_constraints { if (defined($navmap)) { my %anonsubmissions = &Apache::lonnet::dump('nohist_anonsurveys', $cdom,$cnum); + my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry', + $cdom,$cnum); my %allresponses; - my $anonsurv_subm; + my ($anonsurv_subm,$randbytry_subm); foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) { my %responses = $res->responseTypes(); foreach my $key (keys(%responses)) { @@ -391,6 +398,9 @@ sub coursecontent_constraints { if (exists($anonsubmissions{$symb."\0".$part})) { $anonsurv_subm = 1; } + if (exists($randomizetrysubm{$symb."\0".$part})) { + $randbytry_subm = 1; + } } } foreach my $key (keys(%allresponses)) { @@ -401,6 +411,10 @@ sub coursecontent_constraints { ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major}, $anonsurvey{minor},$reqdmajor,$reqdminor); } + if ($randbytry_subm) { + ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($randomizetry{major}, + $randomizetry{minor},$reqdmajor,$reqdminor); + } } return ($reqdmajor,$reqdminor); } @@ -462,6 +476,7 @@ sub build_release_hashes { } } ($anonsurvey{major},$anonsurvey{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'}); + ($randomizetry{major},$randomizetry{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'}); return; }