--- loncom/metadata_database/searchcat.pl 2001/04/14 18:24:54 1.1 +++ loncom/metadata_database/searchcat.pl 2001/04/16 12:08:34 1.4 @@ -8,8 +8,6 @@ # directory and gathers metadata. # The metadata is entered into a SQL database. -use strict; - use IO::File; use HTML::TokeParser; @@ -35,9 +33,9 @@ while ($configline=) { } close(CONFIG); +my $dbh; # ------------------------------------- Make sure that database can be accessed { - my $dbh; unless ( $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0}) ) { @@ -47,8 +45,14 @@ close(CONFIG); } # ------------------------------------------------------------- get .meta files -# need to actually loop over existing users here.. will fix soon -&find("$perlvar{'lonDocRoot'}/res"); +opendir(RESOURCES,"$perlvar{'lonDocRoot'}/res/$perlvar{'lonDefDomain'}"); +my @homeusers=grep + {&ishome("$perlvar{'lonDocRoot'}/res/$perlvar{'lonDefDomain'}/$_")} + grep {!/^\.\.?$/} readdir(RESOURCES); +closedir RESOURCES; +foreach my $user (@homeusers) { + &find("$perlvar{'lonDocRoot'}/res/$perlvar{'lonDefDomain'}/$user"); +} # -- process each file to get metadata and put into search catalog SQL database foreach my $m (@metalist) { @@ -67,7 +71,7 @@ foreach my $m (@metalist) { delete($ref->{'creationdate'}).','. delete($ref->{'lastrevisiondate'}).','. delete($ref->{'owner'}).','. - delete($ref->{'copyright'}). + delete($ref->{'copyright'}) ')'; $sth->execute(); } @@ -141,3 +145,29 @@ sub declutter { $thisfn=~s/^res\///; return $thisfn; } + +# --------------------------------------- Is this the home server of an author? +# (copied from lond, modification of the return value) +sub ishome { + my $author=shift; + $author=~s/\/home\/httpd\/html\/res\/([^\/]*)\/([^\/]*).*/$1\/$2/; + my ($udom,$uname)=split(/\//,$author); + my $proname=propath($udom,$uname); + if (-e $proname) { + return 1; + } else { + return 0; + } +} + +# -------------------------------------------- Return path to profile directory +# (copied from lond) +sub propath { + my ($udom,$uname)=@_; + $udom=~s/\W//g; + $uname=~s/\W//g; + my $subdir=$uname.'__'; + $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/; + my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; + return $proname; +}