Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.622 and 1.633

version 1.622, 2005/04/12 00:20:00 version 1.633, 2005/05/05 20:50:38
Line 258  sub critical { Line 258  sub critical {
   
 sub transfer_profile_to_env {  sub transfer_profile_to_env {
     my ($lonidsdir,$handle)=@_;      my ($lonidsdir,$handle)=@_;
       undef(%env);
     my @profile;      my @profile;
     {      {
  open(my $idf,"$lonidsdir/$handle.id");   open(my $idf,"$lonidsdir/$handle.id");
Line 827  sub getsection { Line 828  sub getsection {
 }  }
   
 sub save_cache {  sub save_cache {
       my ($r)=@_;
       if (! $r->is_initial_req()) { return DECLINED; }
     &purge_remembered();      &purge_remembered();
     undef(%env);      undef(%env);
       return OK;
 }  }
   
 my $to_remember=-1;  my $to_remember=-1;
Line 875  sub do_cache_new { Line 879  sub do_cache_new {
     if (!defined($setvalue)) {      if (!defined($setvalue)) {
  $setvalue='__undef__';   $setvalue='__undef__';
     }      }
       if (!defined($time) ) {
    $time=600;
       }
     if ($debug) { &Apache::lonnet::logthis("Setting $id to $value"); }      if ($debug) { &Apache::lonnet::logthis("Setting $id to $value"); }
     $memcache->set($id,$setvalue,$time);      $memcache->set($id,$setvalue,$time);
     # need to make a copy of $value      # need to make a copy of $value
Line 2558  sub convert_dump_to_currentdump{ Line 2565  sub convert_dump_to_currentdump{
     return \%returnhash;      return \%returnhash;
 }  }
   
   # ------------------------------------------------------ critical inc interface
   
   sub cinc {
       return &inc(@_,'critical');
   }
   
 # --------------------------------------------------------------- inc interface  # --------------------------------------------------------------- inc interface
   
 sub inc {  sub inc {
     my ($namespace,$store,$udomain,$uname) = @_;      my ($namespace,$store,$udomain,$uname,$critical) = @_;
     if (!$udomain) { $udomain=$env{'user.domain'}; }      if (!$udomain) { $udomain=$env{'user.domain'}; }
     if (!$uname) { $uname=$env{'user.name'}; }      if (!$uname) { $uname=$env{'user.name'}; }
     my $uhome=&homeserver($uname,$udomain);      my $uhome=&homeserver($uname,$udomain);
Line 2579  sub inc { Line 2592  sub inc {
         }          }
     }      }
     $items=~s/\&$//;      $items=~s/\&$//;
     return &reply("inc:$udomain:$uname:$namespace:$items",$uhome);      if ($critical) {
    return &critical("inc:$udomain:$uname:$namespace:$items",$uhome);
       } else {
    return &reply("inc:$udomain:$uname:$namespace:$items",$uhome);
       }
 }  }
   
 # --------------------------------------------------------------- put interface  # --------------------------------------------------------------- put interface
Line 2597  sub put { Line 2614  sub put {
    return &reply("put:$udomain:$uname:$namespace:$items",$uhome);     return &reply("put:$udomain:$uname:$namespace:$items",$uhome);
 }  }
   
 # ---------------------------------------------------------- putstore interface  # ------------------------------------------------------------ newput interface
                                                                                        
   sub newput {
      my ($namespace,$storehash,$udomain,$uname)=@_;
      if (!$udomain) { $udomain=$env{'user.domain'}; }
      if (!$uname) { $uname=$env{'user.name'}; }
      my $uhome=&homeserver($uname,$udomain);
      my $items='';
      foreach my $key (keys(%$storehash)) {
          $items.=&escape($key).'='.&freeze_escape($$storehash{$key}).'&';
      }
      $items=~s/\&$//;
      return &reply("newput:$udomain:$uname:$namespace:$items",$uhome);
   }
   
   # ---------------------------------------------------------  putstore interface
   
 sub putstore {  sub putstore {
    my ($namespace,$storehash,$udomain,$uname)=@_;     my ($namespace,$storehash,$udomain,$uname)=@_;
    if (!$udomain) { $udomain=$env{'user.domain'}; }     if (!$udomain) { $udomain=$env{'user.domain'}; }
Line 3740  sub mark_as_readonly { Line 3772  sub mark_as_readonly {
     my %current_permissions = &dump('file_permissions',$domain,$user);      my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);      my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }      if ($tmp=~/^error:/) { undef(%current_permissions); }
   
     foreach my $file (@{$files}) {      foreach my $file (@{$files}) {
         push(@{$current_permissions{$file}},$what);          push(@{$current_permissions{$file}},$what);
     }      }
Line 3819  sub files_not_in_path { Line 3850  sub files_not_in_path {
   
 #--------------------------------------------------------------Get Marked as Read Only  #--------------------------------------------------------------Get Marked as Read Only
   
   
 sub get_marked_as_readonly {  sub get_marked_as_readonly {
     my ($domain,$user,$what) = @_;      my ($domain,$user,$what) = @_;
     my %current_permissions = &dump('file_permissions',$domain,$user);      my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);      my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }      if ($tmp=~/^error:/) { undef(%current_permissions); }
   
     my @readonly_files;      my @readonly_files;
       my $cmp1=$what;
       if (ref($what)) { $cmp1=join('',@{$what}) };
     while (my ($file_name,$value) = each(%current_permissions)) {      while (my ($file_name,$value) = each(%current_permissions)) {
         if (ref($value) eq "ARRAY"){          if (ref($value) eq "ARRAY"){
             foreach my $stored_what (@{$value}) {              foreach my $stored_what (@{$value}) {
                 if ($stored_what eq $what) {                  my $cmp2=$stored_what;
                   if (ref($stored_what)) { $cmp2=join('',@{$stored_what}) };
                   if ($cmp1 eq $cmp2) {
                     push(@readonly_files, $file_name);                      push(@readonly_files, $file_name);
                 } elsif (!defined($what)) {                  } elsif (!defined($what)) {
                     push(@readonly_files, $file_name);                      push(@readonly_files, $file_name);
Line 3864  sub get_marked_as_readonly_hash { Line 3899  sub get_marked_as_readonly_hash {
 # ------------------------------------------------------------ Unmark as Read Only  # ------------------------------------------------------------ Unmark as Read Only
   
 sub unmark_as_readonly {  sub unmark_as_readonly {
     # unmarks all files locked by $what       # unmarks $file_name (if $file_name is defined), or all files locked by $what 
     # for portfolio submissions, $what contains $crsid and $symb      # for portfolio submissions, $what contains [$symb,$crsid] 
     my ($domain,$user,$what) = @_;      my ($domain,$user,$what,$file_name) = @_;
       my $symb_crs = join('',@$what);
     my %current_permissions = &dump('file_permissions',$domain,$user);      my %current_permissions = &dump('file_permissions',$domain,$user);
     my ($tmp)=keys(%current_permissions);      my ($tmp)=keys(%current_permissions);
     if ($tmp=~/^error:/) { undef(%current_permissions); }      if ($tmp=~/^error:/) { undef(%current_permissions); }
   
     my @readonly_files = &get_marked_as_readonly($domain,$user,$what);      my @readonly_files = &get_marked_as_readonly($domain,$user,$what);
     foreach my $file(@readonly_files){      foreach my $file(@readonly_files){
         my $current_locks = $current_permissions{$file};          my $current_locks = $current_permissions{$file};
Line 3878  sub unmark_as_readonly { Line 3913  sub unmark_as_readonly {
         my @del_keys;          my @del_keys;
         if (ref($current_locks) eq "ARRAY"){          if (ref($current_locks) eq "ARRAY"){
             foreach my $locker (@{$current_locks}) {              foreach my $locker (@{$current_locks}) {
                 unless ($locker eq $what) {                  my $compare=$locker;
                   if (ref($locker)) { $compare=join('',@{$locker}) };
                   if ($compare eq $symb_crs) {
                       if (defined($file_name) && ($file_name ne $file)) {
                           push(@new_locks, $what);
                       }
                   } else {
                     push(@new_locks, $what);                      push(@new_locks, $what);
                 }                  }
             }              }
Line 4082  sub devalidatecourseresdata { Line 4123  sub devalidatecourseresdata {
   
 # --------------------------------------------------- Course Resourcedata Query  # --------------------------------------------------- Course Resourcedata Query
   
 sub courseresdata {  sub get_courseresdata {
     my ($coursenum,$coursedomain,@which)=@_;      my ($coursenum,$coursedomain)=@_;
     my $coursehom=&homeserver($coursenum,$coursedomain);      my $coursehom=&homeserver($coursenum,$coursedomain);
     my $hashid=$coursenum.':'.$coursedomain;      my $hashid=$coursenum.':'.$coursedomain;
     my ($result,$cached)=&is_cached_new('courseres',$hashid);      my ($result,$cached)=&is_cached_new('courseres',$hashid);
       my %dumpreply;
     unless (defined($cached)) {      unless (defined($cached)) {
  my %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);   %dumpreply=&dump('resourcedata',$coursedomain,$coursenum);
  $result=\%dumpreply;   $result=\%dumpreply;
  my ($tmp) = keys(%dumpreply);   my ($tmp) = keys(%dumpreply);
  if ($tmp !~ /^(con_lost|error|no_such_host)/i) {   if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
Line 4100  sub courseresdata { Line 4142  sub courseresdata {
     &do_cache_new('courseres',$hashid,$result,600);      &do_cache_new('courseres',$hashid,$result,600);
  }   }
     }      }
       return $result;
   }
   
   sub devalidateuserresdata {
       my ($uname,$udom)=@_;
       my $hashid="$udom:$uname";
       &devalidate_cache_new('userres',$hashid);
   }
   
   sub get_userresdata {
       my ($uname,$udom)=@_;
       #most student don\'t have any data set, check if there is some data
       if (&EXT_cache_status($udom,$uname)) { return undef; }
   
       my $hashid="$udom:$uname";
       my ($result,$cached)=&is_cached_new('userres',$hashid);
       if (!defined($cached)) {
    my %resourcedata=&dump('resourcedata',$udom,$uname);
    $result=\%resourcedata;
    &do_cache_new('userres',$hashid,$result,600);
       }
       my ($tmp)=keys(%$result);
       if (($tmp!~/^error\:/) && ($tmp!~/^con_lost/)) {
    return $result;
       }
       #error 2 occurs when the .db doesn't exist
       if ($tmp!~/error: 2 /) {
    &logthis("<font color=blue>WARNING:".
    " Trying to get resource data for ".
    $uname." at ".$udom.": ".
    $tmp."</font>");
       } elsif ($tmp=~/error: 2 /) {
    #&EXT_cache_set($udom,$uname);
    &do_cache_new('userres',$hashid,undef,600);
       }
       return $tmp;
   }
   
   sub resdata {
       my ($name,$domain,$type,@which)=@_;
       my $result;
       if ($type eq 'course') {
    $result=&get_courseresdata($name,$domain);
       } elsif ($type eq 'user') {
    $result=&get_userresdata($name,$domain);
       }
       if (!ref($result)) { return $result; }    
     foreach my $item (@which) {      foreach my $item (@which) {
  if (defined($result->{$item})) {   if (defined($result->{$item})) {
     return $result->{$item};      return $result->{$item};
Line 4130  sub EXT_cache_status { Line 4219  sub EXT_cache_status {
 sub EXT_cache_set {  sub EXT_cache_set {
     my ($target_domain,$target_user) = @_;      my ($target_domain,$target_user) = @_;
     my $cachename = 'cache.EXT.'.$target_user.'.'.$target_domain;      my $cachename = 'cache.EXT.'.$target_user.'.'.$target_domain;
     &appenv($cachename => time);      #&appenv($cachename => time);
 }  }
   
 # --------------------------------------------------------- Value of a Variable  # --------------------------------------------------------- Value of a Variable
Line 4285  sub EXT { Line 4374  sub EXT {
     $courselevelm=$courseid.'.'.$mapparm;      $courselevelm=$courseid.'.'.$mapparm;
   
 # ----------------------------------------------------------- first, check user  # ----------------------------------------------------------- first, check user
     #most student don\'t have any data set, check if there is some data  
     if (! &EXT_cache_status($udom,$uname)) {      my $userreply=&resdata($uname,$udom,'user',
  my $hashid="$udom:$uname";         ($courselevelr,$courselevelm,
  my ($result,$cached)=&is_cached_new('userres',$hashid);   $courselevel));
  if (!defined($cached)) {  
     my %resourcedata=&dump('resourcedata',$udom,$uname);      if (defined($userreply)) { return $userreply; }
     $result=\%resourcedata;  
     &do_cache_new('userres',$hashid,$result);  
  }  
  my ($tmp)=keys(%$result);  
  if (($tmp!~/^error\:/) && ($tmp!~/^con_lost/)) {  
     if ($$result{$courselevelr}) {  
  return $$result{$courselevelr}; }  
     if ($$result{$courselevelm}) {  
  return $$result{$courselevelm}; }  
     if ($$result{$courselevel}) {  
  return $$result{$courselevel}; }  
  } else {  
     #error 2 occurs when the .db doesn't exist  
     if ($tmp!~/error: 2 /) {  
  &logthis("<font color=blue>WARNING:".  
  " Trying to get resource data for ".  
  $uname." at ".$udom.": ".  
  $tmp."</font>");  
     } elsif ($tmp=~/error: 2 /) {  
  &EXT_cache_set($udom,$uname);  
     } elsif ($tmp =~ /^(con_lost|no_such_host)/) {  
  return $tmp;  
     }  
  }  
     }  
   
 # ------------------------------------------------ second, check some of course  # ------------------------------------------------ second, check some of course
   
     my $coursereply=&courseresdata($env{'course.'.$courseid.'.num'},      my $coursereply=&resdata($env{'course.'.$courseid.'.num'},
    $env{'course.'.$courseid.'.domain'},       $env{'course.'.$courseid.'.domain'},
    ($seclevelr,$seclevelm,$seclevel,       'course',
     $courselevelr));       ($seclevelr,$seclevelm,$seclevel,
         $courselevelr));
     if (defined($coursereply)) { return $coursereply; }      if (defined($coursereply)) { return $coursereply; }
   
 # ------------------------------------------------------ third, check map parms  # ------------------------------------------------------ third, check map parms
Line 4354  sub EXT { Line 4419  sub EXT {
 # ---------------------------------------------- fourth, look in rest pf course  # ---------------------------------------------- fourth, look in rest pf course
  if ($symbparm && defined($courseid) &&    if ($symbparm && defined($courseid) && 
     $courseid eq $env{'request.course.id'}) {      $courseid eq $env{'request.course.id'}) {
     my $coursereply=&courseresdata($env{'course.'.$courseid.'.num'},      my $coursereply=&resdata($env{'course.'.$courseid.'.num'},
    $env{'course.'.$courseid.'.domain'},       $env{'course.'.$courseid.'.domain'},
    ($courselevelm,$courselevel));       'course',
        ($courselevelm,$courselevel));
     if (defined($coursereply)) { return $coursereply; }      if (defined($coursereply)) { return $coursereply; }
  }   }
 # ------------------------------------------------------------------ Cascade up  # ------------------------------------------------------------------ Cascade up
Line 4620  sub metadata { Line 4686  sub metadata {
  $metaentry{':keys'}=join(',',keys %metathesekeys);   $metaentry{':keys'}=join(',',keys %metathesekeys);
  &metadata_generate_part0(\%metathesekeys,\%metaentry,$uri);   &metadata_generate_part0(\%metathesekeys,\%metaentry,$uri);
  $metaentry{':allpossiblekeys'}=join(',',keys %metathesekeys);   $metaentry{':allpossiblekeys'}=join(',',keys %metathesekeys);
  &do_cache_new('meta',$uri,\%metaentry);   &do_cache_new('meta',$uri,\%metaentry,60*60*24);
 # this is the end of "was not already recently cached  # this is the end of "was not already recently cached
     }      }
     return $metaentry{':'.$what};      return $metaentry{':'.$what};
Line 4916  sub symbread { Line 4982  sub symbread {
                  if ($#possibilities==0) {                   if ($#possibilities==0) {
 # ----------------------------------------------- There is only one possibility  # ----------------------------------------------- There is only one possibility
      my ($mapid,$resid)=split(/\./,$ids);       my ($mapid,$resid)=split(/\./,$ids);
                      $syval=declutter($bighash{'map_id_'.$mapid}).'___'.$resid;       $syval=&encode_symb($bighash{'map_id_'.$mapid},
       $resid,$thisfn);
                  } elsif (!$donotrecurse) {                   } elsif (!$donotrecurse) {
 # ------------------------------------------ There is more than one possibility  # ------------------------------------------ There is more than one possibility
                      my $realpossible=0;                       my $realpossible=0;
Line 4926  sub symbread { Line 4993  sub symbread {
              my ($mapid,$resid)=split(/\./,$_);               my ($mapid,$resid)=split(/\./,$_);
                             if ($bighash{'map_type_'.$mapid} ne 'page') {                              if ($bighash{'map_type_'.$mapid} ne 'page') {
  $realpossible++;   $realpossible++;
                                 $syval=declutter($bighash{'map_id_'.$mapid}).                                  $syval=&encode_symb($bighash{'map_id_'.$mapid},
                                        '___'.$resid;      $resid,$thisfn);
                             }                              }
  }   }
                      }                       }
Line 4941  sub symbread { Line 5008  sub symbread {
         }          }
         if ($syval) {          if ($syval) {
     return $env{$cache_str}=$syval;      return $env{$cache_str}=$syval;
     #return $env{$cache_str}=&symbclean($syval.'___'.$thisfn);  
         }          }
     }      }
     &appenv('request.ambiguous' => $thisfn);      &appenv('request.ambiguous' => $thisfn);
Line 6136  revokecustomrole($udom,$uname,$url,$role Line 6202  revokecustomrole($udom,$uname,$url,$role
   
 =item *  =item *
   
 coursedescription($courseid) : course description  coursedescription($courseid) : returns a hash of information about the
   specified course id, including all environment settings for the
   course, the description of the course will be in the hash under the
   key 'description'
   
 =item *  =item *
   
 courseresdata($coursenum,$coursedomain,@which) : request for current  resdata($name,$domain,$type,@which) : request for current parameter
 parameter setting for a specific course, @what should be a list of  setting for a specific $type, where $type is either 'course' or 'user',
 parameters to ask about. This routine caches answers for 5 minutes.  @what should be a list of parameters to ask about. This routine caches
   answers for 5 minutes.
   
 =back  =back
   

Removed from v.1.622  
changed lines
  Added in v.1.633


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