From 4e6e41ce2c381186fe2b86f97f138b3e3daf660a Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 31 Mar 2005 21:22:57 +0000 Subject: [PATCH] upgrade.pl and testEnvironment.pl now use the same config file reader as the rest of WebGUI --- docs/changelog/6.x.x.txt | 3 + lib/WebGUI/Config.pm | 33 ++++++++++- lib/WebGUI/ErrorHandler.pm | 1 + sbin/testEnvironment.pl | 117 +++++++++++++++---------------------- sbin/upgrade.pl | 62 +++++++++----------- 5 files changed, 108 insertions(+), 108 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 96a4398dc..f4c38fd65 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -1,8 +1,11 @@ 6.6.0 - Added a new admin panel for inline content editing. - Tweaked the preloader so WebGUI uses a little less memory per process. + - upgrade.pl and testEnvironment.pl now use the same config file reader as + the rest of WebGUI - fix [ 1173101 ] Template in ^LoginToggle(); + 6.5.5 - fix [ 1171569 ] add/edit sql report help link has wrong namespace - Fixed a bug in the collaboration system that caused replies to fail. diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm index 2d2c0a630..f461d3071 100644 --- a/lib/WebGUI/Config.pm +++ b/lib/WebGUI/Config.pm @@ -84,16 +84,43 @@ The path to the WebGUI installation. =cut sub loadAllConfigs { + my $webguiPath = shift; + my $configs = readAllConfigs($webguiPath); + foreach my $filename (keys %{$configs}) { + unless ($filename =~ /^demo\d/) { + print "\tLoading ".$filename."\n"; + $config{$filename} = $configs->{$filename}; + } + } +} + + +#------------------------------------------------------------------- + +=head2 readAllConfigs ( webguiRoot ) + +Reads all the config file data for all defined sites and returns a hash reference containing the resulting data by config file name. + +Example: $configs->{$filename}; + +=head3 webguiRoot + +The path to the WebGUI installation. + +=cut + +sub readAllConfigs { my $webguiPath = shift; opendir(DIR,$webguiPath."/etc"); my @files = readdir(DIR); closedir(DIR); + my %configs; foreach my $file (@files) { - if ($file =~ /\.conf$/ && !($file =~ /^demo\d/)) { - print "\tLoading ".$file."\n"; - $config{$file} = readConfig($webguiPath,$file); + if ($file =~ /\.conf$/ && !($file =~ /^logs.conf$/)) { + $configs{$file} = readConfig($webguiPath,$file); } } + return \%configs; } diff --git a/lib/WebGUI/ErrorHandler.pm b/lib/WebGUI/ErrorHandler.pm index bfc722ab5..d899e7378 100644 --- a/lib/WebGUI/ErrorHandler.pm +++ b/lib/WebGUI/ErrorHandler.pm @@ -15,6 +15,7 @@ package WebGUI::ErrorHandler; =cut use FileHandle; +use Log::Log4perl; use strict; use WebGUI::Session; diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 566b2c60f..8ef350ed5 100644 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -74,81 +74,12 @@ checkModule("DBIx::FullTextSearch",0.73); ################################### printTest("WebGUI modules"); -if (eval { require WebGUI } && eval { require WebGUI::SQL }) { +if (eval { require WebGUI } && eval { require WebGUI::SQL } && eval { require WebGUI::Config }) { printResult("OK"); } else { failAndExit("Not Found. Perhaps you're running this script from the wrong place."); } -printTest("Locating WebGUI configs"); -my (@files, $file, $dir, $error); -if ($os eq "Windowsish") { - $dir = $webguiRoot."\\etc\\"; -} else { - $dir = $webguiRoot."/etc/"; -} -opendir (DIR,$dir) or $error = "Can't open etc (".$dir.") directory!"; -if (opendir(DIR,$dir)) { - printResult("OK"); - @files = readdir(DIR); - foreach $file (@files) { - if ($file =~ /(.*?)\.conf$/) { - my $prereq = 1; - ################################### - # Checking Config File - ################################### - printTest("Found config file"); - printResult($file); - printTest("Verifying file"); - my ($config); - $config = Parse::PlainConfig->new('DELIM' => '=', - 'FILE' => $dir.$file, - 'PURGE' => 1); - unless (defined $config) { - printResult("Couldn't open the config file."); - $prereq = 0; - } elsif ($config->get('dsn') !~ /\DBI\:\w+\:\w+/) { - printResult("DSN is improperly formatted."); - $prereq = 0; - } else { - printResult("OK"); - } - - if ($prereq) { - ################################### - # Checking uploads folder - ################################### - - printTest("Uploads folder"); - if (opendir(DIR,$config->get('uploadsPath'))) { - printResult("OK"); - closedir(DIR); - } else { - printResult("Appears to be missing!"); - } - - ################################### - # Checking database - ################################### - - printTest("Database connection"); - my ($dbh, $test); - unless (eval {$dbh = DBI->connect($config->get('dsn'),$config->get('dbuser'),$config->get('dbpass'))}) { - printResult("Can't connect with info provided!"); - } else { - printResult("OK"); - $dbh->disconnect(); - } - } - print "\n"; - } - } - closedir(DIR); -} else { - failAndExit($error); -} - - ################################### # Checking Version ################################### @@ -160,6 +91,52 @@ if ($version eq $WebGUI::VERSION."-".$WebGUI::STATUS) { printResult("You are using ".$WebGUI::VERSION."-".$WebGUI::STATUS." and ".$version." is available."); } +printTest("Locating WebGUI configs"); +my $configs = WebGUI::Config::readAllConfigs($webguiRoot); +printResult("OK"); +foreach my $filename (keys %{$configs}) { + print "\n"; + ################################### + # Checking Config File + ################################### + printTest("Checking config file"); + printResult($filename); + + ################################### + # Checking uploads folder + ################################### + printTest("Verifying uploads folder"); + if (opendir(DIR,$configs->{$filename}{uploadsPath})) { + printResult("OK"); + closedir(DIR); + } else { + printResult("Appears to be missing!"); + } + printTest("Verifying DSN"); + my $dsnok = 0; + if ($configs->{$filename}{dsn} !~ /\DBI\:\w+\:\w+/) { + printResult("DSN is improperly formatted."); + } else { + printResult("OK"); + $dsnok = 1; + } + + ################################### + # Checking database + ################################### + if ($dsnok) { + printTest("Verifying database connection"); + my ($dbh, $test); + unless (eval {$dbh = DBI->connect($configs->{$filename}{dsn},$configs->{$filename}{dbuser},$configs->{$filename}{dbpass})}) { + printResult("Can't connect with info provided!"); + } else { + printResult("OK"); + $dbh->disconnect(); + } + } +} + + print "\nTesting complete!\n\n"; diff --git a/sbin/upgrade.pl b/sbin/upgrade.pl index 7d2974e20..7e19055f4 100644 --- a/sbin/upgrade.pl +++ b/sbin/upgrade.pl @@ -20,8 +20,8 @@ BEGIN { use DBI; use File::Path; use Getopt::Long; -use Parse::PlainConfig; use strict; +use WebGUI::Config; use WebGUI::SQL; my $help; @@ -140,47 +140,39 @@ if ($^O =~ /^Win/i) { $slash = "/"; } our $upgradesPath = $webguiRoot.$slash."docs".$slash."upgrades".$slash; -our $configsPath = $webguiRoot.$slash."etc".$slash; our (%upgrade, %config); ## Find site configs. print "\nGetting site configs...\n" unless ($quiet); -opendir (DIR,$configsPath) or die "Can't open $configsPath\n"; -my @files=readdir(DIR); -closedir(DIR); -foreach my $file (@files) { - if ($file =~ /(.*?)\.conf$/ && $file ne "some_other_site.conf") { - print "\tFound $file.\n" unless ($quiet); - $config{$file}{configFile} = $file; - my $config = Parse::PlainConfig->new('DELIM' => '=', - 'FILE' => $configsPath.$config{$file}{configFile}, - 'PURGE' => 1); - $config{$file}{dsn} = $config->get('dsn'); - my $temp = _parseDSN($config{$file}{dsn}, ['database', 'host', 'port']); - if ($temp->{'driver'} eq "mysql") { - $config{$file}{db} = $temp->{'database'}; - $config{$file}{host} = $temp->{'host'}; - $config{$file}{port} = $temp->{'port'}; - $config{$file}{dbuser} = $config->get('dbuser'); - $config{$file}{dbpass} = $config->get('dbpass'); - $config{$file}{mysqlCLI} = $config->get('mysqlCLI'); - $config{$file}{mysqlDump} = $config->get('mysqlDump'); - $config{$file}{backupPath} = $config->get('backupPath'); - my $dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass}); - ($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion - order by dateApplied desc, webguiVersion desc limit 1",$dbh); - unless ($history) { - print "\tPreparing site for upgrade.\n" unless ($quiet); - $dbh->do("replace into settings (name,value) values ('specialState','upgrading')") unless ($history); - rmtree($config->get("uploadsPath").$slash."temp"); - } - $dbh->disconnect; - } else { - delete $config{$file}; - print "\tSkipping non-MySQL database.\n" unless ($quiet); +my $configs = WebGUI::Config::readAllConfigs($webguiRoot); +foreach my $filename (keys %{$configs}) { + print "\tProcessing $filename.\n" unless ($quiet); + $config{$filename}{configFile} = $filename; + $config{$filename}{dsn} = $configs->{$filename}{dsn}; + my $temp = _parseDSN($config{$filename}{dsn}, ['database', 'host', 'port']); + if ($temp->{'driver'} eq "mysql") { + $config{$filename}{db} = $temp->{'database'}; + $config{$filename}{host} = $temp->{'host'}; + $config{$filename}{port} = $temp->{'port'}; + $config{$filename}{dbuser} = $configs->{$filename}{dbuser}; + $config{$filename}{dbpass} = $configs->{$filename}{dbpass}; + $config{$filename}{mysqlCLI} = $configs->{$filename}{mysqlCLI}; + $config{$filename}{mysqlDump} = $configs->{$filename}{mysqlDump}; + $config{$filename}{backupPath} = $configs->{$filename}{backupPath}; + my $dbh = DBI->connect($config{$filename}{dsn},$config{$filename}{dbuser},$config{$filename}{dbpass}); + ($config{$filename}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion + order by dateApplied desc, webguiVersion desc limit 1",$dbh); + unless ($history) { + print "\tPreparing site for upgrade.\n" unless ($quiet); + $dbh->do("replace into settings (name,value) values ('specialState','upgrading')") unless ($history); + rmtree($configs->{$filename}{uploadsPath}.$slash."temp"); } + $dbh->disconnect; + } else { + delete $config{$filename}; + print "\tSkipping non-MySQL database.\n" unless ($quiet); } }