Diff for /loncom/misc/refresh_courseids_db.pl between versions 1.7 and 1.8

version 1.7, 2010/08/01 03:57:32 version 1.8, 2010/08/22 21:14:54
Line 78  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();
   
 &build_release_hashes();  &build_release_hashes();
 $env{'allowed.bre'} = 'F';  $env{'allowed.bre'} = 'F';
   
 foreach my $dom (@domains) {  foreach my $dom (@domains) {
     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 108  print $fh "==== refresh_courseids.db com Line 109  print $fh "==== refresh_courseids.db com
 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 118  sub recurse_courses { Line 119  sub recurse_courses {
         foreach my $item (@contents) {          foreach my $item (@contents) {
             if ($depth < 4) {              if ($depth < 4) {
                 &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 151  sub recurse_courses { Line 152  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);                  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);
Line 176  sub recurse_courses { Line 178  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 '') {
Line 198  sub recurse_courses { Line 201  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 212  sub recurse_courses { Line 213  sub recurse_courses {
                         }                          }
                     }                      }
                 }                  }
                                    
                 $env{'request.course.id'} = $cdom.'_'.$cnum;                  if (($chome ne '')  && ($lastaccess->{$cid} > $twodaysago)) {
                 $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum;                      $env{'request.course.id'} = $cdom.'_'.$cnum;
                 &Apache::lonuserstate::readmap($cdom.'/'.$cnum);                      $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum;
                       &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
                 # check all parameters  
                 ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);                      # check all parameters
                       ($reqdmajor,$reqdminor) = &parameter_constraints($cnum,$cdom);
                 # check course type  
                 ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,                      # check course type
                                                                  $reqdmajor,                      ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,
                                                                  $reqdminor);                                                                        $reqdmajor,
                 # check course contents                                                                        $reqdminor);
                 ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,                      # check course contents
                                                                      $reqdmajor,                      ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,
                                                                      $reqdminor);                                                                           $reqdmajor,
                 delete($env{'request.course.id'});                                                                           $reqdminor);
                 delete($env{'request.role'});                      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') {
                     $courseshash->{$chome}{$cid} = {                      $courseshash->{$chome}{$cid} = {

Removed from v.1.7  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>