Diff for /loncom/misc/refresh_courseids_db.pl between versions 1.1 and 1.2

version 1.1, 2010/03/14 23:17:54 version 1.2, 2010/03/15 20:13:14
Line 78  foreach my $dom (@domains) { Line 78  foreach my $dom (@domains) {
     my @ids=&Apache::lonnet::current_machine_ids();      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 $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,$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 95  print $fh "==== refresh_courseids.db com Line 97  print $fh "==== refresh_courseids.db com
 close($fh);  close($fh);
   
 sub recurse_courses {  sub recurse_courses {
     my ($cdom,$dir,$depth,$courseshash,$currhash,$fh) = @_;      my ($cdom,$dir,$depth,$courseshash,$currhash,$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 106  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,$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 140  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);
                 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 163  sub recurse_courses { Line 168  sub recurse_courses {
                 $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 204  sub recurse_courses { Line 208  sub recurse_courses {
                         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 217  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'};
                       }
                     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";
                        }                          }
                     }                      }
                 }                  }
             }              }
Line 234  sub recurse_courses { Line 281  sub recurse_courses {
     return;      return;
 }  }
   
   
   

Removed from v.1.1  
changed lines
  Added in v.1.2


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