--- loncom/metadata_database/cleanup_database.pl 2002/09/09 14:01:04 1.2 +++ loncom/metadata_database/cleanup_database.pl 2006/08/21 21:30:02 1.6 @@ -1,8 +1,8 @@ #!/usr/bin/perl # The LearningOnline Network -# searchcat.pl "Search Catalog" batch script +# cleanup_database.pl Remove stale temporary search results. # -# $Id: cleanup_database.pl,v 1.2 2002/09/09 14:01:04 harris41 Exp $ +# $Id: cleanup_database.pl,v 1.6 2006/08/21 21:30:02 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -79,7 +79,7 @@ use Time::Local; use DBI; my $help = 0; -my $killtime = 86400; +my $killtime = 86400*2; GetOptions( "killtime=s" => \$killtime, "help" => \$help ); if ($help) { @@ -119,14 +119,11 @@ unless ($dbh = DBI->connect("DBI:mysql:l my $sth = $dbh->prepare("SHOW TABLE STATUS"); $sth->execute(); -my $results = $sth->fetchall_arrayref; +my $results = $sth->fetchall_hashref(['Name']); -foreach my $array (@$results) { - next if ($array->[14] ne 'temporary'); # [14] is the comment - my $name = $array->[0]; - # [10] in status report is creation time. - # [11] in status report is update (last modification?) time. - my $tabletime = $array->[11]; +foreach my $name (keys(%$results)) { + next if ($results->{$name}{Comment} ne 'temporary'); + my $tabletime = $results->{$name}{Update_time}; # Times are like: 2002-07-25 10:17:08 my ($year,$month,$day,$hour,$min,$sec)= ($tabletime =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/); @@ -135,6 +132,7 @@ foreach my $array (@$results) { $dbh->do('DROP TABLE '.$name); } } +$sth->finish(); # --------------------------------------------------- Close database connection $dbh->disconnect;