[LON-CAPA-cvs] cvs: loncom /metadata_database searchcat.pl /metadata_database/LONCAPA lonmetadata.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 29 Dec 2006 19:15:31 -0000


raeburn		Fri Dec 29 14:15:31 2006 EDT

  Modified files:              
    /loncom/metadata_database	searchcat.pl 
    /loncom/metadata_database/LONCAPA	lonmetadata.pm 
  Log:
  Moving &sqltime() from searchcat.pl to lonmetadata.pm so it can accessed elsewhere when usin Apache::lonmetadata().
  
  
Index: loncom/metadata_database/searchcat.pl
diff -u loncom/metadata_database/searchcat.pl:1.70 loncom/metadata_database/searchcat.pl:1.71
--- loncom/metadata_database/searchcat.pl:1.70	Sun Dec 10 19:32:24 2006
+++ loncom/metadata_database/searchcat.pl	Fri Dec 29 14:15:27 2006
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # searchcat.pl "Search Catalog" batch script
 #
-# $Id: searchcat.pl,v 1.70 2006/12/11 00:32:24 albertel Exp $
+# $Id: searchcat.pl,v 1.71 2006/12/29 19:15:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -332,9 +332,9 @@
                         ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
         $acc_data->{scope} = $scope;
         if ($end != 0) {
-            $acc_data->{end} = &sqltime($end);
+            $acc_data->{end} = &LONCAPA::lonmetadata::sqltime($end);
         }
-        $acc_data->{start} = &sqltime($start);
+        $acc_data->{start} = &LONCAPA::lonmetadata::sqltime($start);
         if (! $simulate) {
             my ($count,$err) =
               &LONCAPA::lonmetadata::store_metadata($dbh,
@@ -692,8 +692,10 @@
         $ref->{'lastrevisiondate'} =~ /^\s*$/) {
         $ref->{'lastrevisiondate'} = (stat($target))[9];
     }
-    $ref->{'creationdate'}     = &sqltime($ref->{'creationdate'});
-    $ref->{'lastrevisiondate'} = &sqltime($ref->{'lastrevisiondate'});
+    $ref->{'creationdate'}     = 
+        &LONCAPA::lonmetadata::sqltime($ref->{'creationdate'});
+    $ref->{'lastrevisiondate'} = 
+        &LONCAPA::lonmetadata::sqltime($ref->{'lastrevisiondate'});
 }
 
 ########################################################
@@ -888,41 +890,6 @@
 } 
 
 ##
-## &sqltime($timestamp)
-##
-## Convert perl $timestamp to MySQL time.  MySQL expects YYYY-MM-DD HH:MM:SS
-##
-sub sqltime {
-    my ($time) = @_;
-    my $mysqltime;
-    if ($time =~ 
-        /(\d+)-(\d+)-(\d+) # YYYY-MM-DD
-        \s                 # a space
-        (\d+):(\d+):(\d+)  # HH:MM::SS
-        /x ) { 
-        # Some of the .meta files have the time in mysql
-        # format already, so just make sure they are 0 padded and
-        # pass them back.
-        $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
-                             $1,$2,$3,$4,$5,$6);
-    } elsif ($time =~ /^\d+$/) {
-        my @TimeData = gmtime($time);
-        # Alter the month to be 1-12 instead of 0-11
-        $TimeData[4]++;
-        # Alter the year to be from 0 instead of from 1900
-        $TimeData[5]+=1900;
-        $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
-                             @TimeData[5,4,3,2,1,0]);
-    } elsif (! defined($time) || $time == 0) {
-        $mysqltime = 0;
-    } else {
-        &log(0,"    sqltime:Unable to decode time ".$time);
-        $mysqltime = 0;
-    }
-    return $mysqltime;
-}
-
-##
 ## &declutter($filename)
 ##   Given a filename, returns a url for the filename.
 sub declutter {
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.14 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.15
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.14	Tue Sep 26 11:15:31 2006
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm	Fri Dec 29 14:15:28 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonmetadata.pm,v 1.14 2006/09/26 15:15:31 raeburn Exp $
+# $Id: lonmetadata.pm,v 1.15 2006/12/29 19:15:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -931,6 +931,41 @@
 ######################################################################
 ######################################################################
 
+## Utility originally in searchcat.pl.  Moved to be more widely available. 
+##
+## &sqltime($timestamp)
+##
+## Convert perl $timestamp to MySQL time.  MySQL expects YYYY-MM-DD HH:MM:SS
+##
+sub sqltime {
+    my ($time) = @_;
+    my $mysqltime;
+    if ($time =~
+        /(\d+)-(\d+)-(\d+) # YYYY-MM-DD
+        \s                 # a space
+        (\d+):(\d+):(\d+)  # HH:MM::SS
+        /x ) {
+        # Some of the .meta files have the time in mysql
+        # format already, so just make sure they are 0 padded and
+        # pass them back.
+        $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
+                             $1,$2,$3,$4,$5,$6);
+    } elsif ($time =~ /^\d+$/) {
+        my @TimeData = gmtime($time);
+        # Alter the month to be 1-12 instead of 0-11
+        $TimeData[4]++;
+        # Alter the year to be from 0 instead of from 1900
+        $TimeData[5]+=1900;
+        $mysqltime = sprintf('%04d-%02d-%02d %02d:%02d:%02d',
+                             @TimeData[5,4,3,2,1,0]);
+    } elsif (! defined($time) || $time == 0) {
+        $mysqltime = 0;
+    } else {
+        &log(0,"    sqltime:Unable to decode time ".$time);
+        $mysqltime = 0;
+    }
+    return $mysqltime;
+}
 
 ######################################################################
 ######################################################################