version 1.3, 2010/03/17 18:16:56
|
version 1.23, 2021/03/31 02:19:59
|
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 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'); |
Line 73 open(my $fh,'>>'.$Apache::lonnet::perlva
|
Line 77 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::lonrelrequtils::init_global_hashes(); |
|
my $globals_set = 1; |
|
|
|
$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; |
my %domdesign = &Apache::loncommon::get_domainconf($dom); |
my %domdesign = &Apache::loncommon::get_domainconf($dom); |
my $autoassign = $domdesign{$dom.'.autoassign.co-owners'}; |
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)) { |
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 90 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,$autoassign,$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 105 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,$autoassign,$fh); |
$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 140 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 (%roleshash,$gotcc); |
my $twodaysago = time - 172800; |
|
my (%roleshash,$gotcc,$reqdmajor,$reqdminor); |
if ($owner eq '') { |
if ($owner eq '') { |
%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; |
$gotcc = 1; |
Line 165 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 $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 187 sub recurse_courses {
|
Line 209 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 201 sub recurse_courses {
|
Line 221 sub recurse_courses {
|
} |
} |
} |
} |
} |
} |
|
|
|
if (($chome ne '') && ($lastaccess->{$cid} > $twodaysago)) { |
|
$env{'request.course.id'} = $cdom.'_'.$cnum; |
|
$env{'request.role'} = 'cc./'.$cdom.'/'.$cnum; |
|
$env{'request.role.adv'} = 1; |
|
|
|
my $readmap = 1; |
|
($reqdmajor,$reqdminor) = &Apache::lonrelrequtils::get_release_req($cnum,$cdom, |
|
$crstype,$readmap, |
|
$globals_set); |
|
delete($env{'request.role.adv'}); |
|
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, |
Line 231 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 268 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}; |
} |
} |
} |
} |
|
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: "; |
Line 292 sub recurse_courses {
|
Line 369 sub recurse_courses {
|
return; |
return; |
} |
} |
|
|
|
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; |
|
} |
|
|