[LON-CAPA-cvs] cvs: loncom /metadata_database searchcat.pl /metadata_database/LONCAPA lonmetadata.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 11 Mar 2005 03:25:19 -0000
matthew Thu Mar 10 22:25:19 2005 EDT
Modified files:
/loncom/metadata_database searchcat.pl
/loncom/metadata_database/LONCAPA lonmetadata.pm
Log:
searchcat.pl:Bug 3961 - metadata only processed for default domain on
multi-domain servers. Now takes command line option -multi_domain.
This causes a hostname lookup and the hosts.tab file to be parsed for
matches of the hostname. Added 'domain' to the dynamic metadata.
lonmetadata.pm:Added 'domain' to the metadata table and to the dynamic
metadata;
Index: loncom/metadata_database/searchcat.pl
diff -u loncom/metadata_database/searchcat.pl:1.61 loncom/metadata_database/searchcat.pl:1.62
--- loncom/metadata_database/searchcat.pl:1.61 Wed Mar 9 13:22:19 2005
+++ loncom/metadata_database/searchcat.pl Thu Mar 10 22:25:18 2005
@@ -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 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 @@
-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 @@
}
#
# 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 (<HOSTFILE>) {
+ 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 @@
&log(1,"MySQL table rename successful.");
}
}
-
if (! $dbh->disconnect) {
&log(0,"MySQL Error Disconnect: ".$dbh->errstr);
die $dbh->errstr;
@@ -504,6 +534,8 @@
#
%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 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
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.11 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.12
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.11 Thu Jun 17 16:33:21 2004
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm Thu Mar 10 22:25:18 2005
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonmetadata.pm,v 1.11 2004/06/17 20:33:21 www Exp $
+# $Id: lonmetadata.pm,v 1.12 2005/03/11 03:25:18 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -75,6 +75,7 @@
lastrevisiondate DATETIME,
owner TEXT,
copyright TEXT,
+domain TEXT
FULLTEXT idx_title (title),
FULLTEXT idx_author (author),
@@ -111,6 +112,7 @@
{ name => 'lastrevisiondate', type=>'DATETIME'},
{ name => 'owner', type=>'TEXT'},
{ name => 'copyright', type=>'TEXT'},
+ { name => 'domain', type=>'TEXT'},
#--------------------------------------------------
{ name => 'dependencies', type=>'TEXT'},
{ name => 'modifyinguser', type=>'TEXT'},
@@ -754,6 +756,9 @@
if (exists($resdata->{'stats'})) {
$data{'stats'} = $resdata->{'stats'};
}
+ if (exists($DynamicData->{'domain'})) {
+ $data{'domain'} = $DynamicData->{'domain'};
+ }
#
return %data;
}