From a141de0ebfed96cade5da25609578eefb1218c64 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 23 Feb 2010 16:16:09 -0600 Subject: [PATCH] removing first parameter from WebGUI::Session->open and other cleanups --- docs/upgrades/_upgrade.skeleton | 10 +-- docs/upgrades/upgrade_7.9.3-8.0.0.pl | 10 +-- {sbin => etc}/preload.custom.example | 0 {sbin => etc}/preload.exclude.example | 0 lib/WebGUI.pm | 2 +- lib/WebGUI/AssetExportHtml.pm | 8 +- lib/WebGUI/Config.pm | 7 +- lib/WebGUI/Paths.pm | 22 ++++- lib/WebGUI/Session.pm | 11 ++- lib/WebGUI/URL/Content.pm | 2 +- lib/WebGUI/URL/Uploads.pm | 2 +- .../Activity/DeleteExpiredSessions.pm | 2 +- sbin/_utility.skeleton | 24 ++---- sbin/changeIobStatus.pl | 12 +-- sbin/diskUsage.pl | 12 +-- sbin/fileImport.pl | 18 ++-- sbin/galleryImport.pl | 6 +- sbin/generateContent.pl | 30 +++---- sbin/installClass.pl | 4 +- sbin/maintenanceMode.pl | 12 +-- sbin/preload.perl | 83 +++---------------- sbin/purgeWGAccess.pl | 12 +-- sbin/rebuildLineage.pl | 16 +--- sbin/search.pl | 14 +--- sbin/spectre.pl | 15 +--- sbin/syncToCdn.pl | 12 +-- sbin/thumbnailer.pl | 8 +- sbin/upgrade.pl | 37 +++------ sbin/userImport.pl | 10 +-- t/Config.t | 2 +- t/Group.t | 4 +- t/Macro/UsersOnline.t | 2 +- t/Session/ErrorHandler.t | 4 +- t/Session/Scratch.t | 4 +- t/Shop/Cart.t | 4 +- t/User.t | 2 +- t/VersionTag.t | 10 +-- t/Workflow/Activity/DeleteExpiredSessions.t | 4 +- t/Workflow/Activity/RemoveOldCarts.t | 4 +- 39 files changed, 150 insertions(+), 291 deletions(-) rename {sbin => etc}/preload.custom.example (100%) rename {sbin => etc}/preload.exclude.example (100%) mode change 100644 => 100755 sbin/syncToCdn.pl diff --git a/docs/upgrades/_upgrade.skeleton b/docs/upgrades/_upgrade.skeleton index a89ab3d63..7fcc51999 100644 --- a/docs/upgrades/_upgrade.skeleton +++ b/docs/upgrades/_upgrade.skeleton @@ -10,15 +10,9 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = "../.."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Getopt::Long; +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Asset; @@ -86,7 +80,7 @@ sub start { 'configFile=s'=>\$configFile, 'quiet'=>\$quiet ); - my $session = WebGUI::Session->open($webguiRoot,$configFile); + my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Upgrade to ".$toVersion}); diff --git a/docs/upgrades/upgrade_7.9.3-8.0.0.pl b/docs/upgrades/upgrade_7.9.3-8.0.0.pl index 94a63072c..cc55df740 100644 --- a/docs/upgrades/upgrade_7.9.3-8.0.0.pl +++ b/docs/upgrades/upgrade_7.9.3-8.0.0.pl @@ -10,16 +10,10 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = "../.."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use File::Path qw/rmtree/; use Getopt::Long; +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Asset; @@ -116,7 +110,7 @@ sub start { 'configFile=s'=>\$configFile, 'quiet'=>\$quiet ); - my $session = WebGUI::Session->open($webguiRoot,$configFile); + my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Upgrade to ".$toVersion}); diff --git a/sbin/preload.custom.example b/etc/preload.custom.example similarity index 100% rename from sbin/preload.custom.example rename to etc/preload.custom.example diff --git a/sbin/preload.exclude.example b/etc/preload.exclude.example similarity index 100% rename from sbin/preload.exclude.example rename to etc/preload.exclude.example diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index dfe954165..c4711c119 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -98,7 +98,7 @@ sub authen { # determine session id my $sessionId = $cookies->{$config->getCookieName}; - my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'),$config->getFilename, $request, $server, $sessionId); + my $session = WebGUI::Session->open($config, $request, $server, $sessionId); my $log = $session->log; $request->pnotes(wgSession => $session); diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 1e20f1cf7..af1d4f6f7 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -264,9 +264,7 @@ sub exportAsHtml { # now, create a new session as the user doing the exports. this is so that # the exported assets are taken from that user's perspective. - my $exportSession = WebGUI::Session->open( - $session->config->getFilename, - ); + my $exportSession = WebGUI::Session->open($session->config); my $esGuard = Scope::Guard->new(sub { $exportSession->var->end; $exportSession->close; @@ -497,9 +495,7 @@ sub exportGetDescendants { # open a temporary session as the user doing the exporting so we don't get # assets that they can't see if ( ref $user && $user->isa('WebGUI::User') ) { - $session = WebGUI::Session->open( - $session->config->getFilename, - ); + $session = WebGUI::Session->open($session->config); $session->user( { userId => $user->userId } ); $sGuard = Scope::Guard->new(sub { $session->var->end; diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm index ab4d70877..92107884b 100644 --- a/lib/WebGUI/Config.pm +++ b/lib/WebGUI/Config.pm @@ -36,9 +36,9 @@ This package parses the WebGUI config file. WebGUI::Config->loadAllConfigs($webguiRoot); - my $configs = WebGUI::Config->readAllConfigs($webguiRoot); + my $configs = WebGUI::Config->readAllConfigs; - my $config = WebGUI::Config->new($webguiRoot, $configFileName); + my $config = WebGUI::Config->new($configFileName); my $value = $config->get($param); $config->set($param,$value); @@ -123,8 +123,7 @@ The path to the WebGUI installation. sub loadAllConfigs { my $class = shift; - my $webguiPath = shift; - my $configs = $class->readAllConfigs($webguiPath); + my $configs = $class->readAllConfigs; foreach my $filename (keys %{$configs}) { unless ($filename =~ /^demo\d/) { print "\tLoading ".$filename."\n"; diff --git a/lib/WebGUI/Paths.pm b/lib/WebGUI/Paths.pm index 25ff2e795..54bf8eafb 100644 --- a/lib/WebGUI/Paths.pm +++ b/lib/WebGUI/Paths.pm @@ -15,6 +15,9 @@ package WebGUI::Paths; =cut our $VERSION = '0.0.1'; +use 5.010; +use strict; +use warnings; use Carp qw(croak); use Cwd qw(realpath); use File::Spec::Functions qw(catdir splitpath catpath splitpath updir catfile); @@ -59,6 +62,21 @@ BEGIN { } } +sub import { + my $class = shift; + given (\@_) { + when ('-inc') { + $class->includePreloads; + } + when ('-preload') { + $class->preloadAll; + } + default { + warn "Invalid option $_"; + } + } +} + sub siteConfigs { my $class = shift; opendir my $dh, $class->configBase; @@ -83,7 +101,7 @@ sub preloadPaths { try { @paths = grep { (-d) ? 1 : do { - warn "WARNING: Not adding lib directory '$path' from @{[$class->preloadCustom]}: Directory does not exist.\n"; + warn "WARNING: Not adding lib directory '$_' from @{[$class->preloadCustom]}: Directory does not exist.\n"; 0; } } _readTextLines($class->preloadCustom); @@ -104,6 +122,8 @@ sub preloadExclude { sub preloadAll { my $class = shift; + $class->includePreloads; + require WebGUI::Pluggable; WebGUI::Pluggable::findAndLoad( 'WebGUI', { diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 826c3520a..49817e481 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -50,7 +50,7 @@ B It is important to distinguish the difference between a WebGUI session use WebGUI::Session; - $session = WebGUI::Session->open($webguiRoot, $configFile); + $session = WebGUI::Session->open($configFile); $sessionId = $session->getId; ($form, $db, $user) = $session->quick("form", "db", "user"); $session->close; @@ -455,11 +455,16 @@ Uses simple session vars. See WebGUI::Session::Var::new() for more details. sub open { my $class = shift; - my $webguiRoot = shift; my $configFile = shift; my $request = shift; my $server = shift; - my $config = WebGUI::Config->new($configFile); + my $config; + if (try { $configFile->isa('WebGUI::Config' }) { + $config = $configFile; + } + else { + $config = WebGUI::Config->new($configFile); + } my $self = {_config=>$config, _server=>$server}; bless $self , $class; $self->{_request} = $request if (defined $request); diff --git a/lib/WebGUI/URL/Content.pm b/lib/WebGUI/URL/Content.pm index f94dc1257..fa6128bba 100644 --- a/lib/WebGUI/URL/Content.pm +++ b/lib/WebGUI/URL/Content.pm @@ -66,7 +66,7 @@ sub handler { my $session = $request->pnotes('wgSession'); WEBGUI_FATAL: { unless (defined $session) { - $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server); + $session = WebGUI::Session->open($config, $request, $server); return Apache2::Const::OK if ! defined $session; } foreach my $handler (@{$config->get("contentHandlers")}) { diff --git a/lib/WebGUI/URL/Uploads.pm b/lib/WebGUI/URL/Uploads.pm index 36ca8470a..c07efc9c6 100644 --- a/lib/WebGUI/URL/Uploads.pm +++ b/lib/WebGUI/URL/Uploads.pm @@ -62,7 +62,7 @@ sub handler { unless ($privs[1] eq "7" || $privs[1] eq "1") { my $session = $request->pnotes('wgSession'); unless (defined $session) { - $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server); + $session = WebGUI::Session->open($config->getFilename, $request, $server); } my $hasPrivs = ($session->var->get("userId") eq $privs[0] || $session->user->isInGroup($privs[1]) || $session->user->isInGroup($privs[2])); $session->close(); diff --git a/lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm b/lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm index 74af19bfe..1d5872c7b 100644 --- a/lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm +++ b/lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm @@ -87,7 +87,7 @@ sub execute { $self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows"); $self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] ); } - my $session = WebGUI::Session->open($self->session->config->getFilename, undef, undef, $sessionId, 1); + my $session = WebGUI::Session->open($self->session->config, undef, undef, $sessionId, 1); if (defined $session) { $session->var->end; $session->close; diff --git a/sbin/_utility.skeleton b/sbin/_utility.skeleton index 18c08945e..8ce5fe320 100644 --- a/sbin/_utility.skeleton +++ b/sbin/_utility.skeleton @@ -10,31 +10,26 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -$|++; # disable output buffering -our ($webguiRoot, $configFile, $help, $man); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Pod::Usage; use Getopt::Long; +use WebGUI::Paths -inc; use WebGUI::Session; +$|++; # disable output buffering + # Get parameters here, including $help GetOptions( - 'configFile=s' => \$configFile, - 'help' => \$help, - 'man' => \$man, + 'configFile=s' => \(my $configFile), + 'help' => \(my $help), + 'man' => \(my $man), ); pod2usage( verbose => 1 ) if $help; pod2usage( verbose => 2 ) if $man; -pod2usage( msg => "Must specify a config file!" ) unless $configFile; +pod2usage( msg => "Must specify a config file!" ) unless $configFile; -my $session = start( $webguiRoot, $configFile ); +my $session = start( $configFile ); # Do your work here finish($session); @@ -43,9 +38,8 @@ finish($session); #---------------------------------------------------------------------------- sub start { - my $webguiRoot = shift; my $configFile = shift; - my $session = WebGUI::Session->open($webguiRoot,$configFile); + my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); ## If your script is adding or changing content you need these lines, otherwise leave them commented diff --git a/sbin/changeIobStatus.pl b/sbin/changeIobStatus.pl index e42b76b6a..77c3ed9f1 100755 --- a/sbin/changeIobStatus.pl +++ b/sbin/changeIobStatus.pl @@ -10,16 +10,10 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - +use strict; use Getopt::Long; use Pod::Usage; -use strict; +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::User; use WebGUI::Inbox; @@ -51,7 +45,7 @@ pod2usage( verbose => 2 ) if $help; pod2usage() unless $configFile; print "Starting up...\n" unless ($quiet); -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); if ($userMessageFile) { print "Opening message file.." unless ($quiet); diff --git a/sbin/diskUsage.pl b/sbin/diskUsage.pl index d15f3a69c..5ee66645b 100755 --- a/sbin/diskUsage.pl +++ b/sbin/diskUsage.pl @@ -10,16 +10,10 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - +use strict; use Getopt::Long; use Pod::Usage; -use strict; +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::Asset; @@ -54,7 +48,7 @@ finish($session); #------------------------------------------------- sub start { - my $session = WebGUI::Session->open($webguiRoot,$configFile); + my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); return $session; } diff --git a/sbin/fileImport.pl b/sbin/fileImport.pl index 29bdfbd92..4300e5bf7 100755 --- a/sbin/fileImport.pl +++ b/sbin/fileImport.pl @@ -10,16 +10,8 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot, @nailable); +use strict; -BEGIN { - $webguiRoot = ".."; - @nailable = qw(jpg jpeg png gif); - unshift (@INC, $webguiRoot."/lib"); -} - - -$| = 1; use File::Path; use File::stat; @@ -27,13 +19,17 @@ use FileHandle; use Getopt::Long; use POSIX; use Pod::Usage; -use strict; +use WebGUI::Paths -inc; use WebGUI::Asset::File; use WebGUI::Asset::File::Image; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Utility; +$| = 1; + +my @nailable = qw(jpg jpeg png gif); + # TB : Get the time as soon as possible. Use $now as global variable. # $now is used for skipOlderThan feature. my $now = time; @@ -89,7 +85,7 @@ my %ListAssetExists; my %filelisthash; print "Starting..." unless ($quiet); -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); print "OK\n" unless ($quiet); diff --git a/sbin/galleryImport.pl b/sbin/galleryImport.pl index 7f6570274..5d1321a74 100755 --- a/sbin/galleryImport.pl +++ b/sbin/galleryImport.pl @@ -10,14 +10,13 @@ # http://www.plainblack.com info@plainblack.com # ------------------------------------------------------------------- -$|=1; -use lib '../lib'; use strict; use Carp qw( carp croak ); use File::Find; use Getopt::Long; use Pod::Usage; use Scalar::Util qw( blessed ); +use WebGUI::Paths -inc; use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Wobject::GalleryAlbum; use WebGUI::Asset::Wobject::Gallery; @@ -25,6 +24,7 @@ use WebGUI::Asset::Wobject::Folder; use WebGUI::Asset::Post::Thread; use WebGUI::Storage; +$|=1; # custom flags my ($fromAssetId, $fromPath, $fromAssetUrl, $toId, $toUrl) = undef; @@ -378,7 +378,7 @@ sub start { pod2usage("$0: Must specify a --configFile"); } - my $session = WebGUI::Session->open("..",$configFile); + my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); my $versionTag = WebGUI::VersionTag->getWorking($session); diff --git a/sbin/generateContent.pl b/sbin/generateContent.pl index 9a58208e6..ee51b29ca 100755 --- a/sbin/generateContent.pl +++ b/sbin/generateContent.pl @@ -10,19 +10,10 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- - -our $webguiRoot; - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - -use DBI; -use FileHandle; +use strict; use Getopt::Long; use Pod::Usage; -use strict qw(subs vars); +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::Asset; @@ -46,7 +37,7 @@ pod2usage( verbose => 2 ) if $help; pod2usage() if ($configFile eq '' || !($assetId||$url) ); # Open WebGUI session -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); $session->user({userId=>$userId}) if (defined $userId); $session->scratch->set("personalStyleId", $styleId) if (defined $styleId); @@ -54,23 +45,26 @@ my $asset = undef; if ($url) { $asset = WebGUI::Asset->newByUrl($session,$url); -} else { +} +else { $asset = WebGUI::Asset->newByDynamicClass($session,$assetId); } if (defined $asset) { - my $file = undef; + my $file; if ($toFile) { - $file = FileHandle->new(">$toFile") or die "Can't open file $toFile for writing. $!"; + open $file '>', $toFile or die "Can't open file $toFile for writing. $!"; $session->output->setHandle($file); } my $content = $asset->www_view; unless ($content eq "chunked") { - $session->output->print($content); + $session->output->print($content); $session->output->setHandle(undef); } - $file->close if (defined $file); -} else { + close $file + if defined $file; +} +else { print "Asset not defined!!\n"; } diff --git a/sbin/installClass.pl b/sbin/installClass.pl index 60dafd76e..58cbc000d 100755 --- a/sbin/installClass.pl +++ b/sbin/installClass.pl @@ -11,10 +11,10 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -use lib "../lib"; use strict; use Getopt::Long; use Pod::Usage; +use WebGUI::Paths -inc; use WebGUI::Pluggable; use WebGUI::Session; use WebGUI::Paths; @@ -48,7 +48,7 @@ die "Config file '$configFile' does not exist!\n" if !-f WebGUI::Paths->configBase . '/' . $configFile; # Open the session -my $session = WebGUI::Session->open( "..", $configFile ); +my $session = WebGUI::Session->open( $configFile ); $session->user( { userId => 3 } ); # Install or uninstall the asset diff --git a/sbin/maintenanceMode.pl b/sbin/maintenanceMode.pl index e757056f5..72053a221 100755 --- a/sbin/maintenanceMode.pl +++ b/sbin/maintenanceMode.pl @@ -11,16 +11,10 @@ #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - +use strict; use Getopt::Long; use Pod::Usage; -use strict; +use WebGUI::Paths -inc; use WebGUI::Session; my $help; @@ -39,7 +33,7 @@ pod2usage( verbose => 2 ) if $help; pod2usage() if $configFile eq ""; -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); $session->setting->remove('specialState'); $session->setting->add('specialState','upgrading') unless $stop; $session->var->end; diff --git a/sbin/preload.perl b/sbin/preload.perl index 5a71f3ecd..17209bffe 100644 --- a/sbin/preload.perl +++ b/sbin/preload.perl @@ -1,62 +1,24 @@ use strict; -my $webguiRoot = '/data/WebGUI'; +use WebGUI::Paths -preload; -@INC = grep { $_ ne q{.} } @INC; +use Log::Log4perl; +Log::Log4perl->init( WebGUI::Paths->logConfig ); -unshift @INC, "$webguiRoot/lib"; +use DBI; +DBI->install_driver("mysql"); -# add custom lib directories to library search path -unshift @INC, grep { - if (!-d $_) { - warn "WARNING: Not adding lib directory '$_' from $webguiRoot/sbin/preload.custom: Directory does not exist.\n"; - 0; - } - else { - 1; - } -} readLines($webguiRoot."/sbin/preload.custom"); - -#---------------------------------------- -# Logger -#---------------------------------------- -require Log::Log4perl; -Log::Log4perl->init( $webguiRoot."/etc/log.conf" ); - -#---------------------------------------- -# Database connectivity. -#---------------------------------------- -#require Apache::DBI; # Uncomment if you want to enable connection pooling. Not recommended on servers with many sites, or those using db slaves. -require DBI; -DBI->install_driver("mysql"); # Change to match your database driver. - -#---------------------------------------- -# WebGUI modules. -#---------------------------------------- -require WebGUI; -require WebGUI::Config; -require WebGUI::Pluggable; - -# these modules should always be skipped -my @excludes; -push @excludes, readLines($webguiRoot."/sbin/preload.exclude"); - -WebGUI::Pluggable::findAndLoad( "WebGUI", - { - exclude => \@excludes, - onLoadFail => sub { warn sprintf 'Error loading %s: %s', @_ }, - } -); - -require APR::Request::Apache2; -require Apache2::Cookie; -require Apache2::ServerUtil; +use WebGUI; +use WebGUI::Config; +use APR::Request::Apache2; +use Apache2::Cookie; +use Apache2::ServerUtil; if ( $ENV{MOD_PERL} ) { # Add WebGUI to Apache version tokens my $server = Apache2::ServerUtil->server; $server->push_handlers(PerlPostConfigHandler => sub { - $server->add_version_component("WebGUI/".$WebGUI::VERSION); + $server->add_version_component('WebGUI/' . $WebGUI::VERSION); }); } @@ -64,28 +26,7 @@ $| = 1; print "\nStarting WebGUI ".$WebGUI::VERSION."\n"; -#---------------------------------------- -# Preload all site configs. -#---------------------------------------- -WebGUI::Config->loadAllConfigs($webguiRoot); - - -# reads lines from a file into an array, trimming white space and ignoring commented lines -sub readLines { - my $file = shift; - my @lines; - if (open(my $fh, '<', $file)) { - while (my $line = <$fh>) { - $line =~ s/#.*//; - $line =~ s/^\s+//; - $line =~ s/\s+$//; - next if !$line; - push @lines, $line; - } - close $fh; - } - return @lines; -} +WebGUI::Config->loadAllConfigs; 1; diff --git a/sbin/purgeWGAccess.pl b/sbin/purgeWGAccess.pl index 9ea4312fd..85ea8e5e9 100755 --- a/sbin/purgeWGAccess.pl +++ b/sbin/purgeWGAccess.pl @@ -10,16 +10,11 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Getopt::Long; use Pod::Usage; +use File::Find (); +use WebGUI::Paths -inc; use WebGUI::Config; local $| = 1; #disable output buffering @@ -31,8 +26,7 @@ GetOptions( pod2usage( verbose => 2 ) if $help; pod2usage() if $configFile eq ''; -my $config = WebGUI::Config->new($webguiRoot,$configFile); -use File::Find; +my $config = WebGUI::Config->new($configFile); print "\tRemoving unnecessary .wgaccess files.\n"; my $uploadsPath = $config->get('uploadsPath'); diff --git a/sbin/rebuildLineage.pl b/sbin/rebuildLineage.pl index 355d55ff9..a8d652634 100755 --- a/sbin/rebuildLineage.pl +++ b/sbin/rebuildLineage.pl @@ -10,22 +10,14 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - - -$| = 1; - +use strict; use Getopt::Long; use Pod::Usage; -use strict; +use WebGUI::Paths -inc; use WebGUI::Session; use WebGUI::Utility; +$| = 1; my $configFile; my $help; my $quiet; @@ -40,7 +32,7 @@ pod2usage( verbose => 2 ) if $help; pod2usage() unless (defined($configFile) && $configFile ne ''); print "Starting..." unless ($quiet); -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); print "OK\n" unless ($quiet); print "Looking for descendant replationships...\n" unless ($quiet); diff --git a/sbin/search.pl b/sbin/search.pl index 12e188345..7b4631f48 100755 --- a/sbin/search.pl +++ b/sbin/search.pl @@ -10,15 +10,9 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Getopt::Long; +use WebGUI::Paths -inc; use WebGUI::Asset; use WebGUI::Config; use WebGUI::Session; @@ -47,7 +41,7 @@ GetOptions( pod2usage( verbose => 2 ) if $help; if ($configFile) { - my $session = WebGUI::Session->open($webguiRoot, $configFile); + my $session = WebGUI::Session->open($configFile); if ($indexsite) { reindexSite($session); } elsif ($updatesite) { @@ -67,10 +61,10 @@ if ($configFile) { #------------------------------------------------------------------- sub reindexAllSites { - my $configs = WebGUI::Config->readAllConfigs($webguiRoot); + my $configs = WebGUI::Config->readAllConfigs; foreach my $site (keys %{$configs}) { print "Indexing ".$site."...\n"; - my $session = WebGUI::Session->open($webguiRoot,$site); + my $session = WebGUI::Session->open($site); reindexSite($session); $session->var->end; $session->close; diff --git a/sbin/spectre.pl b/sbin/spectre.pl index 99d88217a..d1991ae9e 100755 --- a/sbin/spectre.pl +++ b/sbin/spectre.pl @@ -10,19 +10,14 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - -use Pod::Usage; use strict; use warnings; +use Pod::Usage; use Getopt::Long; +use File::Spec; use POE::Component::IKC::ClientLite; use Spectre::Admin; +use WebGUI::Paths -inc; use WebGUI::Config; use JSON; @@ -52,9 +47,7 @@ GetOptions( pod2usage( verbose => 2 ) if $help; pod2usage() unless ($ping||$shutdown||$daemon||$run||$test||$status); -require File::Spec; -# Convert to absolute since we'll be changing directory -my $config = WebGUI::Config->new(File::Spec->rel2abs($webguiRoot),"spectre.conf",1); +my $config = WebGUI::Config->new( WebGUI::Paths->spectreConfig, 1); unless (defined $config) { print < != 0 && !$override ) { } print "Starting..." unless ($quiet); -my $session = WebGUI::Session->open( $webguiRoot, $configFile ); +my $session = WebGUI::Session->open( $configFile ); $session->user( { userId => 3 } ); print "OK\n" unless ($quiet); diff --git a/sbin/thumbnailer.pl b/sbin/thumbnailer.pl index 88ac1013f..303a0b5a9 100755 --- a/sbin/thumbnailer.pl +++ b/sbin/thumbnailer.pl @@ -10,13 +10,6 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - #----------------------------------------- # A little utility to generate WebGUI # thumbnails. @@ -29,6 +22,7 @@ use Pod::Usage; use Image::Magick; +use WebGUI::Paths -inc; use WebGUI::Utility; my $thumbnailSize; diff --git a/sbin/upgrade.pl b/sbin/upgrade.pl index 7e1e9a332..edf176414 100755 --- a/sbin/upgrade.pl +++ b/sbin/upgrade.pl @@ -10,29 +10,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Cwd (); use File::Path (); +use File::Spec; use Getopt::Long (); use Pod::Usage (); +use WebGUI::Paths -inc; -foreach my $libDir ( readLines( "$webguiRoot/sbin/preload.custom" ) ) { - if ( !-d $libDir ) { - warn "WARNING: Not adding lib directory '$libDir' from $webguiRoot/sbin/preload.custom: Directory does not exist.\n"; - next; - } - unshift @INC, $libDir; -} - -require WebGUI::Config; -require WebGUI::Session; +use WebGUI::Config; +use WebGUI::Session; my $help; my $history; @@ -108,14 +95,14 @@ if ($^O =~ /^Win/i) { } else { $slash = "/"; } -our $upgradesPath = $webguiRoot.$slash."docs".$slash."upgrades".$slash; +our $upgradesPath = WebGUI::Paths->upgrades; our (%upgrade, %config); ## Find site configs. print "\nGetting site configs...\n" unless ($quiet); -my $configs = WebGUI::Config->readAllConfigs($webguiRoot); +my $configs = WebGUI::Config->readAllConfigs; foreach my $filename (keys %{$configs}) { print "\tProcessing $filename.\n" unless ($quiet); $config{$filename}{configFile} = $filename; @@ -130,7 +117,7 @@ foreach my $filename (keys %{$configs}) { $config{$filename}{mysqlCLI} = $configs->{$filename}->get("mysqlCLI"); $config{$filename}{mysqlDump} = $configs->{$filename}->get("mysqlDump"); $config{$filename}{backupPath} = $configs->{$filename}->get("backupPath"); - my $session = WebGUI::Session->open($webguiRoot,$filename); + my $session = WebGUI::Session->open($filename); ($config{$filename}{version}) = $session->db->quickArray("select webguiVersion from webguiVersion order by dateApplied desc, length(webguiVersion) desc, webguiVersion desc limit 1"); unless ($history) { @@ -141,10 +128,10 @@ foreach my $filename (keys %{$configs}) { } unless ($skipDelete) { print "\tDeleting temp files.\n" unless ($quiet); - my $path = $configs->{$filename}->get("uploadsPath").$slash."temp"; + my $path = File::Spec->catdir($configs->{$filename}->get("uploadsPath"), 'temp'); File::Path::rmtree($path) unless ($path eq "" || $path eq "/" || $path eq "/data"); print "\tDeleting file cache.\n" unless ($quiet); - $path = $configs->{$filename}->get("fileCacheRoot")||"/tmp/WebGUICache"; + $path = $configs->{$filename}->get("fileCacheRoot") || "/tmp/WebGUICache"; File::Path::rmtree($path) unless ($path eq "" || $path eq "/" || $path eq "/data"); } } @@ -159,7 +146,7 @@ if ($history) { print "\nDisplaying upgrade history for each site.\n"; foreach my $file (keys %config) { print "\n".$file."\n"; - my $session = WebGUI::Session->open($webguiRoot,$file); + my $session = WebGUI::Session->open($file); my $sth = $session->db->read("select * from webguiVersion order by dateApplied asc, webguiVersion asc"); while (my $data = $sth->hashRef) { print "\t".sprintf("%-8s %-15s %-15s", @@ -220,7 +207,7 @@ foreach my $filename (keys %config) { $cmd .= " --host=".$config{$filename}{host} if ($config{$filename}{host}); $cmd .= " --port=".$config{$filename}{port} if ($config{$filename}{port}); $cmd .= " --add-drop-table ".$config{$filename}{db}." --result-file=" - .$backupTo.$slash.$config{$filename}{db}."_".$upgrade{$upgrade}{from}."_".time.".sql"; + .File::Spec->catfile($backupTo, $config{$filename}{db}."_".$upgrade{$upgrade}{from}."_".time.".sql"); unless (system($cmd)) { print "OK\n" unless ($quiet); } else { @@ -267,7 +254,7 @@ foreach my $filename (keys %config) { sleep 1; # Sleep a second to avoid adding asset revisions too quickly } chdir($currentPath); - my $session = WebGUI::Session->open($webguiRoot,$filename); + my $session = WebGUI::Session->open($filename); print "\tSetting site upgrade completed..." unless ($quiet); $session->setting->remove('specialState'); $session->close(); diff --git a/sbin/userImport.pl b/sbin/userImport.pl index 55c9719bb..f040b9951 100755 --- a/sbin/userImport.pl +++ b/sbin/userImport.pl @@ -10,17 +10,11 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -our ($webguiRoot); - -BEGIN { - $webguiRoot = ".."; - unshift (@INC, $webguiRoot."/lib"); -} - use strict; use Digest::MD5; use Getopt::Long; use Pod::Usage; +use WebGUI::Paths -inc; use WebGUI::DateTime; use WebGUI::Group; use WebGUI::Session; @@ -78,7 +72,7 @@ if (!($^O =~ /^Win/i) && $> != 0 && !$override) { print "Starting up..." unless ($quiet); -my $session = WebGUI::Session->open($webguiRoot,$configFile); +my $session = WebGUI::Session->open($configFile); $session->user({userId=>3}); open(FILE,"<".$usersFile); print "OK\n" unless ($quiet); diff --git a/t/Config.t b/t/Config.t index ca0112f02..395058d65 100644 --- a/t/Config.t +++ b/t/Config.t @@ -27,7 +27,7 @@ is( ref $config->get("macros"), "HASH", "get() macros hash" ); is( ref $config->get("assets"), "HASH", "get() assets hash" ); is( ref $config->get("shippingDrivers"), "ARRAY", "get() shippingDrivers array" ); is( $config->getFilename, basename($configFile), "getFilename()" ); -ok( defined WebGUI::Config->readAllConfigs($webguiRoot), "readAllConfigs" ); +ok( defined WebGUI::Config->readAllConfigs, "readAllConfigs" ); $config->addToArray("shippingDrivers","TEST"); my $found = 0; foreach my $driver ( @{$config->get("shippingDrivers")}) { diff --git a/t/Group.t b/t/Group.t index d1cf801c4..d1b43d765 100644 --- a/t/Group.t +++ b/t/Group.t @@ -540,7 +540,7 @@ my @sessionBank = (); foreach my $idx (0..$#scratchTests) { ##Create a new session - $sessionBank[$idx] = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); + $sessionBank[$idx] = WebGUI::Session->open(WebGUI::Test->file); ##Create a new user and make this session's default user that user $itchies[$idx] = WebGUI::User->new($sessionBank[$idx], "new"); @@ -587,7 +587,7 @@ foreach my $idx (0..$#ipTests) { $ENV{REMOTE_ADDR} = $ip; ##Create a new session - $sessionBank[$idx] = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); + $sessionBank[$idx] = WebGUI::Session->open(WebGUI::Test->file); ##Create a new user and make this session's default user that user $tcps[$idx] = WebGUI::User->new($sessionBank[$idx], "new"); diff --git a/t/Macro/UsersOnline.t b/t/Macro/UsersOnline.t index c64e6e32b..d3966fa35 100644 --- a/t/Macro/UsersOnline.t +++ b/t/Macro/UsersOnline.t @@ -178,7 +178,7 @@ sub setupUsers { # Create sessions such that users are added to the userSession table foreach (@users) { - my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file); + my $newSession = WebGUI::Session->open(WebGUI::Test::file); $newSession->user({user => $_}); } addToCleanup(@users); diff --git a/t/Session/ErrorHandler.t b/t/Session/ErrorHandler.t index dfdd3797f..84229a9b2 100644 --- a/t/Session/ErrorHandler.t +++ b/t/Session/ErrorHandler.t @@ -225,8 +225,8 @@ my $showDebug = $eh->showDebug; # #################################################### -my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file); -WebGUI::Test->sessionsToDelete($newSession); +my $newSession = WebGUI::Session->open(WebGUI::Test::file); +addToCleanup($newSession); my $outputBuffer; open my $outputHandle, '>', \$outputBuffer or die "Unable to create scalar filehandle: $!\n"; $newSession->output->setHandle($outputHandle); diff --git a/t/Session/Scratch.t b/t/Session/Scratch.t index 948e5bdf8..173719f7c 100644 --- a/t/Session/Scratch.t +++ b/t/Session/Scratch.t @@ -54,7 +54,7 @@ for (my $count = 1; $count <= $maxCount; $count++){ } ##Creating a new session with the previous session's Id should clone the scratch data -my $newSession = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file, undef, undef, $session->getId); +my $newSession = WebGUI::Session->open(WebGUI::Test->file, undef, undef, $session->getId); is($newSession->getId, $session->getId, "Successful session duplication"); @@ -81,7 +81,7 @@ is($scratch->set('','value'), undef, 'set returns undef unless it gets a name ev # ############################################ -my @sessionBank = map { WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file) } 0..3; +my @sessionBank = map { WebGUI::Session->open(WebGUI::Test->file) } 0..3; ##Set variables to be deleted by name foreach my $i (0..3) { diff --git a/t/Shop/Cart.t b/t/Shop/Cart.t index b3b96e266..e64efad04 100644 --- a/t/Shop/Cart.t +++ b/t/Shop/Cart.t @@ -133,8 +133,8 @@ is( $cart->readyForCheckout, 0, 'Cannot checkout an empty cart' ); is($session->db->quickScalar("select count(*) from cartItem where cartId=?",[ $cart->getId ]), 0, "Items are removed from cart."); -my $session2 = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); -WebGUI::Test->sessionsToDelete($session2); +my $session2 = WebGUI::Session->open(WebGUI::Test->file); +addToCleanup($session2); $session2->user({userId => 3}); my $cart2 = WebGUI::Shop::Cart->newBySession($session2); isnt( diff --git a/t/User.t b/t/User.t index dd324c1a0..272d2d196 100644 --- a/t/User.t +++ b/t/User.t @@ -80,7 +80,7 @@ is($user->status, "Selfdestructed", 'status("Selfdestructed")'); # Deactivation user deletes all sessions and scratches -my $newSession = WebGUI::Session->open( WebGUI::Test->root, WebGUI::Test->file ); +my $newSession = WebGUI::Session->open( WebGUI::Test->file ); $newSession->user({ user => $user }); $newSession->scratch->set("hasStapler" => "no"); diff --git a/t/VersionTag.t b/t/VersionTag.t index 368393a96..95e8b305f 100644 --- a/t/VersionTag.t +++ b/t/VersionTag.t @@ -214,7 +214,7 @@ is($siteWideTag->getId(), $siteWideTagId, 'versionTagMode siteWide: reclaim site ## Through in a new session as different user -my $admin_session = WebGUI::Session->open($WebGUI::Test::WEBGUI_ROOT, $WebGUI::Test::CONFIG_FILE); +my $admin_session = WebGUI::Session->open($WebGUI::Test->file); $admin_session->user({'userId' => 3}); WebGUI::Test->sessionsToDelete($admin_session); @@ -279,8 +279,8 @@ $adminUserTag->rollback(); is($tag->getAssetCount, 1, qq{$test_prefix [singlePerUser] tag with 1 asset}); # create admin session - my $admin_session = WebGUI::Session->open($WebGUI::Test::WEBGUI_ROOT, $WebGUI::Test::CONFIG_FILE); - WebGUI::Test->sessionsToDelete($admin_session); + my $admin_session = WebGUI::Session->open($WebGUI::Test->file); + addToCleanup($session); $admin_session->user({'userId' => 3}); setUserVersionTagMode($admin_session->user(), q{autoCommit}); @@ -331,8 +331,8 @@ $adminUserTag->rollback(); is($tag->getAssetCount, 1, qq{$test_prefix [siteWide] tag with 1 asset}); # create admin session - $admin_session = WebGUI::Session->open($WebGUI::Test::WEBGUI_ROOT, $WebGUI::Test::CONFIG_FILE); - WebGUI::Test->sessionsToDelete($admin_session); + $admin_session = WebGUI::Session->open(WebGUI::Test->file); + addToCleanup($admin_session); $admin_session->user({'userId' => 3}); setUserVersionTagMode($admin_session->user(), q{autoCommit}); diff --git a/t/Workflow/Activity/DeleteExpiredSessions.t b/t/Workflow/Activity/DeleteExpiredSessions.t index 2164ac6d9..3ccd755b3 100644 --- a/t/Workflow/Activity/DeleteExpiredSessions.t +++ b/t/Workflow/Activity/DeleteExpiredSessions.t @@ -58,14 +58,14 @@ note $scratchCount; my @sessions; foreach (1..2) { - push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); + push @sessions, WebGUI::Session->open(WebGUI::Test->file); } ##Force automatic expiration of the sessions $session->setting->set('sessionTimeout', -500); foreach (1..2) { - push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); + push @sessions, WebGUI::Session->open(WebGUI::Test->file); } $session->setting->set('sessionTimeout', $origSessionTimeout ); diff --git a/t/Workflow/Activity/RemoveOldCarts.t b/t/Workflow/Activity/RemoveOldCarts.t index 5def4eabf..43f1d53b0 100644 --- a/t/Workflow/Activity/RemoveOldCarts.t +++ b/t/Workflow/Activity/RemoveOldCarts.t @@ -37,8 +37,8 @@ WebGUI::Test->tagsToRollback($tag); my $cart1 = WebGUI::Shop::Cart->create($session); -my $session2 = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file); -WebGUI::Test->sessionsToDelete($session2); +my $session2 = WebGUI::Session->open(WebGUI::Test->file); +addToCleanup($session2); my $cart2 = WebGUI::Shop::Cart->create($session2); $cart2->update({creationDate => time()-10000});