--- loncom/metadata_database/parse_activity_log.pl 2004/12/22 20:42:39 1.11 +++ loncom/metadata_database/parse_activity_log.pl 2005/02/09 21:24:33 1.12 @@ -2,7 +2,7 @@ # # The LearningOnline Network # -# $Id: parse_activity_log.pl,v 1.11 2004/12/22 20:42:39 matthew Exp $ +# $Id: parse_activity_log.pl,v 1.12 2005/02/09 21:24:33 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,15 +64,16 @@ use Fcntl qw(:flock); # # Determine parameters -my ($help,$course,$domain,$drop,$file,$time_run,$nocleanup,$log,$backup); +my ($help,$course,$domain,$drop_when_done,$srcfile,$logfile,$time_run,$nocleanup,$log,$backup); &Getopt::Long::GetOptions( "course=s" => \$course, "domain=s" => \$domain, "backup" => \$backup, "help" => \$help, - "logfile=s" => \$file, + "logfile=s" => \$logfile, + "srcfile=s" => \$srcfile, "timerun" => \$time_run, "nocleanup" => \$nocleanup, - "drop" => \$drop, + "dropwhendone" => \$drop_when_done, "log" => \$log); if (! defined($course) || $help) { print<$logfile")) { warn("Unable to open $logfile for writing. Run aborted."); @@ -137,8 +143,8 @@ my $sourcefilename; # activity log dat my $newfilename; # $sourcefilename will be renamed to this my $gz_sql_filename; # the gzipped mysql backup data file name. my $error_filename; # Errors in parsing the activity log will be written here -if ($file) { - $sourcefilename = $file; +if ($srcfile) { + $sourcefilename = $srcfile; } else { $sourcefilename = &get_filename($course,$domain); } @@ -187,7 +193,7 @@ close(LOCKFILE); ## Table definitions ## my $prefix = $course.'_'.$domain.'_'; -my $student_table = $prefix.'students'; +my $student_table = &Apache::lonmysql::fix_table_name($prefix.'students'); my $student_table_def = { id => $student_table, permanent => 'no', @@ -203,7 +209,7 @@ my $student_table_def = 'PRIMARY KEY' => ['student_id',], }; -my $res_table = $prefix.'resource'; +my $res_table = &Apache::lonmysql::fix_table_name($prefix.'resource'); my $res_table_def = { id => $res_table, permanent => 'no', @@ -218,7 +224,7 @@ my $res_table_def = 'PRIMARY KEY' => ['res_id'], }; -#my $action_table = $prefix.'actions'; +#my $action_table = &Apache::lonmysql::fix_table_name($prefix.'actions'); #my $action_table_def = #{ id => $action_table, # permanent => 'no', @@ -233,7 +239,7 @@ my $res_table_def = # 'PRIMARY KEY' => ['action_id',], #}; -my $machine_table = $prefix.'machine_table'; +my $machine_table = &Apache::lonmysql::fix_table_name($prefix.'machine_table'); my $machine_table_def = { id => $machine_table, permanent => 'no', @@ -248,7 +254,7 @@ my $machine_table_def = 'PRIMARY KEY' => ['machine_id',], }; -my $activity_table = $prefix.'activity'; +my $activity_table = &Apache::lonmysql::fix_table_name($prefix.'activity'); my $activity_table_def = { id => $activity_table, permanent => 'no', @@ -283,7 +289,7 @@ my $activity_table_def = my @Activity_Table = ($activity_table_def); my @ID_Tables = ($student_table_def,$res_table_def,$machine_table_def); ## -## End of table definitions +## End of table definitionsOB ## $logthis->('Connectiong to mysql'); @@ -296,8 +302,6 @@ if (!&Apache::lonmysql::verify_sql_conne } $logthis->('SQL connection is up'); -if ($drop) { &drop_tables(); $logthis->('dropped tables'); } - if (-s $gz_sql_filename) { my $backup_modification_time = (stat($gz_sql_filename))[9]; $logthis->($gz_sql_filename.' was last modified '. @@ -382,6 +386,7 @@ if (-s $newfilename) { &backup_tables($gz_sql_filename); $time_this->('write backup tables'); } + if ($drop_when_done) { &drop_tables(); $logthis->('dropped tables'); } } close($error_fh); @@ -405,6 +410,13 @@ if ($log) { close LOGFILE; } +foreach my $file ($lockfilename, $error_filename,$logfile) { + if (-z $file) { + unlink($file); + } +} + + exit 0; # Everything is okay, so end here before it gets worse. ######################################################## @@ -637,10 +649,10 @@ sub outputtimes { ## sub backup_tables { my ($gz_sql_filename) = @_; - my $command = qq{mysqldump --opt loncapa }; - + my $command = qq{mysqldump --quote-names --opt loncapa }; foreach my $table (@ID_Tables,@Activity_Table) { my $tablename = $table->{'id'}; + $tablename =~ s/\`//g; $command .= $tablename.' '; } $command .= '| gzip >'.$gz_sql_filename; @@ -680,11 +692,10 @@ sub get_filename { sub create_tables { foreach my $table (@ID_Tables,@Activity_Table) { my $table_id = &Apache::lonmysql::create_table($table); -# print STDERR "Unable to create table ".$table->{'id'}.$/; -# print STDERR join($/,&Apache::lonmysql::build_table_creation_request($table)).$/; if (! defined($table_id)) { warn "Unable to create table ".$table->{'id'}.$/; - warn join($/,&Apache::lonmysql::build_table_creation_request($table)).$/; + $logthis->('Unable to create table '.$table->{'id'}); + $logthis->(join($/,&Apache::lonmysql::build_table_creation_request($table))); return 0; } }