--- loncom/metadata_database/searchcat.pl 2005/03/09 18:22:19 1.61 +++ loncom/metadata_database/searchcat.pl 2005/03/11 03:25:18 1.62 @@ -2,7 +2,7 @@ # The LearningOnline Network # searchcat.pl "Search Catalog" batch script # -# $Id: searchcat.pl,v 1.61 2005/03/09 18:22:19 matthew Exp $ +# $Id: searchcat.pl,v 1.62 2005/03/11 03:25:18 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -77,17 +77,20 @@ use HTML::TokeParser; use GDBM_File; use POSIX qw(strftime mktime); +use Sys::Hostname; + use File::Find; # # Set up configuration options -my ($simulate,$oneuser,$help,$verbose,$logfile,$debug); +my ($simulate,$oneuser,$help,$verbose,$logfile,$debug,$multidom); GetOptions ( 'help' => \$help, 'simulate' => \$simulate, 'only=s' => \$oneuser, 'verbose=s' => \$verbose, 'debug' => \$debug, + 'multi_domain' => \$multidom, ); if ($help) { @@ -100,6 +103,7 @@ Options: -only=user Only compute for the given user. Implies -simulate -verbose=val Sets logging level, val must be a number -debug Turns on debugging output + -multi_domain Parse the hosts.tab file domain(s) to use. ENDHELP exit 0; } @@ -173,33 +177,60 @@ if ($dbh->err) { } # # find out which users we need to examine -my $dom = $perlvar{'lonDefDomain'}; -opendir(RESOURCES,"$perlvar{'lonDocRoot'}/res/$dom"); -my @homeusers = - grep { - &ishome("$perlvar{'lonDocRoot'}/res/$dom/$_"); - } grep { - !/^\.\.?$/; - } readdir(RESOURCES); -closedir RESOURCES; -# -if ($oneuser) { - @homeusers=($oneuser); -} -# -# Loop through the users -foreach my $user (@homeusers) { - &log(0,"=== User: ".$user); - &process_dynamic_metadata($user,$dom); - # - # Use File::Find to get the files we need to read/modify - find( - {preprocess => \&only_meta_files, -# wanted => \&print_filename, -# wanted => \&log_metadata, - wanted => \&process_meta_file, - }, - "$perlvar{'lonDocRoot'}/res/$perlvar{'lonDefDomain'}/$user"); +my @domains; +if (defined($multidom)) { + &log(1,'====multi domain setup===='); + # Peek into the hosts.tab and look for matches of our hostname + my $host = hostname(); + &log(9,'hostname = "'.$host.'"'); + open(HOSTFILE,$perlvar{'lonTabDir'}.'/hosts.tab') || + die ("Unable to determine domain(s) of multi-domain server"); + my %domains; + while () { + next if (/^\#/); + next if (!/:\Q$host\E/); + &log(9,$_); + $domains{(split(':',$_))[1]}++; + } + close HOSTFILE; + @domains = sort(keys(%domains)); + &log(9,join(',',@domains)); + if (! scalar(@domains)) { + die ("Unable to find any domains in the hosts.tab that match ".$host); + } +} else { + push(@domains,$perlvar{'lonDefDomain'}); +} + +foreach my $dom (@domains) { + &log(9,'domain = '.$dom); + opendir(RESOURCES,"$perlvar{'lonDocRoot'}/res/$dom"); + my @homeusers = + grep { + &ishome("$perlvar{'lonDocRoot'}/res/$dom/$_"); + } grep { + !/^\.\.?$/; + } readdir(RESOURCES); + closedir RESOURCES; + &log(5,'users = '.$dom.':'.join(',',@homeusers)); + # + if ($oneuser) { + @homeusers=($oneuser); + } + # + # Loop through the users + foreach my $user (@homeusers) { + &log(0,"=== User: ".$user); + &process_dynamic_metadata($user,$dom); + # + # Use File::Find to get the files we need to read/modify + find( + {preprocess => \&only_meta_files, + #wanted => \&print_filename, + #wanted => \&log_metadata, + wanted => \&process_meta_file, + }, join('/',($perlvar{'lonDocRoot'},'res',$dom,$user)) ); + } } # # Rename the table @@ -212,7 +243,6 @@ if (! $simulate) { &log(1,"MySQL table rename successful."); } } - if (! $dbh->disconnect) { &log(0,"MySQL Error Disconnect: ".$dbh->errstr); die $dbh->errstr; @@ -504,6 +534,8 @@ sub process_dynamic_metadata { # %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata); untie(%evaldata); + $DynamicData{'domain'} = $dom; + print('user = '.$user.' domain = '.$dom.$/); # # Read in the access count data &log(7,'Reading access count data') if ($debug); @@ -532,10 +564,6 @@ sub process_dynamic_metadata { sub get_dynamic_metadata { my ($url) = @_; $url =~ s:^/res/::; - if (! exists($DynamicData{$url})) { - &log(7,' No dynamic data for '.$url) if ($debug); - return (); - } my %data = &LONCAPA::lonmetadata::process_dynamic_metadata($url, \%DynamicData); # find the count