--- loncom/misc/refresh_courseids_db.pl 2010/12/24 07:58:09 1.10 +++ loncom/misc/refresh_courseids_db.pl 2013/06/26 21:22:42 1.16 @@ -1,7 +1,7 @@ #!/usr/bin/perl # The LearningOnline Network # -# $Id: refresh_courseids_db.pl,v 1.10 2010/12/24 07:58:09 raeburn Exp $ +# $Id: refresh_courseids_db.pl,v 1.16 2013/06/26 21:22:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -85,6 +85,8 @@ my @ids=&Apache::lonnet::current_machine $env{'allowed.bre'} = 'F'; foreach my $dom (@domains) { + $env{'user.domain'} = $dom; + $env{'user.name'} = &Apache::lonnet::get_domainconfiguser($dom); my %courseshash; my %currhash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@ids,'.'); my %lastaccess = &Apache::lonnet::courselastaccess($dom,undef,\@ids); @@ -101,6 +103,8 @@ foreach my $dom (@domains) { } } } + delete($env{'user.name'}); + delete($env{'user.domain'}); } delete($env{'allowed.bre'}); @@ -227,6 +231,10 @@ sub recurse_courses { ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype, $reqdmajor, $reqdminor); + # check communication blocks + ($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom, + $reqdmajor, + $reqdminor); # check course contents ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom, $reqdmajor, @@ -238,6 +246,20 @@ sub recurse_courses { } 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, @@ -354,6 +376,13 @@ sub parameter_constraints { if ($key =~ /(\Q$item\E)$/) { if (ref($checkparms{$item}) eq 'ARRAY') { my $value = $resourcedata->{$key}; + if ($item eq 'examcode') { + if (&Apache::lonnet::validCODE($value)) { + $value = 'valid'; + } else { + $value = ''; + } + } if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) { my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value}); ($reqdmajor,$reqdminor) = @@ -377,6 +406,36 @@ sub coursetype_constraints { return ($reqdmajor,$reqdminor); } +sub commblock_constraints { + my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_; + my %comm_blocks = &Apache::lonnet::dump('commblock',$cdom,$cnum); + my $now = time; + if (keys(%comm_blocks) > 0) { + foreach my $block (keys(%comm_blocks)) { + if ($block =~ /^firstaccess____(.+)$/) { + my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.timer'}); + ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); + last; + } elsif ($block =~ /^(\d+)____(\d+)$/) { + my ($start,$end) = ($1,$2); + next if ($end < $now); + } + if (ref($comm_blocks{$block}) eq 'HASH') { + if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') { + if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') { + if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) { + my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'course.commblock.docs'}); + ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); + last; + } + } + } + } + } + } + return; +} + sub coursecontent_constraints { my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); @@ -455,3 +514,21 @@ sub read_paramdata { 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; +} +