precache webgui config files

This commit is contained in:
JT Smith 2004-07-07 05:40:39 +00:00
parent 6bc2c33954
commit c39e7dc7b0
7 changed files with 196 additions and 34 deletions

156
lib/WebGUI/Config.pm Normal file
View file

@ -0,0 +1,156 @@
package WebGUI::Config;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2004 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Parse::PlainConfig;
our %config;
=head1 NAME
Package WebGUI::Config
=head1 DESCRIPTION
This package parses the WebGUI config file.
=head1 SYNOPSIS
use WebGUI::Config;
$hashRef = WebGUI::Config::getConfig($webguiRoot, $configFile);
$hashRef = WebGUI::Config::readConfig($webguiRoot, $configFile);
WebGUI::Config::loadAllConfigs($webguiRoot);
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 getConfig ( webguiRoot , configFile )
Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary.
=over
=item webguiRoot
The path to the WebGUI installation.
=item configFile
The filename of the config file to read.
=back
=cut
sub getConfig {
my $webguiPath = shift;
my $filename = shift;
if (exists $config{$filename}) {
return $config{$filename};
} else {
return readConfig($webguiPath,$filename);
}
}
#-------------------------------------------------------------------
=head2 loadAllConfigs ( webguiRoot )
Reads all the config file data for all defined sites into an in-memory cache.
=over
=item webguiRoot
The path to the WebGUI installation.
=back
=cut
sub laodAllConfigs {
my $webguiPath = shift;
opendir(DIR,$webguiPath."/etc");
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
if ($file =~ /\.conf$/) {
print "\tLoading ".$file."\n";
$config{$file} = readConfig($webguiPath,$file);
}
}
}
#-------------------------------------------------------------------
=head2 readConfig ( webguiRoot , configFile )
Returns a hash reference containing the configuration data. It reads the config data directly from the file.
=over
=item webguiRoot
The path to the WebGUI installation.
=item configFile
The filename of the config file to read.
=back
=cut
sub readConfig {
my $webguiPath = shift;
my $filename = shift;
my $config = Parse::PlainConfig->new('DELIM' => '=',
'FILE' => $webguiPath.'/etc/'.$filename,
'PURGE' => 1);
my %data;
foreach my $key ($config->directives) {
$data{$key} = $config->get($key);
}
if (ref $data{authMethods} ne "ARRAY") {
$data{authMethods} = [$data{authMethods}];
}
if( defined( $data{scripturl} ) ) {
# get rid of leading "/" if present.
$data{scripturl} =~ s/^\///;
}
if (ref $data{sitename} eq "ARRAY") {
$data{defaultSitename} = $data{sitename}[0];
} else {
$data{defaultSitename} = $data{sitename};
}
return \%data;
}
1;

View file

@ -15,7 +15,7 @@ use WebGUI::Session;
#-------------------------------------------------------------------
sub process {
return $session{config}{scripturl}.'/';
return ($session{config}{scripturl} || $session{env}{SCRIPT_NAME})."/";
}

View file

@ -19,9 +19,9 @@ use CGI;
use Date::Calc;
use DBI;
use Exporter;
use Parse::PlainConfig;
use strict;
use Tie::CPHash;
use WebGUI::Config;
use WebGUI::ErrorHandler;
use WebGUI::SQL;
use WebGUI::Utility;
@ -96,7 +96,7 @@ sub _setupPageInfo {
}
}
%page = WebGUI::SQL->quickHash("select * from page where pageId='".$pageId."'");
$page{url} = $session{config}{scripturl}."/".$page{urlizedTitle};
$page{url} = ($session{config}{scripturl} || $session{env}{SCRIPT_NAME})."/".$page{urlizedTitle};
$session{page} = \%page;
}
@ -291,7 +291,9 @@ The filename of the config file that WebGUI should operate from.
=cut
sub open {
my ($key, $config);
my $webguiRoot = shift;
my $configFile = shift;
my ($key);
###----------------------------
### operating system specific things
$session{os}{name} = $^O;
@ -304,32 +306,7 @@ sub open {
}
###----------------------------
### config variables
$session{config}{webguiRoot} = $_[0];
$session{config}{configFile} = $_[1] || "WebGUI.conf";
$config = Parse::PlainConfig->new('DELIM' => '=',
'FILE' => $session{config}{webguiRoot}.'/etc/'.$session{config}{configFile},
'PURGE' => 1);
foreach ($config->directives) {
$session{config}{$_} = $config->get($_);
}
if (ref $session{config}{authMethods} ne "ARRAY") {
$session{config}{authMethods} = [$session{config}{authMethods}];
}
if( defined( $session{config}{scripturl} ) ) {
# get rid of leading "/" if present.
$session{config}{scripturl} =~ s/^\///;
} else {
# default to the "real" path to script.
$session{config}{scripturl} = $ENV{SCRIPT_NAME};
}
$session{config}{extrasURL} = $session{config}{extrasURL} || $session{config}{extras} || "/extras";
$session{config}{extras} = $session{config}{extras} || $session{config}{extrasURL}; # for backward compatibility
$session{config}{extrasPath} = $session{config}{extrasPath} || "/data/WebGUI/www/extras";
if (ref $session{config}{sitename} eq "ARRAY") {
$session{config}{defaultSitename} = $session{config}{sitename}[0];
} else {
$session{config}{defaultSitename} = $session{config}{sitename};
}
$session{config} = WebGUI::Config::getConfig($webguiRoot,$configFile);
###----------------------------
### default database handler object
$session{dbh} = DBI->connect($session{config}{dsn},$session{config}{dbuser},$session{config}{dbpass},{ RaiseError=>0,AutoCommit=>1 });

View file

@ -148,7 +148,7 @@ Name value pairs to add to the URL in the form of:
=cut
sub gateway {
my $url = _getSiteURL().$session{config}{scripturl}.'/'.$_[0];
my $url = _getSiteURL().($session{config}{scripturl} || $session{env}{SCRIPT_NAME}).'/'.$_[0];
if ($_[1]) {
$url = append($url,$_[1]);
}