[LON-CAPA-cvs] cvs: loncom /interface lonmysql.pm /publisher lonpublisher.pm

www lon-capa-cvs@mail.lon-capa.org
Sat, 27 Dec 2003 16:58:36 -0000


www		Sat Dec 27 11:58:36 2003 EDT

  Modified files:              
    /loncom/interface	lonmysql.pm 
    /loncom/publisher	lonpublisher.pm 
  Log:
  Update metadata entry on re-publication
  
  
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.17 loncom/interface/lonmysql.pm:1.18
--- loncom/interface/lonmysql.pm:1.17	Fri Dec 26 20:44:49 2003
+++ loncom/interface/lonmysql.pm	Sat Dec 27 11:58:36 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # MySQL utility functions
 #
-# $Id: lonmysql.pm,v 1.17 2003/12/27 01:44:49 www Exp $
+# $Id: lonmysql.pm,v 1.18 2003/12/27 16:58:36 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -559,7 +559,27 @@
     $debugstring = "Retrieved table info for $tablename";
     return 1;
 }
+###############################
+
+=pod
+
+=item &col_order()
+
+Inputs: table id
 
+Returns: array with column order
+
+=cut
+
+
+sub col_order {
+    my $table_id=shift;
+    if (&update_table_info($table_id)) {
+	return @{$Tables{$table_id}->{'Col_order'}};
+    } else {
+	return ();
+    }
+}
 ###############################
 
 =pod
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.154 loncom/publisher/lonpublisher.pm:1.155
--- loncom/publisher/lonpublisher.pm:1.154	Sat Dec 27 09:42:57 2003
+++ loncom/publisher/lonpublisher.pm	Sat Dec 27 11:58:36 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.154 2003/12/27 14:42:57 www Exp $
+# $Id: lonpublisher.pm,v 1.155 2003/12/27 16:58:36 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -791,11 +791,41 @@
 	    ('metadata','url',$metadata{'url'});
     } else {
 # store new data
+# adjust some values to metadatadatabase (e.g., "usage" is a reserved word)
 	$metadata{'creationdate'}=
 	    &Apache::lonmysql::sqltime($metadata{'creationdate'}); 
 	$metadata{'lastrevisiondate'}=
-	    &Apache::lonmysql::sqltime($metadata{'lastrevisiondate'}); 
-	$status = &Apache::lonmysql::store_row('metadata',\%metadata);
+	    &Apache::lonmysql::sqltime($metadata{'lastrevisiondate'});
+	$metadata{'sequsage'}=$metadata{'usage'};
+	$metadata{'sequsage_list'}=$metadata{'usage_list'};
+	my %newmetadata=();
+# retrieve current database column names
+	my @columns=&Apache::lonmysql::col_order('metadata');
+# see if we have old entries
+	my @oldmeta=&Apache::lonmysql::get_rows('metadata',
+						"url LIKE BINARY '".
+						$metadata{'url'}."'");
+	if ($#oldmeta==0) {
+# there is an old value
+	    for (my $i=0; $i<=$#columns; $i++) {
+		$newmetadata{$columns[$i]}=$oldmeta[0]->[$i];
+	    }
+# remove old entry
+	    $status=&Apache::lonmysql::remove_from_table
+		('metadata','url',$metadata{'url'});
+	} elsif ($#oldmeta>0) {
+# more than one entry fit - how did that happen?
+	    $error='<font color="red">Error occured retrieving old values in '.
+	      'metadata table in LON-CAPA database: '.$#oldmeta.
+	      ' matches</font>';
+	    &Apache::lonnet::logthis($error);
+	    return ($error,undef);
+	}
+# store new data on top of it
+	foreach (keys %metadata) {
+	    $newmetadata{$_}=$metadata{$_};
+	}
+	$status = &Apache::lonmysql::store_row('metadata',\%newmetadata);
     }
     if (! defined($status)) {
         $error='<font color="red">Error occured storing new values in '.