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

www lon-capa-cvs@mail.lon-capa.org
Fri, 26 Dec 2003 19:12:51 -0000


www		Fri Dec 26 14:12:51 2003 EDT

  Modified files:              
    /loncom/interface	lonmysql.pm 
    /loncom/publisher	lonpublisher.pm 
  Log:
  Was trying to store UNIX timestamps into MySQL DATE field
  
  
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.15 loncom/interface/lonmysql.pm:1.16
--- loncom/interface/lonmysql.pm:1.15	Mon Jun  2 13:01:05 2003
+++ loncom/interface/lonmysql.pm	Fri Dec 26 14:12:51 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # MySQL utility functions
 #
-# $Id: lonmysql.pm,v 1.15 2003/06/02 17:01:05 matthew Exp $
+# $Id: lonmysql.pm,v 1.16 2003/12/26 19:12:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,6 +32,8 @@
 use strict;
 use DBI;
 use Apache::lonnet();
+use POSIX qw(strftime mktime);
+
 
 ######################################################################
 ######################################################################
@@ -1041,6 +1043,39 @@
     delete($Tables{$table_id}); # remove any knowledge of the table
     return 1; # if we got here there was no error, so return a 'true' value
 }
+
+
+
+
+# ---------------------------- convert 'time' format into a datetime sql format
+sub sqltime {
+    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
+	localtime(&unsqltime($_[0]));
+    $mon++; $year+=1900;
+    return "$year-$mon-$mday $hour:$min:$sec";
+}
+
+sub maketime {
+    my %th=@_;
+    return POSIX::mktime(($th{'seconds'},$th{'minutes'},$th{'hours'},
+                          $th{'day'},$th{'month'}-1,
+                          $th{'year'}-1900,0,0,$th{'dlsav'}));
+}
+
+
+#########################################
+#
+# Retro-fixing of un-backward-compatible time format
+
+sub unsqltime {
+    my $timestamp=shift;
+    if ($timestamp=~/^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/) {
+        $timestamp=&maketime('year'=>$1,'month'=>$2,'day'=>$3,
+                             'hours'=>$4,'minutes'=>$5,'seconds'=>$6);
+    }
+    return $timestamp;
+}
+
 
 1;
 
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.151 loncom/publisher/lonpublisher.pm:1.152
--- loncom/publisher/lonpublisher.pm:1.151	Fri Dec 26 13:25:29 2003
+++ loncom/publisher/lonpublisher.pm	Fri Dec 26 14:12:51 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.151 2003/12/26 18:25:29 www Exp $
+# $Id: lonpublisher.pm,v 1.152 2003/12/26 19:12:51 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -784,7 +784,19 @@
         &Apache::lonnet::logthis($error);
         return ($error,undef);
     }
-    $status = &Apache::lonmysql::store_row('metadata',\%metadata);
+    if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv') ||
+	($metadata{'copyright'} eq 'custom')) {
+# remove this entry
+	$status=&Apache::lonmysql::remove_from_table
+	    ('metadata','url',$metadata{'url'});
+    } else {
+# store new data
+	$metadata{'creationdate'}=
+	    &Apache::lonmysql::sqltime($metadata{'creationdate'}); 
+	$metadata{'lastrevisiondate'}=
+	    &Apache::lonmysql::sqltime($metadata{'lastrevisiondate'}); 
+	$status = &Apache::lonmysql::store_row('metadata',\%metadata);
+    }
     if (! defined($status)) {
         $error='<font color="red">Error occured storing new values in '.
             'metadata table in LON-CAPA database</font>';
@@ -1324,6 +1336,9 @@
     $metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'};
     $metadatafields{'owner'}=$ENV{'form.owner'};
     $metadatafields{'copyright'}=$ENV{'form.copyright'};
+    $metadatafields{'standards'}=$ENV{'form.standards'};
+    $metadatafields{'lowestgradelevel'}=$ENV{'form.lowestgradelevel'};
+    $metadatafields{'highestgradelevel'}=$ENV{'form.highestgradelevel'};
     $metadatafields{'customdistributionfile'}=
                                  $ENV{'form.customdistributionfile'};
     $metadatafields{'obsolete'}=$ENV{'form.obsolete'};
@@ -1385,21 +1400,16 @@
 
     $metadatafields{'url'} = $distarget;
     $metadatafields{'version'} = 'current';
-    unless ($metadatafields{'copyright'} eq 'priv') {
-        my ($error,$success) = &store_metadata(\%metadatafields);
-        if ($success) {
-            $r->print('<p>'.&mt('Synchronized SQL metadata database').'</p>');
-            print $logfile "\nSynchronized SQL metadata database";
-        } else {
-            $r->print($error);
-            print $logfile "\n".$error;
-        }
+
+    my ($error,$success) = &store_metadata(%metadatafields);
+    if ($success) {
+	$r->print('<p>'.&mt('Synchronized SQL metadata database').'</p>');
+	print $logfile "\nSynchronized SQL metadata database";
     } else {
-        $r->print('<p>'.
-	     &mt('Private Publication - did not synchronize database').'</p>');
-        print $logfile "\nPrivate: Did not synchronize data into ".
-            "SQL metadata database";
+	$r->print($error);
+	print $logfile "\n".$error;
     }
+
 # ----------------------------------------------------------- Copy old versions
    
     if (-e $target) {