[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 04 Jan 2008 18:08:12 -0000


raeburn		Fri Jan  4 13:08:12 2008 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - Updated domain configuration interface allows modification of a few components at a time - potentially leaving others still using data/files from the legacy definitions in lonDomColors and lonDomLogos (for older domains).
  - Retrieve legacy data when displaying pages for domains that have partially transitioned to storage in configuration.db
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.631 loncom/interface/loncommon.pm:1.632
--- loncom/interface/loncommon.pm:1.631	Thu Jan  3 19:20:56 2008
+++ loncom/interface/loncommon.pm	Fri Jan  4 13:08:11 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.631 2008/01/04 00:20:56 raeburn Exp $
+# $Id: loncommon.pm,v 1.632 2008/01/04 18:08:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3670,45 +3670,78 @@
 
     my %domconfig = &Apache::lonnet::get_dom('configuration',
 					     ['login','rolecolors'],$udom);
-    my %designhash;
+    my (%designhash,%legacy);
     if (keys(%domconfig) > 0) {
         if (ref($domconfig{'login'}) eq 'HASH') {
-            foreach my $key (keys(%{$domconfig{'login'}})) {
-                $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
+            if (keys(%{$domconfig{'login'}})) {
+                foreach my $key (keys(%{$domconfig{'login'}})) {
+                    $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
+                }
+            } else {
+                $legacy{'login'} = 1;
             }
+        } else {
+            $legacy{'login'} = 1;
         }
         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
-            foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
-                if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
-                    foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
-                        $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
+            if (keys(%{$domconfig{'rolecolors'}})) {
+                foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
+                    if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
+                        foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
+                            $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
+                        }
                     }
                 }
+            } else {
+                $legacy{'rolecolors'} = 1;
             }
+        } else {
+            $legacy{'rolecolors'} = 1;
         }
-    } else {
-        my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
-        my $designfile =  $designdir.'/'.$udom.'.tab';
-        if (-e $designfile) {
-            if ( open (my $fh,"<$designfile") ) {
-                while (my $line = <$fh>) {
-                    next if ($line =~ /^\#/);
-                    chomp($line);
-                    my ($key,$val)=(split(/\=/,$line));
-                    if ($val) { $designhash{$udom.'.'.$key}=$val; }
+        if (keys(%legacy) > 0) {
+            my %legacyhash = &get_legacy_domconf($udom);
+            foreach my $item (keys(%legacyhash)) {
+                if ($item =~ /^\Q$udom\E\.login/) {
+                    if ($legacy{'login'}) { 
+                        $designhash{$item} = $legacyhash{$item};
+                    }
+                } else {
+                    if ($legacy{'rolecolors'}) {
+                        $designhash{$item} = $legacyhash{$item};
+                    }
                 }
-                close($fh);
             }
         }
-        if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
-            $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
-        }
+    } else {
+        %designhash = &get_legacy_domconf($udom); 
     }
     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
 				  $cachetime);
     return %designhash;
 }
 
+sub get_legacy_domconf {
+    my ($udom) = @_;
+    my %legacyhash;
+    my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
+    my $designfile =  $designdir.'/'.$udom.'.tab';
+    if (-e $designfile) {
+        if ( open (my $fh,"<$designfile") ) {
+            while (my $line = <$fh>) {
+                next if ($line =~ /^\#/);
+                chomp($line);
+                my ($key,$val)=(split(/\=/,$line));
+                if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
+            }
+            close($fh);
+        }
+    }
+    if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
+        $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
+    }
+    return %legacyhash;
+}
+
 =pod
 
 =item * &domainlogo()