Diff for /loncom/misc/refresh_courseids_db.pl between versions 1.6 and 1.9

version 1.6, 2010/07/30 17:46:12 version 1.9, 2010/12/16 17:03:48
Line 61  use LONCAPA qw(:DEFAULT :match); Line 61  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 );  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');
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} = {
Line 375  sub coursecontent_constraints { Line 380  sub coursecontent_constraints {
     my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;      my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
     if (defined($navmap)) {      if (defined($navmap)) {
         my %resourcetracker =  &Apache::lonnet::dump('nohist_resourcetracker',          my %anonsubmissions =  &Apache::lonnet::dump('nohist_anonsurveys',
                                                        $cdom,$cnum);
           my %randomizetrysubm = &Apache::lonnet::dump('nohist_randomizetry',
                                                      $cdom,$cnum);                                                       $cdom,$cnum);
         my %allresponses;          my %allresponses;
         my $anonsurv_subm;          my ($anonsurv_subm,$randbytry_subm);
         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {          foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
             my %responses = $res->responseTypes();              my %responses = $res->responseTypes();
             foreach my $key (keys(%responses)) {              foreach my $key (keys(%responses)) {
Line 388  sub coursecontent_constraints { Line 395  sub coursecontent_constraints {
             my @parts = @{$res->parts()};              my @parts = @{$res->parts()};
             my $symb = $res->symb();              my $symb = $res->symb();
             foreach my $part (@parts) {              foreach my $part (@parts) {
                 if (exists($resourcetracker{$symb."\0".$part."\0anonymous"})) {                  if (exists($anonsubmissions{$symb."\0".$part})) {
                     $anonsurv_subm = 1;                      $anonsurv_subm = 1;
                 }                  }
                   if (exists($randomizetrysubm{$symb."\0".$part})) {
                       $randbytry_subm = 1;
                   }
             }              }
         }          }
         foreach my $key (keys(%allresponses)) {          foreach my $key (keys(%allresponses)) {
Line 401  sub coursecontent_constraints { Line 411  sub coursecontent_constraints {
             ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major},              ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($anonsurvey{major},
                                           $anonsurvey{minor},$reqdmajor,$reqdminor);                                            $anonsurvey{minor},$reqdmajor,$reqdminor);
         }          }
           if ($randbytry_subm) {
               ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($randomizetry{major},
                                             $randomizetry{minor},$reqdmajor,$reqdminor);
           }
     }      }
     return ($reqdmajor,$reqdminor);      return ($reqdmajor,$reqdminor);
 }  }
Line 462  sub build_release_hashes { Line 476  sub build_release_hashes {
         }          }
     }      }
     ($anonsurvey{major},$anonsurvey{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});      ($anonsurvey{major},$anonsurvey{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
       ($randomizetry{major},$randomizetry{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
     return;      return;
 }  }
   

Removed from v.1.6  
changed lines
  Added in v.1.9


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