version 1.8, 2010/08/22 21:14:54
|
version 1.23, 2021/03/31 02:19:59
|
Line 57 use Apache::loncommon;
|
Line 57 use Apache::loncommon;
|
use Apache::lonuserstate; |
use Apache::lonuserstate; |
use Apache::loncoursedata; |
use Apache::loncoursedata; |
use Apache::lonnavmaps; |
use Apache::lonnavmaps; |
|
use Apache::lonrelrequtils; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
exit if ($Apache::lonnet::perlvar{'lonRole'} ne 'library'); |
exit if ($Apache::lonnet::perlvar{'lonRole'} ne 'library'); |
|
|
use vars qw( %checkparms %checkresponsetypes %checkcrstypes %anonsurvey ); |
|
|
|
# Make sure this process is running from user=www |
# Make sure this process is running from user=www |
my $wwwid=getpwnam('www'); |
my $wwwid=getpwnam('www'); |
if ($wwwid!=$<) { |
if ($wwwid!=$<) { |
Line 80 print $fh "==== refresh_courseids_db.pl
|
Line 79 print $fh "==== refresh_courseids_db.pl
|
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
my @ids=&Apache::lonnet::current_machine_ids(); |
my @ids=&Apache::lonnet::current_machine_ids(); |
|
|
&build_release_hashes(); |
&Apache::lonrelrequtils::init_global_hashes(); |
|
my $globals_set = 1; |
|
|
$env{'allowed.bre'} = 'F'; |
$env{'allowed.bre'} = 'F'; |
|
|
foreach my $dom (@domains) { |
foreach my $dom (@domains) { |
|
$env{'user.domain'} = $dom; |
|
$env{'user.name'} = &Apache::lonnet::get_domainconfiguser($dom); |
my %courseshash; |
my %courseshash; |
my %currhash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@ids,'.'); |
my %currhash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@ids,'.'); |
my %lastaccess = &Apache::lonnet::courselastaccess($dom,undef,\@ids); |
my %lastaccess = &Apache::lonnet::courselastaccess($dom,undef,\@ids); |
Line 100 foreach my $dom (@domains) {
|
Line 103 foreach my $dom (@domains) {
|
} |
} |
} |
} |
} |
} |
|
delete($env{'user.name'}); |
|
delete($env{'user.domain'}); |
} |
} |
|
|
delete($env{'allowed.bre'}); |
delete($env{'allowed.bre'}); |
Line 117 sub recurse_courses {
|
Line 122 sub recurse_courses {
|
closedir(DIR); |
closedir(DIR); |
$depth ++; |
$depth ++; |
foreach my $item (@contents) { |
foreach my $item (@contents) { |
if ($depth < 4) { |
if (($depth < 4) && (length($item) == 1)) { |
&recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash, |
&recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash, |
$currhash,$lastaccess,$autoassign,$fh); |
$currhash,$lastaccess,$autoassign,$fh); |
} elsif ($item =~ /^$match_courseid$/) { |
} elsif ($item =~ /^$match_courseid$/) { |
Line 178 sub recurse_courses {
|
Line 183 sub recurse_courses {
|
my $creator = $courseinfo{'internal.creator'}; |
my $creator = $courseinfo{'internal.creator'}; |
my $creationcontext = $courseinfo{'internal.creationcontext'}; |
my $creationcontext = $courseinfo{'internal.creationcontext'}; |
my $inst_code = $courseinfo{'internal.coursecode'}; |
my $inst_code = $courseinfo{'internal.coursecode'}; |
|
my $xlists = $courseinfo{'internal.crosslistings'}; |
my $releaserequired = $courseinfo{'internal.releaserequired'}; |
my $releaserequired = $courseinfo{'internal.releaserequired'}; |
|
my $uniquecode = $courseinfo{'internal.uniquecode'}; |
$inst_code = '' if (!defined($inst_code)); |
$inst_code = '' if (!defined($inst_code)); |
$owner = '' if (!defined($owner)); |
$owner = '' if (!defined($owner)); |
|
$uniquecode = '' if (!defined($uniquecode)); |
if ($created eq '') { |
if ($created eq '') { |
if (ref($currhash->{$cid}) eq 'HASH') { |
if (ref($currhash->{$cid}) eq 'HASH') { |
$created = $currhash->{$cid}{'created'}; |
$created = $currhash->{$cid}{'created'}; |
Line 217 sub recurse_courses {
|
Line 225 sub recurse_courses {
|
if (($chome ne '') && ($lastaccess->{$cid} > $twodaysago)) { |
if (($chome ne '') && ($lastaccess->{$cid} > $twodaysago)) { |
$env{'request.course.id'} = $cdom.'_'.$cnum; |
$env{'request.course.id'} = $cdom.'_'.$cnum; |
$env{'request.role'} = 'cc./'.$cdom.'/'.$cnum; |
$env{'request.role'} = 'cc./'.$cdom.'/'.$cnum; |
&Apache::lonuserstate::readmap($cdom.'/'.$cnum); |
$env{'request.role.adv'} = 1; |
|
|
# check all parameters |
|
($reqdmajor,$reqdminor) = ¶meter_constraints($cnum,$cdom); |
|
|
|
# check course type |
my $readmap = 1; |
($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype, |
($reqdmajor,$reqdminor) = &Apache::lonrelrequtils::get_release_req($cnum,$cdom, |
$reqdmajor, |
$crstype,$readmap, |
$reqdminor); |
$globals_set); |
# check course contents |
delete($env{'request.role.adv'}); |
($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom, |
|
$reqdmajor, |
|
$reqdminor); |
|
delete($env{'request.course.id'}); |
delete($env{'request.course.id'}); |
delete($env{'request.role'}); |
delete($env{'request.role'}); |
} elsif ($releaserequired) { |
} elsif ($releaserequired) { |
Line 237 sub recurse_courses {
|
Line 239 sub recurse_courses {
|
} |
} |
|
|
unless ($chome eq 'no_host') { |
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} = { |
$courseshash->{$chome}{$cid} = { |
description => $courseinfo{'description'}, |
description => $courseinfo{'description'}, |
inst_code => $inst_code, |
inst_code => $inst_code, |
Line 266 sub recurse_courses {
|
Line 282 sub recurse_courses {
|
my $cc = $1; |
my $cc = $1; |
unless ($cc eq $owner) { |
unless ($cc eq $owner) { |
my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc); |
my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc); |
|
unless ($result eq 'valid') { |
|
if ($xlists ne '') { |
|
foreach my $xlist (split(',',$xlists)) { |
|
my ($inst_crosslist,$lcsec) = split(':',$xlist); |
|
$result = |
|
&Apache::lonnet::auto_validate_inst_crosslist($cnum,$cdom,$inst_code, |
|
$inst_crosslist,$cc); |
|
last if ($result eq 'valid'); |
|
} |
|
} |
|
} |
if ($result eq 'valid') { |
if ($result eq 'valid') { |
if (@newcoowners > 0) { |
if (@newcoowners > 0) { |
unless (grep(/^\Q$cc\E$/,@newcoowners)) { |
unless (grep(/^\Q$cc\E$/,@newcoowners)) { |
push(@newcoowners,$cc); |
push(@newcoowners,$cc); |
} |
} |
} else { |
} else { |
Line 303 sub recurse_courses {
|
Line 330 sub recurse_courses {
|
$courseshash->{$chome}{$cid}{$item} = $courseinfo{$item}; |
$courseshash->{$chome}{$cid}{$item} = $courseinfo{$item}; |
} |
} |
} |
} |
foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') { |
foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date','uniquecode') { |
if ($courseinfo{'internal.'.$item} ne '') { |
if ($courseinfo{'internal.'.$item} ne '') { |
$courseshash->{$chome}{$cid}{$item} = |
$courseshash->{$chome}{$cid}{$item} = |
$courseinfo{'internal.'.$item}; |
$courseinfo{'internal.'.$item}; |
Line 320 sub recurse_courses {
|
Line 347 sub recurse_courses {
|
$changes{'internal.releaserequired'} = $releasereq; |
$changes{'internal.releaserequired'} = $releasereq; |
} else { |
} else { |
if ($courseinfo{'internal.releaserequired'} ne $releasereq) { |
if ($courseinfo{'internal.releaserequired'} ne $releasereq) { |
|
|
$changes{'internal.releaserequired'} = $releasereq; |
$changes{'internal.releaserequired'} = $releasereq; |
} |
} |
} |
} |
Line 343 sub recurse_courses {
|
Line 369 sub recurse_courses {
|
return; |
return; |
} |
} |
|
|
sub parameter_constraints { |
sub last_map_update { |
my ($cnum,$cdom) = @_; |
my ($cnum,$cdom) = @_; |
my ($reqdmajor,$reqdminor); |
my $lastupdate = 0; |
my $resourcedata=&read_paramdata($cnum,$cdom); |
my $path = &LONCAPA::propath($cdom,$cnum); |
if (ref($resourcedata) eq 'HASH') { |
if (-d "$path/userfiles") { |
foreach my $key (keys(%{$resourcedata})) { |
if (opendir(my $dirh, "$path/userfiles")) { |
foreach my $item (keys(%checkparms)) { |
my @maps = grep(/^default_?\d*\.(?:sequence|page)$/,readdir($dirh)); |
if ($key =~ /(\Q$item\E)$/) { |
foreach my $map (@maps) { |
if (ref($checkparms{$item}) eq 'ARRAY') { |
my $mtime = (stat("$path/userfiles/$map"))[9]; |
my $value = $resourcedata->{$key}; |
if ($mtime > $lastupdate) { |
if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) { |
$lastupdate = $mtime; |
my ($major,$minor) = split(/\./,$Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value}); |
|
($reqdmajor,$reqdminor) = |
|
&update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return ($reqdmajor,$reqdminor); |
|
} |
|
|
|
sub coursetype_constraints { |
|
my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_; |
|
if (defined($checkcrstypes{$crstype})) { |
|
my ($major,$minor) = split(/\./,$checkcrstypes{$crstype}); |
|
($reqdmajor,$reqdminor) = |
|
&update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); |
|
} |
|
return ($reqdmajor,$reqdminor); |
|
} |
|
|
|
sub coursecontent_constraints { |
|
my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_; |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
|
if (defined($navmap)) { |
|
my %anonsubmissions = &Apache::lonnet::dump('nohist_anonsurveys', |
|
$cdom,$cnum); |
|
my %allresponses; |
|
my $anonsurv_subm; |
|
foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) { |
|
my %responses = $res->responseTypes(); |
|
foreach my $key (keys(%responses)) { |
|
next unless(exists($checkresponsetypes{$key})); |
|
$allresponses{$key} += $responses{$key}; |
|
} |
|
my @parts = @{$res->parts()}; |
|
my $symb = $res->symb(); |
|
foreach my $part (@parts) { |
|
if (exists($anonsubmissions{$symb."\0".$part})) { |
|
$anonsurv_subm = 1; |
|
} |
|
} |
|
} |
|
foreach my $key (keys(%allresponses)) { |
|
my ($major,$minor) = split(/\./,$checkresponsetypes{$key}); |
|
($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); |
|
} |
|
if ($anonsurv_subm) { |
|
($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major}, |
|
$anonsurvey{minor},$reqdmajor,$reqdminor); |
|
} |
|
} |
|
return ($reqdmajor,$reqdminor); |
|
} |
|
|
|
sub update_reqd_loncaparev { |
|
my ($major,$minor,$reqdmajor,$reqdminor) = @_; |
|
if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) { |
|
if ($reqdmajor eq '' || $reqdminor eq '') { |
|
$reqdmajor = $major; |
|
$reqdminor = $minor; |
|
} elsif (($major > $reqdmajor) || |
|
($major == $reqdmajor && $minor > $reqdminor)) { |
|
$reqdmajor = $major; |
|
$reqdminor = $minor; |
|
} |
|
} |
|
return ($reqdmajor,$reqdminor); |
|
} |
|
|
|
sub read_paramdata { |
|
my ($cnum,$dom)=@_; |
|
my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$dom); |
|
my $classlist=&Apache::loncoursedata::get_classlist(); |
|
foreach my $student (keys(%{$classlist})) { |
|
if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) { |
|
my ($tuname,$tudom)=($1,$2); |
|
my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom); |
|
foreach my $userkey (keys(%{$useropt})) { |
|
if ($userkey=~/^$env{'request.course.id'}/) { |
|
my $newkey=$userkey; |
|
$newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./; |
|
$$resourcedata{$newkey}=$$useropt{$userkey}; |
|
} |
} |
} |
} |
} |
|
} |
|
return $resourcedata; |
|
} |
|
|
|
sub build_release_hashes { |
|
foreach my $key (keys(%Apache::lonnet::needsrelease)) { |
|
my ($item,$name,$value) = split(/:/,$key); |
|
if ($item eq 'parameter') { |
|
if (ref($checkparms{$name}) eq 'ARRAY') { |
|
unless(grep(/^\Q$name\E$/,@{$checkparms{$name}})) { |
|
push(@{$checkparms{$name}},$value); |
|
} |
|
} else { |
|
push(@{$checkparms{$name}},$value); |
|
} |
|
} elsif ($item eq 'resourcetag') { |
|
if ($name eq 'responsetype') { |
|
$checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key} |
|
} |
|
} elsif ($item eq 'course') { |
|
if ($name eq 'crstype') { |
|
$checkcrstypes{$value} = $Apache::lonnet::needsrelease{$key}; |
|
} |
|
} |
} |
} |
} |
($anonsurvey{major},$anonsurvey{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'}); |
return $lastupdate; |
return; |
|
} |
} |
|
|