version 1.1, 2010/03/14 23:17:54
|
version 1.14, 2013/05/10 15:57:36
|
Line 54 use strict;
|
Line 54 use strict;
|
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
|
use Apache::lonuserstate; |
|
use Apache::loncoursedata; |
|
use Apache::lonnavmaps; |
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 %randomizetry ); |
|
|
# 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 73 open(my $fh,'>>'.$Apache::lonnet::perlva
|
Line 78 open(my $fh,'>>'.$Apache::lonnet::perlva
|
print $fh "==== refresh_courseids_db.pl Run ".localtime()."====\n"; |
print $fh "==== refresh_courseids_db.pl Run ".localtime()."====\n"; |
|
|
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
|
my @ids=&Apache::lonnet::current_machine_ids(); |
|
|
|
&Apache::loncommon::build_release_hashes(\%checkparms,\%checkresponsetypes, |
|
\%checkcrstypes,\%anonsurvey,\%randomizetry); |
|
$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 @ids=&Apache::lonnet::current_machine_ids(); |
|
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 $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
&recurse_courses($dom,$dir,0,\%courseshash,\%currhash,$fh); |
my %domdesign = &Apache::loncommon::get_domainconf($dom); |
|
my $autoassign = $domdesign{$dom.'.autoassign.co-owners'}; |
|
&recurse_courses($dom,$dir,0,\%courseshash,\%currhash,\%lastaccess,$autoassign,$fh); |
foreach my $lonhost (keys(%courseshash)) { |
foreach my $lonhost (keys(%courseshash)) { |
if (ref($courseshash{$lonhost}) eq 'HASH') { |
if (ref($courseshash{$lonhost}) eq 'HASH') { |
if (&Apache::lonnet::courseidput($dom,$courseshash{$lonhost},$lonhost,'notime') eq 'ok') { |
if (&Apache::lonnet::courseidput($dom,$courseshash{$lonhost},$lonhost,'notime') eq 'ok') { |
Line 88 foreach my $dom (@domains) {
|
Line 103 foreach my $dom (@domains) {
|
} |
} |
} |
} |
} |
} |
|
delete($env{'user.name'}; |
|
delete($env{'user.domain'}); |
} |
} |
|
|
|
delete($env{'allowed.bre'}); |
|
|
## Finished! |
## Finished! |
print $fh "==== refresh_courseids.db completed ".localtime()." ====\n"; |
print $fh "==== refresh_courseids.db completed ".localtime()." ====\n"; |
close($fh); |
close($fh); |
|
|
sub recurse_courses { |
sub recurse_courses { |
my ($cdom,$dir,$depth,$courseshash,$currhash,$fh) = @_; |
my ($cdom,$dir,$depth,$courseshash,$currhash,$lastaccess,$autoassign,$fh) = @_; |
next unless (ref($currhash) eq 'HASH'); |
next unless (ref($currhash) eq 'HASH'); |
if (-d $dir) { |
if (-d $dir) { |
opendir(DIR,$dir); |
opendir(DIR,$dir); |
Line 104 sub recurse_courses {
|
Line 123 sub recurse_courses {
|
$depth ++; |
$depth ++; |
foreach my $item (@contents) { |
foreach my $item (@contents) { |
if ($depth < 4) { |
if ($depth < 4) { |
&recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash,$currhash,$fh); |
&recurse_courses($cdom,$dir.'/'.$item,$depth,$courseshash, |
|
$currhash,$lastaccess,$autoassign,$fh); |
} elsif ($item =~ /^$match_courseid$/) { |
} elsif ($item =~ /^$match_courseid$/) { |
my $cnum = $item; |
my $cnum = $item; |
my $cid = $cdom.'_'.$cnum; |
my $cid = $cdom.'_'.$cnum; |
Line 137 sub recurse_courses {
|
Line 157 sub recurse_courses {
|
} |
} |
my $chome = &Apache::lonnet::homeserver($cnum,$cdom); |
my $chome = &Apache::lonnet::homeserver($cnum,$cdom); |
my $owner = $courseinfo{'internal.courseowner'}; |
my $owner = $courseinfo{'internal.courseowner'}; |
|
my $twodaysago = time - 172800; |
|
my (%roleshash,$gotcc,$reqdmajor,$reqdminor); |
if ($owner eq '') { |
if ($owner eq '') { |
my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1); |
%roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1); |
|
$gotcc = 1; |
if (keys(%roleshash) == 1) { |
if (keys(%roleshash) == 1) { |
foreach my $key (keys(%roleshash)) { |
foreach my $key (keys(%roleshash)) { |
if ($key =~ /^($match_username\:$match_domain)\:cc$/) { |
if ($key =~ /^($match_username\:$match_domain)\:cc$/) { |
Line 160 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 $releaserequired = $courseinfo{'internal.releaserequired'}; |
$inst_code = '' if (!defined($inst_code)); |
$inst_code = '' if (!defined($inst_code)); |
$owner = '' if (!defined($owner)); |
$owner = '' if (!defined($owner)); |
if ($created eq '') { |
if ($created eq '') { |
my %currdump = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.'); |
if (ref($currhash->{$cid}) eq 'HASH') { |
if (ref($currdump{$cid}) eq 'HASH') { |
$created = $currhash->{$cid}{'created'}; |
$created = $currdump{$cid}{'created'}; |
$creator = $currhash->{$cid}{'creator'}; |
$creator = $currdump{$cid}{'creator'}; |
$creationcontext = $currhash->{$cid}{'context'}; |
$creationcontext = $currdump{$cid}{'context'}; |
|
unless ($created eq '') { |
unless ($created eq '') { |
$changes{'internal.created'} = $created; |
$changes{'internal.created'} = $created; |
} |
} |
Line 183 sub recurse_courses {
|
Line 206 sub recurse_courses {
|
my @stats = stat("$dir/$cnum/passwd"); |
my @stats = stat("$dir/$cnum/passwd"); |
$created = $stats[9]; |
$created = $stats[9]; |
} |
} |
my %lastaccess = |
if ($lastaccess->{$cid}) { |
&Apache::lonnet::courselastaccess($cdom,$cnum); |
|
if ($lastaccess{$cid}) { |
|
if ($created eq '') { |
if ($created eq '') { |
$created = $lastaccess{$cid}; |
$created = $lastaccess->{$cid}; |
} elsif ($lastaccess{$cid} < $created) { |
} elsif ($lastaccess->{$cid} < $created) { |
$created = $lastaccess{$cid}; |
$created = $lastaccess->{$cid}; |
} |
} |
} |
} |
unless ($created eq '') { |
unless ($created eq '') { |
Line 197 sub recurse_courses {
|
Line 218 sub recurse_courses {
|
} |
} |
} |
} |
} |
} |
|
|
|
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 communication blocks |
|
($reqdmajor,$reqdminor) = &commblock_constraints($cnum,$cdom, |
|
$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') { |
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, |
owner => $owner, |
owner => $owner, |
type => $crstype, |
type => $crstype, |
}; |
}; |
if ($courseinfo{'internal.co-owners'} ne '') { |
|
$courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'}; |
|
} |
|
if ($creator ne '') { |
if ($creator ne '') { |
$courseshash->{$chome}{$cid}{'creator'} = $creator; |
$courseshash->{$chome}{$cid}{'creator'} = $creator; |
} |
} |
Line 216 sub recurse_courses {
|
Line 275 sub recurse_courses {
|
if ($creationcontext ne '') { |
if ($creationcontext ne '') { |
$courseshash->{$chome}{$cid}{'context'} = $creationcontext; |
$courseshash->{$chome}{$cid}{'context'} = $creationcontext; |
} |
} |
|
if (($inst_code ne '') && ($autoassign)) { |
|
unless ($gotcc) { |
|
%roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1); |
|
} |
|
my @currcoowners; |
|
my @newcoowners; |
|
if ($courseinfo{'internal.co-owners'} ne '') { |
|
@currcoowners = split(',',$courseinfo{'internal.co-owners'}); |
|
} |
|
foreach my $key (keys(%roleshash)) { |
|
if ($key =~ /^($match_username\:$match_domain)\:cc$/) { |
|
my $cc = $1; |
|
unless ($cc eq $owner) { |
|
my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc); |
|
if ($result eq 'valid') { |
|
if (@newcoowners > 0) { |
|
unless (grep(/^\Q$cc\E$/,@newcoowners)) { |
|
push(@newcoowners,$cc); |
|
} |
|
} else { |
|
push(@newcoowners,$cc); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
my @diffs = &Apache::loncommon::compare_arrays(\@currcoowners,\@newcoowners); |
|
if (@diffs > 0) { |
|
if (@newcoowners > 0) { |
|
$changes{'internal.co-owners'} = join(',',@newcoowners); |
|
$courseshash->{$chome}{$cid}{'co-owners'} = $changes{'internal.co-owners'}; |
|
} else { |
|
if ($courseinfo{'internal.co-owners'} ne '') { |
|
if (&Apache::lonnet::del('environment',['internal.co-owners'],$cdom,$cnum) eq 'ok') { |
|
print $fh "Former co-owner(s): $courseinfo{'internal.co-owners'} for official course: $inst_code (".$cdom."_".$cnum.") no longer active CCs, co-ownership status deleted.\n"; |
|
} |
|
} else { |
|
print $fh "Error occurred when updating co-ownership in course's environment.db for ".$cdom."_".$cnum."\n"; |
|
} |
|
} |
|
} elsif (@currcoowners > 0) { |
|
$courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'}; |
|
} |
|
} elsif ($courseinfo{'internal.co-owners'} ne '') { |
|
$courseshash->{$chome}{$cid}{'co-owners'} = $courseinfo{'internal.co-owners'}; |
|
} |
|
foreach my $item ('categories','cloners','hidefromcat') { |
|
if ($courseinfo{$item} ne '') { |
|
$courseshash->{$chome}{$cid}{$item} = $courseinfo{$item}; |
|
} |
|
} |
|
foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') { |
|
if ($courseinfo{'internal.'.$item} ne '') { |
|
$courseshash->{$chome}{$cid}{$item} = |
|
$courseinfo{'internal.'.$item}; |
|
} |
|
} |
|
if ($reqdmajor eq '' && $reqdminor eq '') { |
|
if ($courseinfo{'internal.releaserequired'} ne '') { |
|
$changes{'internal.releaserequired'} = ''; |
|
} |
|
} else { |
|
my $releasereq = $reqdmajor.'.'.$reqdminor; |
|
$courseshash->{$chome}{$cid}{'releaserequired'} = $releasereq; |
|
if ($courseinfo{'internal.releaserequired'} eq '') { |
|
$changes{'internal.releaserequired'} = $releasereq; |
|
} else { |
|
if ($courseinfo{'internal.releaserequired'} ne $releasereq) { |
|
|
|
$changes{'internal.releaserequired'} = $releasereq; |
|
} |
|
} |
|
} |
if (keys(%changes)) { |
if (keys(%changes)) { |
if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') { |
if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') { |
print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: "; |
print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: "; |
foreach my $key (sort(keys(%changes))) { |
foreach my $key (sort(keys(%changes))) { |
print $fh "$key => $changes{$key} "; |
print $fh "$key => $changes{$key} "; |
} |
} |
print $fh "\n"; |
print $fh "\n"; |
} else { |
} else { |
print $fh "Error occurred when updating course's environment.db for ".$cdom."_".$cnum."\n"; |
print $fh "Error occurred when updating course's environment.db for ".$cdom."_".$cnum."\n"; |
} |
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
sub parameter_constraints { |
|
my ($cnum,$cdom) = @_; |
|
my ($reqdmajor,$reqdminor); |
|
my $resourcedata=&read_paramdata($cnum,$cdom); |
|
if (ref($resourcedata) eq 'HASH') { |
|
foreach my $key (keys(%{$resourcedata})) { |
|
foreach my $item (keys(%checkparms)) { |
|
if ($key =~ /(\Q$item\E)$/) { |
|
if (ref($checkparms{$item}) eq 'ARRAY') { |
|
my $value = $resourcedata->{$key}; |
|
if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) { |
|
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 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; |
|
} |
} |
} |
} |
} |
} |
} |
Line 234 sub recurse_courses {
|
Line 429 sub recurse_courses {
|
return; |
return; |
} |
} |
|
|
|
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 %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry', |
|
$cdom,$cnum); |
|
my %allresponses; |
|
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)) { |
|
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; |
|
} |
|
if (exists($randomizetrysubm{$symb."\0".$part})) { |
|
$randbytry_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); |
|
} |
|
if ($randbytry_subm) { |
|
($reqdmajor,$reqdminor) = &update_reqd_loncaparev($randomizetry{major}, |
|
$randomizetry{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 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; |
|
} |
|
|