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

raeburn raeburn@source.lon-capa.org
Sun, 31 Jan 2010 03:12:03 -0000


raeburn		Sun Jan 31 03:12:03 2010 EDT

  Modified files:              
    /loncom/metadata_database/LONCAPA	lonmetadata.pm 
  Log:
  - Logging when &sqltime() is unable to convert time.
    - Replace direct call to &log() originally used for this 
      from time when &sqltime() was in lonsearchcat.pm;
      (moved to lonmetadata.pm in rev 1.15). 
  
  
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.27 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.28
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.27	Wed Apr 29 15:21:00 2009
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm	Sun Jan 31 03:12:03 2010
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonmetadata.pm,v 1.27 2009/04/29 15:21:00 bisitz Exp $
+# $Id: lonmetadata.pm,v 1.28 2010/01/31 03:12:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1080,10 +1080,14 @@
                             ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
             next if (($scope ne 'public') && ($scope ne 'guest'));
             $acc_data->{scope} = $scope;
+            my $sqltime_error;
             if ($end != 0) {
-                $acc_data->{end} = &sqltime($end);
+                $acc_data->{end} = &sqltime($end,\$sqltime_error);
+            }
+            $acc_data->{start} = &sqltime($start,\$sqltime_error);
+            if ($sqltime_error) {
+                $loghash{$key}{'err'} = $sqltime_error;
             }
-            $acc_data->{start} = &sqltime($start);
             if (! $simulate) {
                 my ($count,$err) =
                      &store_metadata($dbh,$newnames->{'access'},
@@ -1127,7 +1131,8 @@
     if (-e $fullpath) {
         my ($ref,$crs,$addedfields) = &portfolio_metadata($fullpath,$dom,$uname,
                                                           $group);
-        &getfiledates($ref,$fullpath);
+        my $sqltime_error;
+        &getfiledates($ref,$fullpath,\$sqltime_error);
         if ($is_course) {
             $ref->{'groupname'} = $group;
         }
@@ -1142,6 +1147,9 @@
         );
         my %loghash;
         if (! $simulate) {
+            if ($sqltime_error) {
+                $loghash{'metadata'."\0"}{'err'} = $sqltime_error;
+            }
             my ($count,$err) =
             &store_metadata($dbh,$newnames->{'portfolio'},'portfolio_metadata',
                             \%Data);
@@ -1233,11 +1241,11 @@
 }
 
 ##
-## &getfiledates()
+## &getfiledates($ref,$target,$sqltime_error)
 ## Converts creationdate and modifieddates to SQL format
 ## Applies stat() to file to retrieve dates if missing
 sub getfiledates {
-    my ($ref,$target) = @_;
+    my ($ref,$target,$sqltime_error) = @_;
     if (! defined($ref->{'creationdate'}) ||
         $ref->{'creationdate'} =~ /^\s*$/) {
         $ref->{'creationdate'} = (stat($target))[9];
@@ -1246,17 +1254,17 @@
         $ref->{'lastrevisiondate'} =~ /^\s*$/) {
         $ref->{'lastrevisiondate'} = (stat($target))[9];
     }
-    $ref->{'creationdate'}     = &sqltime($ref->{'creationdate'});
-    $ref->{'lastrevisiondate'} = &sqltime($ref->{'lastrevisiondate'});
+    $ref->{'creationdate'}     = &sqltime($ref->{'creationdate'},$sqltime_error);
+    $ref->{'lastrevisiondate'} = &sqltime($ref->{'lastrevisiondate'},$sqltime_error);
 }
  
 ##
-## &sqltime($timestamp)
+## &sqltime($timestamp,$sqltime_error)
 ##
 ## Convert perl $timestamp to MySQL time.  MySQL expects YYYY-MM-DD HH:MM:SS
 ##
 sub sqltime {
-    my ($time) = @_;
+    my ($time,$sqltime_error) = @_;
     my $mysqltime;
     if ($time =~
         /(\d+)-(\d+)-(\d+) # YYYY-MM-DD
@@ -1279,7 +1287,9 @@
     } elsif (! defined($time) || $time == 0) {
         $mysqltime = 0;
     } else {
-        &log(0,"    sqltime:Unable to decode time ".$time);
+        if (ref($sqltime_error) eq 'SCALAR') {
+            $$sqltime_error = "sqltime:Unable to decode time ".$time;
+        }
         $mysqltime = 0;
     }
     return $mysqltime;