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

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 12 Oct 2005 21:48:32 -0000


albertel		Wed Oct 12 17:48:32 2005 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm 
  Log:
  - wasn't updating the internal memory spreadsheet cache when saving to the external remote spreadsheet cache, now both stay in sync
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.56 loncom/interface/spreadsheet/Spreadsheet.pm:1.57
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.56	Thu Sep  1 17:52:56 2005
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Wed Oct 12 17:48:32 2005
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.56 2005/09/01 21:52:56 albertel Exp $
+# $Id: Spreadsheet.pm,v 1.57 2005/10/12 21:48:32 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1623,7 +1623,7 @@
         $self->{'row_source'}=$spreadsheets{$cachekey}->{'row_source'};
         $self->{'row_numbers'}=$spreadsheets{$cachekey}->{'row_numbers'};
         $self->{'maxrow'}=$spreadsheets{$cachekey}->{'maxrow'};
-   } else {
+    } else {
         # Not cached, need to read
         if (! defined($filename)) {
             $formulas = $self->load_system_default_sheet();
@@ -1656,24 +1656,33 @@
                 $formulas = $self->load_system_default_sheet();
             }
         }
-        $filename=$self->filename(); # filename may have changed
-	$cachekey = join('_',($cnum,$cdom,$stype,$filename));
-	if (ref($formulas) eq 'HASH') {
-	    %{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas};
-	}
 	$self->formulas($formulas);
 	$self->set_row_sources();
 	$self->set_row_numbers();
-	if (ref($self->{'row_source'})) {
-	    %{$spreadsheets{$cachekey}->{'row_source'}} = 
-		%{$self->{'row_source'}};
-	}
-	if (ref($self->{'row_numbers'})) {
-	    %{$spreadsheets{$cachekey}->{'row_numbers'}} = 
-		%{$self->{'row_numbers'}};
-	}
-        $spreadsheets{$cachekey}->{'maxrow'} = $self->{'maxrow'};
+	$self->cache_sheet($formulas);
+    }
+}
+
+sub cache_sheet {
+    my $self = shift;
+    my $formulas=(@_);
+    my $stype = $self->{'type'};
+    my $cnum  = $self->{'cnum'};
+    my $cdom  = $self->{'cdom'};
+    #
+    my $filename = $self->filename();
+    my $cachekey = join('_',($cnum,$cdom,$stype,$filename));
+
+    if (ref($self->{'formulas'}) eq 'HASH') {
+	%{$spreadsheets{$cachekey}->{'formulas'}} = %{$formulas};
+    }
+    if (ref($self->{'row_source'})) {
+	%{$spreadsheets{$cachekey}->{'row_source'}} =%{$self->{'row_source'}};
+    }
+    if (ref($self->{'row_numbers'})) {
+	%{$spreadsheets{$cachekey}->{'row_numbers'}}=%{$self->{'row_numbers'}};
     }
+    $spreadsheets{$cachekey}->{'maxrow'} = $self->{'maxrow'};
 }
 
 sub set_row_sources {
@@ -1725,9 +1734,8 @@
         my $cnum  = $self->{'cnum'};
         my $cdom  = $self->{'cdom'};
         my $filename    = $self->{'filename'};
-        my $cachekey = join('_',($cnum,$cdom,$stype,$filename));
         # Cache new sheet
-        %{$spreadsheets{$cachekey}->{'formulas'}}=%f;
+	$self->cache_sheet(\%f);
         # Write sheet
         foreach (keys(%f)) {
             delete($f{$_}) if ($f{$_} eq 'import');