--- loncom/metadata_database/searchcat.pl 2001/04/16 13:17:05 1.10 +++ loncom/metadata_database/searchcat.pl 2001/04/17 13:36:07 1.15 @@ -2,7 +2,7 @@ # The LearningOnline Network # searchcat.pl "Search Catalog" batch script -# 04/14/2001 Scott Harrison +# 04/14/2001, 04/16/2001 Scott Harrison # This script goes through a LON-CAPA resource # directory and gathers metadata. @@ -34,6 +34,9 @@ while ($configline=) { } close(CONFIG); +# ------------------------------------- Only run if machine is a library server +exit unless $perlvar{'lonRole'} eq 'library'; + my $dbh; # ------------------------------------- Make sure that database can be accessed { @@ -57,16 +60,17 @@ foreach my $user (@homeusers) { # -- process each file to get metadata and put into search catalog SQL database # Also, check to see if already there. -# I could not search first and just delete, but this works for now. +# I could just delete (without searching first), but this works for now. foreach my $m (@metalist) { my $ref=&metadata($m); - my $m2=&declutter($m); - my $q2="select * from metadata where url like '$m2'"; + my $m2='/res/'.&declutter($m); + $m2=~s/\.meta$//; + my $q2="select * from metadata where url like binary '$m2'"; my $sth = $dbh->prepare($q2); $sth->execute(); my $r1=$sth->fetchall_arrayref; if (@$r1) { - $sth=$dbh->prepare("delete from metadata where url like '$m2'"); + $sth=$dbh->prepare("delete from metadata where url like binary '$m2'"); $sth->execute(); } $sth=$dbh->prepare('insert into metadata values ('. @@ -80,8 +84,8 @@ foreach my $m (@metalist) { '"'.delete($ref->{'abstract'}).'"'.','. '"'.delete($ref->{'mime'}).'"'.','. '"'.delete($ref->{'language'}).'"'.','. - '"'.delete($ref->{'creationdate'}).'"'.','. - '"'.delete($ref->{'lastrevisiondate'}).'"'.','. + '"'.sqltime(delete($ref->{'creationdate'})).'"'.','. + '"'.sqltime(delete($ref->{'lastrevisiondate'})).'"'.','. '"'.delete($ref->{'owner'}).'"'.','. '"'.delete($ref->{'copyright'}).'"'.')'); $sth->execute(); @@ -182,3 +186,11 @@ sub propath { my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; return $proname; } + +# ---------------------------- convert 'time' format into a datetime sql format +sub sqltime { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = + localtime(@_[0]); + $mon++; $year+=1900; + return "$year-$mon-$mday $hour:$min:$sec"; +}