[LON-CAPA-cvs] cvs: loncom / lond

raeburn raeburn at source.lon-capa.org
Wed Apr 11 02:22:05 EDT 2012


raeburn		Wed Apr 11 06:22:05 2012 EDT

  Modified files:              
    /loncom	lond 
  Log:
  - Change in args passed to &check_homecourses().
    Eliminate user's domain ($udom) as arg.
    - %homecourses is now hash of hash of array, where outer hash key is domain
      of course role, and inner hash key is coursenum of course role.
   (Addresses corner case: LON-CAPA version checking in lond for roles retrieval 
    for a user for whom home server is a multi-domain server, and where user 
    session is hosted on 2.9 or older, and where course domain is different to
    user domain, but current server is home server for both user and course).
  
  
Index: loncom/lond
diff -u loncom/lond:1.488 loncom/lond:1.489
--- loncom/lond:1.488	Wed Apr 11 01:07:18 2012
+++ loncom/lond	Wed Apr 11 06:22:04 2012
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.488 2012/04/11 01:07:18 raeburn Exp $
+# $Id: lond,v 1.489 2012/04/11 06:22:04 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,7 +60,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.488 $'; #' stupid emacs
+my $VERSION='$Revision: 1.489 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -3365,7 +3365,7 @@
 #
             if (($namespace eq 'roles') && (!$skipcheck)) {
                 if (keys(%homecourses) > 0) {
-                    $qresult .= &check_homecourses(\%homecourses,$udom,$regexp,$count,
+                    $qresult .= &check_homecourses(\%homecourses,$regexp,$count,
                                                    $range,$start,$end,$major,$minor);
                 }
             }
@@ -7517,10 +7517,18 @@
         if (ref($ids) eq 'ARRAY') {
             if (grep(/^\Q$home\E$/,@{$ids})) {
                 if (ref($homecourses) eq 'HASH') {
-                    if (ref($homecourses->{$hashid}) eq 'ARRAY') {
-                        push(@{$homecourses->{$hashid}},{$key=>$value});
+                    if (ref($homecourses->{$cdom}) eq 'HASH') {
+                        if (ref($homecourses->{$cdom}{$cnum}) eq 'HASH') {
+                            if (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY') {
+                                push(@{$homecourses->{$cdom}{$cnum}},{$key=>$value});
+                            } else {
+                                $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
+                            }
+                        } else {
+                            $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
+                        }
                     } else {
-                        $homecourses->{$hashid} = [{$key=>$value}];
+                        $homecourses->{$cdom}{$cnum} = [{$key=>$value}];
                     }
                 }
                 return;
@@ -7595,42 +7603,44 @@
 # 
 
 sub check_homecourses {
-    my ($homecourses,$udom,$regexp,$count,$range,$start,$end,$major,$minor) = @_;
+    my ($homecourses,$regexp,$count,$range,$start,$end,$major,$minor) = @_;
     my ($result,%addtocache);
     my $yesterday = time - 24*3600; 
     if (ref($homecourses) eq 'HASH') {
         my (%okcourses,%courseinfo,%recent);
-        my $hashref = &tie_domain_hash($udom, "nohist_courseids", &GDBM_WRCREAT());
-        if ($hashref) {
-            while (my ($key,$value) = each(%$hashref)) {
-                my $unesc_key = &unescape($key);
-                if ($unesc_key =~ /^lasttime:(\w+)$/) {
-                    my $cid = $1;
-                    $cid =~ s/_/:/;
-                    if ($value > $yesterday ) {
-                        $recent{$cid} = 1;
+        foreach my $domain (keys(%{$homecourses})) {
+            my $hashref = 
+                &tie_domain_hash($domain, "nohist_courseids", &GDBM_WRCREAT());
+            if (ref($hashref) eq 'HASH') {
+                while (my ($key,$value) = each(%$hashref)) {
+                    my $unesc_key = &unescape($key);
+                    if ($unesc_key =~ /^lasttime:(\w+)$/) {
+                        my $cid = $1;
+                        $cid =~ s/_/:/;
+                        if ($value > $yesterday ) {
+                            $recent{$cid} = 1;
+                        }
+                        next;
                     }
-                    next;
-                }
-                my $items = &Apache::lonnet::thaw_unescape($value);
-                if (ref($items) eq 'HASH') {
-                    my $hashid = $unesc_key;
-                    $hashid =~ s/_/:/;
-                    $courseinfo{$hashid} = $items;
-                    if (ref($homecourses->{$hashid}) eq 'ARRAY') {
-                        my ($reqdmajor,$reqdminor) = split(/\./,$items->{'releaserequired'});
-                        if (&useable_role($reqdmajor,$reqdminor,$major,$minor)) {
-                            $okcourses{$hashid} = 1;
+                    my $items = &Apache::lonnet::thaw_unescape($value);
+                    if (ref($items) eq 'HASH') {
+                        my ($cdom,$cnum) = split(/_/,$unesc_key);
+                        my $hashid = $cdom.':'.$cnum; 
+                        $courseinfo{$hashid} = $items;
+                        if (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY') {
+                            my ($reqdmajor,$reqdminor) = split(/\./,$items->{'releaserequired'});
+                            if (&useable_role($reqdmajor,$reqdminor,$major,$minor)) {
+                               $okcourses{$hashid} = 1;
+                            }
                         }
                     }
                 }
+                unless (&untie_domain_hash($hashref)) {
+                    &logthis("Failed to untie tied hash for nohist_courseids.db for $domain");
+                }
+            } else {
+                &logthis("Failed to tie hash for nohist_courseids.db for $domain");
             }
-            unless (&untie_domain_hash($hashref)) {
-                &logthis('Failed to untie tied hash for nohist_courseids.db');
-            }
-        } else {
-            &logthis('Failed to tie hash for nohist_courseids.db');
-            return;
         }
         foreach my $hashid (keys(%recent)) {
             my ($result,$cached)=&Apache::lonnet::is_cached_new('courseinfo',$hashid);
@@ -7638,13 +7648,20 @@
                 &Apache::lonnet::do_cache_new('courseinfo',$hashid,$courseinfo{$hashid},600);
             }
         }
-        foreach my $hashid (keys(%{$homecourses})) {
-            next if ($recent{$hashid});
-            &Apache::lonnet::do_cache_new('courseinfo',$hashid,$courseinfo{$hashid},600);
+        foreach my $cdom (keys(%{$homecourses})) {
+            if (ref($homecourses->{$cdom}) eq 'HASH') {
+                foreach my $cnum (keys(%{$homecourses->{$cdom}})) {
+                    my $hashid = $cdom.':'.$cnum;
+                    next if ($recent{$hashid});
+                    &Apache::lonnet::do_cache_new('courseinfo',$hashid,$courseinfo{$hashid},600);
+                }
+            }
         }
         foreach my $hashid (keys(%okcourses)) {
-            if (ref($homecourses->{$hashid}) eq 'ARRAY') {
-                foreach my $role (@{$homecourses->{$hashid}}) {
+            my ($cdom,$cnum) = split(/:/,$hashid);
+            if ((ref($homecourses->{$cdom}) eq 'HASH') &&  
+                (ref($homecourses->{$cdom}{$cnum}) eq 'ARRAY')) {
+                foreach my $role (@{$homecourses->{$cdom}{$cnum}}) {
                     if (ref($role) eq 'HASH') {
                         while (my ($key,$value) = each(%{$role})) {
                             if ($regexp eq '.') {




More information about the LON-CAPA-cvs mailing list