Diff for /loncom/metadata_database/parse_activity_log.pl between versions 1.18 and 1.21

version 1.18, 2005/09/20 16:50:40 version 1.21, 2005/11/15 20:52:02
Line 48 Line 48
 # parameter is not set $logthis is set to &nothing, which does what you  # parameter is not set $logthis is set to &nothing, which does what you
 # would expect.  # would expect.
 #  #
   BEGIN {
       eval "use Apache2::compat();";
   };
 use strict;  use strict;
 use DBI;  use DBI;
 use lib '/home/httpd/lib/perl/Apache';  use lib '/home/httpd/lib/perl/Apache';
Line 144  if ($log) { Line 146  if ($log) {
 my $sourcefilename;   # activity log data  my $sourcefilename;   # activity log data
 my $newfilename;      # $sourcefilename will be renamed to this  my $newfilename;      # $sourcefilename will be renamed to this
 my $error_filename;   # Errors in parsing the activity log will be written here  my $error_filename;   # Errors in parsing the activity log will be written here
   my $chunk_filename;   # where we save data we are not going to write to db
 if ($srcfile) {  if ($srcfile) {
     $sourcefilename = $srcfile;      $sourcefilename = $srcfile;
 } else {  } else {
Line 153  my $sql_filename = $sourcefilename; Line 156  my $sql_filename = $sourcefilename;
 $sql_filename =~ s|[^/]*$|activity.log.sql|;  $sql_filename =~ s|[^/]*$|activity.log.sql|;
 my $gz_sql_filename = $sql_filename.'.gz';  my $gz_sql_filename = $sql_filename.'.gz';
 #  #
   $chunk_filename = $sourcefilename.".unprocessed_chunks";
   #
 my $xml_filename = $sourcefilename;  my $xml_filename = $sourcefilename;
 my $gz_xml_filename = $xml_filename.'.gz';  my $gz_xml_filename = $xml_filename.'.gz';
 if (defined($xmlfile)) {  if (defined($xmlfile)) {
Line 486  sub process_courselog { Line 491  sub process_courselog {
         if (! defined($host)) { $host = 'unknown'; }          if (! defined($host)) { $host = 'unknown'; }
         my $prevchunk = 'none';          my $prevchunk = 'none';
         foreach my $chunk (split(/\&\&\&/,$log)) {          foreach my $chunk (split(/\&\&\&/,$log)) {
             my $warningflag = '';              if (length($chunk) > 20000) {
     my ($time,$res,$uname,$udom,$action,@values)= split(/:/,$chunk);                  # avoid putting too much data into the database
             #                   # (usually an uploaded file or something similar)
             # Sometimes we get a file pasted into the activity.log from                  if (! &savechunk(\$chunk,$timestamp,$host)) {
             # an upload form.  Here we try to detect it and avoid inserting                      close(IN);
             # it into the database to avoid the quiet death of the database                      return undef;
             # connection  
             my $i;  
             for ($i=0;$i<$#values;$i++) {  
                 if ($values[$i] =~ /^HWVAL/) {  
                     $#values = $i;  
                     last;  
                 }                  }
                   next;
             }              }
               my $warningflag = '';
       my ($time,$res,$uname,$udom,$action,@values)= split(/:/,$chunk);
             #              #
             if (! defined($res) || $res =~ /^\s*$/) {              if (! defined($res) || $res =~ /^\s*$/) {
                 $res = '/adm/roles';                  $res = '/adm/roles';
Line 514  sub process_courselog { Line 516  sub process_courselog {
             if ($action !~ /^(LOGIN|VIEW|POST|CSTORE|STORE)$/) {              if ($action !~ /^(LOGIN|VIEW|POST|CSTORE|STORE)$/) {
                 $warningflag .= 'action';                  $warningflag .= 'action';
                 print $error_fh 'full log entry:'.$log.$/;                  print $error_fh 'full log entry:'.$log.$/;
                 print $error_fh 'error on chunk:'.$chunk.$/;                  print $error_fh 'error on chunk (saving)'.$/;
                 $logthis->('(action) Unable to parse '.$/.$chunk.$/.                  if (! &savechunk(\$chunk,$timestamp,$host)) {
                       close(IN);
                       return undef;
                   }
                   $logthis->('(action) Unable to parse chunk'.$/.
                          'got '.                           'got '.
                          'time = '.$time.$/.                           'time = '.$time.$/.
                          'res  = '.$res.$/.                           'res  = '.$res.$/.
Line 552  sub process_courselog { Line 558  sub process_courselog {
     }      }
     close IN;      close IN;
     return $linecount;      return $linecount;
       ##
       ##
       sub savechunk {
           my ($chunkref,$timestamp,$host) = @_;
           my $chunk = &escape(${$chunkref});
           if (! open(CHUNKFILE,">>$chunk_filename") ||
               ! print CHUNKFILE $timestamp.':'.$host.':'.$chunk.$/) {
               # abort
               close(CHUNKFILE);
               return 0;
           }
           close(CHUNKFILE);
           return 1;
       }
 }  }
   
   

Removed from v.1.18  
changed lines
  Added in v.1.21


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>