[LON-CAPA-cvs] cvs: loncom /misc refresh_courseids_db.pl
raeburn
raeburn@source.lon-capa.org
Sun, 22 Aug 2010 21:14:54 -0000
raeburn Sun Aug 22 21:14:54 2010 EDT
Modified files:
/loncom/misc refresh_courseids_db.pl
Log:
- Only check courses with last access within past two days when updating
LON-CAPA release required in nohist_courseids.db.
Index: loncom/misc/refresh_courseids_db.pl
diff -u loncom/misc/refresh_courseids_db.pl:1.7 loncom/misc/refresh_courseids_db.pl:1.8
--- loncom/misc/refresh_courseids_db.pl:1.7 Sun Aug 1 03:57:32 2010
+++ loncom/misc/refresh_courseids_db.pl Sun Aug 22 21:14:54 2010
@@ -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.8 2010/08/22 21:14:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,18 +78,19 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
}
}
}
-
- $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} = {