[Rt-commit] r4429 - in rt/branches/3.7-EXPERIMENTAL: . etc lib
lib/RT lib/RT/Interface
ruz at bestpractical.com
ruz at bestpractical.com
Sat Jan 21 01:54:07 EST 2006
Author: ruz
Date: Sat Jan 21 01:54:06 2006
New Revision: 4429
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
rt/branches/3.7-EXPERIMENTAL/lib/RT.pm.in
rt/branches/3.7-EXPERIMENTAL/lib/RT/Config.pm
rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm
rt/branches/3.7-EXPERIMENTAL/lib/RT/Principal_Overlay.pm
rt/branches/3.7-EXPERIMENTAL/lib/RT/Record.pm
rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in
Log:
r1652 at cubic-pc: cubic | 2006-01-21 09:41:26 +0300
config handling fixes
Modified: rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in Sat Jan 21 01:54:06 2006
@@ -238,7 +238,7 @@
# sprintf() format of the friendly 'From:' header; its arguments
# are WatcherType and TicketId.
-Set($FriendlyToLineFormat, "\"%s of $Config->Get('rtname') Ticket #%s\":;");
+Set($FriendlyToLineFormat, "\"%s of ". RT->Config->Get('rtname') ." Ticket #%s\":;");
# By default, RT doesn't notify the person who performs an update, as they
# already know what they've done. If you'd like to change this behaviour,
@@ -318,32 +318,31 @@
# your server
# $WebPath requires a leading / but no trailing /
-Set($WebPath , "");
+Set($WebPath, "");
# If we're running as a superuser, run on port 80
# Otherwise, pick a high port for this user.
-Set($WebPort , 80);# + ($< * 7274) % 32766 + ($< && 1024));
+Set($WebPort, 80);# + ($< * 7274) % 32766 + ($< && 1024));
# This is the Scheme, server and port for constructing urls to webrt
# $WebBaseURL doesn't need a trailing /
-Set($WebBaseURL , "http://localhost:". $Config->Get('WebPort'));
+Set($WebBaseURL, "http://localhost:". RT->Config->Get('WebPort'));
-Set($WebURL , $Config->Get('WebBaseURL') . $Config->Get('WebPath') . "/");
+Set($WebURL, RT->Config->Get('WebBaseURL') . RT->Config->Get('WebPath') . "/");
# $WebImagesURL points to the base URL where RT can find its images.
-Set($WebImagesURL , $Config->Get('WebPath') . "/NoAuth/images/");
+Set($WebImagesURL, RT->Config->Get('WebPath') . "/NoAuth/images/");
# $LogoURL points to the URL of the RT logo displayed in the web UI
-Set($LogoURL , $Config->Get('WebImagesURL') . "bplogo.gif");
+Set($LogoURL, $Config->Get('WebImagesURL') . "bplogo.gif");
# WebNoAuthRegex - What portion of RT's URLspace should not require
# authentication.
-Set($WebNoAuthRegex, qr!^(?:/+NoAuth/|
- /+REST/\d+\.\d+/NoAuth/)!x );
+Set($WebNoAuthRegex, qr{^ (?:/+NoAuth/ | /+REST/\d+\.\d+/NoAuth/) }x );
# For message boxes, set the entry box width and what type of wrapping
# to use.
@@ -455,8 +454,8 @@
# $DefaultSearchResultFormat is the default format for RT search results
Set ($DefaultSearchResultFormat, qq{
- '<B><A HREF="}. RT->Config->Get('WebPath') .qq{/Ticket/Display.html?id=__id__">__id__</a></B>/TITLE:#',
- '<B><A HREF="}. RT->Config->Get('WebPath') .qq{/Ticket/Display.html?id=__id__">__Subject__</a></B>/TITLE:Subject',
+ '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></B>/TITLE:#',
+ '<B><A HREF="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></B>/TITLE:Subject',
Status,
QueueName,
OwnerName,
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT.pm.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT.pm.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT.pm.in Sat Jan 21 01:54:06 2006
@@ -44,55 +44,42 @@
#
# END BPS TAGGED BLOCK }}}
package RT;
+
use strict;
-use RT::I18N;
-use RT::CurrentUser;
-use RT::System;
-
-use vars qw($VERSION $Config $System $SystemUser $Nobody $Handle $Logger
- $BasePath
- $EtcPath
- $VarPath
- $LocalPath
- $LocalEtcPath
- $LocalLexiconPath
- $LogDir
- $BinPath
- $MasonComponentRoot
- $MasonLocalComponentRoot
- $MasonDataDir
- $MasonSessionDir
-);
+use warnings;
-$VERSION = '@RT_VERSION_MAJOR at .@RT_VERSION_MINOR at .@RT_VERSION_PATCH@';
+use File::Spec ();
- at DATABASE_ENV_PREF@
+use vars qw($VERSION $Config $System $SystemUser $Nobody $Handle $Logger);
-$BasePath = '@RT_PATH@';
+our $VERSION = '@RT_VERSION_MAJOR at .@RT_VERSION_MINOR at .@RT_VERSION_PATCH@';
-$EtcPath = '@RT_ETC_PATH@';
-$BinPath = '@RT_BIN_PATH@';
-$VarPath = '@RT_VAR_PATH@';
-$LocalPath = '@RT_LOCAL_PATH@';
-$LocalEtcPath = '@LOCAL_ETC_PATH@';
-$LocalLexiconPath = '@LOCAL_LEXICON_PATH@';
+ at DATABASE_ENV_PREF@
+
+our $BasePath = '@RT_PATH@';
+our $EtcPath = '@RT_ETC_PATH@';
+our $BinPath = '@RT_BIN_PATH@';
+our $VarPath = '@RT_VAR_PATH@';
+our $LocalPath = '@RT_LOCAL_PATH@';
+our $LocalEtcPath = '@LOCAL_ETC_PATH@';
+our $LocalLexiconPath = '@LOCAL_LEXICON_PATH@';
# $MasonComponentRoot is where your rt instance keeps its mason html files
-$MasonComponentRoot = '@MASON_HTML_PATH@';
+our $MasonComponentRoot = '@MASON_HTML_PATH@';
# $MasonLocalComponentRoot is where your rt instance keeps its site-local
# mason html files.
-$MasonLocalComponentRoot = '@MASON_LOCAL_HTML_PATH@';
+our $MasonLocalComponentRoot = '@MASON_LOCAL_HTML_PATH@';
# $MasonDataDir Where mason keeps its datafiles
-$MasonDataDir = '@MASON_DATA_PATH@';
+our $MasonDataDir = '@MASON_DATA_PATH@';
# RT needs to put session data (for preserving state between connections
# via the web interface)
-$MasonSessionDir = '@MASON_SESSION_PATH@';
+our $MasonSessionDir = '@MASON_SESSION_PATH@';
@@ -122,41 +109,18 @@
=cut
sub LoadConfig {
-
- # get list of the core config files
- my @configs = ();
- foreach my $path( $RT::LocalEtcPath, $RT::EtcPath ) {
- my $mask = File::Spec->catfile($path, "*_Config.pm");
- my @files = glob $mask;
- @files = grep { $_ !~ /^RT_Config\.pm$/ }
- grep { $_ && /^\w+_Config\.pm$/ }
- map { s/^.*[\\\/]//; $_ } @files;
- push @configs, @files;
- }
- @configs = sort @configs;
- unshift(@configs, 'RT_Config.pm');
-
- foreach my $file( @configs ) {
- local @INC = ( $RT::LocalEtcPath, $RT::EtcPath, @INC );
- local *Set = sub { $_[0] = $_[1] unless defined $_[0] };
-
- # load site config
- my $site_file = $file;
- $site_file =~ s/(?=Config\.pm$)/Site/;
- eval { require $site_file };
- if( $@ && $@ !~ qr{^Can't locate \Q$site_file} ) {
- die "Couldn't load site config file '$site_file': $@";
- }
-
- # load core config
- eval { require $file };
- if( $@ ) {
- die "Couldn't load core config file '$file': $@";
- }
- }
+ require RT::Config;
+ $Config = new RT::Config;
+ $Config->LoadConfigs;
+ require RT::I18N;
RT::I18N->Init;
}
+sub Config {
+ return $Config;
+}
+
+
=head2 Init
Conenct to the database, set up logging.
@@ -169,13 +133,15 @@
ConnectToDatabase();
#RT's system user is a genuine database user. its id lives here
+ require RT::CurrentUser;
$SystemUser = new RT::CurrentUser();
$SystemUser->LoadByName('RT_System');
#RT's "nobody user" is a genuine database user. its ID lives here.
$Nobody = new RT::CurrentUser();
$Nobody->LoadByName('Nobody');
-
+
+ require RT::System;
$System = RT::System->new();
InitClasses();
@@ -206,108 +172,103 @@
# We have to set the record separator ($, man perlvar)
# or Log::Dispatch starts getting
# really pissy, as some other module we use unsets it.
-
$, = '';
use Log::Dispatch 1.6;
unless ($RT::Logger) {
- $RT::Logger = Log::Dispatch->new();
+ $RT::Logger = Log::Dispatch->new;
+ my $simple_cb = sub {
+ # if this code throw any warning we can get segfault
+ no warnings;
+
+ my %p = @_;
+
+ my $frame = 0; # stack frame index
+ # skip Log::* stack frames
+ $frame++ while( caller($frame) && caller($frame) =~ /^Log::/ );
+
+ my ($package, $filename, $line) = caller($frame);
+ $p{message} =~ s/(?:\r*\n)+$//;
+ my $str = "[".gmtime(time)."] [".$p{level}."]: $p{message} ($filename:$line)\n";
+
+ if( $Config->Get('LogStackTraces') ) {
+ $str .= "\nStack trace:\n";
+ # skip calling of the Log::* subroutins
+ $frame++ while( caller($frame) && (caller($frame))[3] =~ /^Log::/ );
+ while( my ($package, $filename, $line, $sub) = caller($frame++) ) {
+ $str .= "\t". $sub ."() called at $filename:$line\n";
+ }
+ }
+ return $str;
+ };
+
+ my $syslog_cb = sub {
+ my %p = @_;
- my $simple_cb = sub {
- # if this code throw any warning we can get segfault
- no warnings;
-
- my %p = @_;
-
- my $frame = 0; # stack frame index
- # skip Log::* stack frames
- $frame++ while( caller($frame) && caller($frame) =~ /^Log::/ );
-
- my ($package, $filename, $line) = caller($frame);
- $p{message} =~ s/(?:\r*\n)+$//;
- my $str = "[".gmtime(time)."] [".$p{level}."]: $p{message} ($filename:$line)\n";
-
- if( $RT::LogStackTraces ) {
- $str .= "\nStack trace:\n";
- # skip calling of the Log::* subroutins
- $frame++ while( caller($frame) && (caller($frame))[3] =~ /^Log::/ );
- while( my ($package, $filename, $line, $sub) = caller($frame++) ) {
- $str .= "\t". $sub ."() called at $filename:$line\n";
+ my $frame = 0; # stack frame index
+ # skip Log::* stack frames
+ $frame++ while( caller($frame) && caller($frame) =~ /^Log::/ );
+ my ($package, $filename, $line) = caller($frame);
+
+ # syswrite() cannot take utf8; turn it off here.
+ Encode::_utf8_off($p{message});
+
+ $p{message} =~ s/(?:\r*\n)+$//;
+ if ($p{level} eq 'debug') {
+ return "$p{message}\n"
+ } else {
+ return "$p{message} ($filename:$line)\n"
+ }
+ };
+
+ if ( $Config->Get('LogToFile') ) {
+ my ($filename, $logdir) = (
+ $Config->Get('LogToFileNamed') || 'rt.log',
+ $Config->Get('LogDir') || File::Spec->catdir( $VarPath, 'log' ),
+ );
+ if ( $filename =~ m![/\\]! ) { # looks like an absolute path.
+ ($logdir) = $filename =~ m{^(.*[/\\])};
+ }
+ else {
+ $filename = File::Spec->catfile( $logdir, $filename );
}
- }
- return $str;
- };
- my $syslog_cb = sub {
- my %p = @_;
+ unless ( -d $logdir && ( ( -f $filename && -w $filename ) || -w $logdir ) ) {
+ # localizing here would be hard when we don't have a current user yet
+ die "Log file '$filename' couldn't be written or created.\n RT can't run.";
+ }
- my $frame = 0; # stack frame index
- # skip Log::* stack frames
- $frame++ while( caller($frame) && caller($frame) =~ /^Log::/ );
- my ($package, $filename, $line) = caller($frame);
-
- # syswrite() cannot take utf8; turn it off here.
- Encode::_utf8_off($p{message});
-
- $p{message} =~ s/(?:\r*\n)+$//;
- if ($p{level} eq 'debug') {
- return "$p{message}\n"
- } else {
- return "$p{message} ($filename:$line)\n"
- }
- };
-
- if ($RT::LogToFile) {
- my ($filename, $logdir);
- if ($RT::LogToFileNamed =~ m![/\\]!) {
- # looks like an absolute path.
- $filename = $RT::LogToFileNamed;
- ($logdir) = $RT::LogToFileNamed =~ m!^(.*[/\\])!;
+ require Log::Dispatch::File;
+ $RT::Logger->add( Log::Dispatch::File->new
+ ( name=>'file',
+ min_level=> $Config->Get('LogToFile'),
+ filename=> $filename,
+ mode=>'append',
+ callbacks => $simple_cb,
+ ));
}
- else {
- $filename = "$RT::LogDir/$RT::LogToFileNamed";
- $logdir = $RT::LogDir;
+ if ( $Config->Get('LogToScreen') ) {
+ require Log::Dispatch::Screen;
+ $RT::Logger->add( Log::Dispatch::Screen->new
+ ( name => 'screen',
+ min_level => $Config->Get('LogToScreen'),
+ callbacks => $simple_cb,
+ stderr => 1,
+ ));
}
-
- unless ( -d $logdir && ( ( -f $filename && -w $filename ) || -w $logdir ) ) {
- # localizing here would be hard when we don't have a current user yet
- die "Log file $filename couldn't be written or created.\n RT can't run.";
+ if ( $Config->Get('LogToSyslog') ) {
+ require Log::Dispatch::Syslog;
+ $RT::Logger->add(Log::Dispatch::Syslog->new
+ ( name => 'syslog',
+ ident => 'RT',
+ min_level => $Config->Get('LogToSyslog'),
+ callbacks => $syslog_cb,
+ stderr => 1,
+ $Config->Get('LogToSyslogConf'),
+ ));
}
- package Log::Dispatch::File;
- require Log::Dispatch::File;
- $RT::Logger->add(Log::Dispatch::File->new
- ( name=>'rtlog',
- min_level=> RT->Config->Get('LogToFile'),
- filename=> $filename,
- mode=>'append',
- callbacks => $simple_cb,
- ));
- }
- if ($RT::LogToScreen) {
- package Log::Dispatch::Screen;
- require Log::Dispatch::Screen;
- $RT::Logger->add(Log::Dispatch::Screen->new
- ( name => 'screen',
- min_level => $RT::LogToScreen,
- callbacks => $simple_cb,
- stderr => 1,
- ));
- }
- if ($RT::LogToSyslog) {
- package Log::Dispatch::Syslog;
- require Log::Dispatch::Syslog;
- $RT::Logger->add(Log::Dispatch::Syslog->new
- ( name => 'syslog',
- ident => 'RT',
- min_level => $RT::LogToSyslog,
- callbacks => $syslog_cb,
- stderr => 1,
- RT->Config->Get('LogToSyslogConf')
- ));
- }
-
}
# {{{ Signal handlers
@@ -373,7 +334,7 @@
sub SystemUser {
return($SystemUser);
-}
+}
sub Nobody {
return ($Nobody);
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Config.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Config.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Config.pm Sat Jan 21 01:54:06 2006
@@ -3,6 +3,8 @@
use strict;
use warnings;
+use File::Spec ();
+
=head1 NAME
RT::Config - RT's config
@@ -74,9 +76,9 @@
=head2 LoadConfigs
-Load all configs. First of all load RT's config then load config files
-of the extensions in alphabetic order.
-Takes nothing.
+Load all configs. First of all load RT's config then load
+extensions' config files in alphabetical order.
+Takes no arguments.
=cut
@@ -137,7 +139,7 @@
Extension => $is_ext,
);
};
- local @INC = ($LocalEtcPath, $EtcPath);
+ local @INC = ($RT::LocalEtcPath, $RT::EtcPath);
require $args{'File'};
};
if( $@ ) {
@@ -161,9 +163,9 @@
foreach my $path( $RT::LocalEtcPath, $RT::EtcPath ) {
my $mask = File::Spec->catfile($path, "*_Config.pm");
my @files = glob $mask;
- @files = grep { $_ !~ /^RT_Config\.pm$/ }
- grep { $_ && /^\w+_Config\.pm$/ }
- map { s/^.*[\\\/]//; $_ } @files;
+ @files = grep !/^RT_Config\.pm$/,
+ grep $_ && /^\w+_Config\.pm$/,
+ map { s/^.*[\\\/]//; $_ } @files;
push @configs, @files;
}
@@ -184,6 +186,8 @@
my $self = shift;
my $name = shift;
my $type = $META{$name}->{'Type'} || 'SCALAR';
+ return $OPTIONS{$name} unless wantarray;
+
if( $type eq 'ARRAY' ) {
return @{ $OPTIONS{$name} };
} elsif( $type eq 'HASH' ) {
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email.pm Sat Jan 21 01:54:06 2006
@@ -250,7 +250,8 @@
}
if (RT->Config->Get('MailCommand') eq 'sendmailpipe') {
- open (MAIL, "|RT->Config->Get('SendmailPath') RT->Config->Get('SendmailArguments')") || return(0);
+ my $cmd = RT->Config->Get('SendmailPath') ." ". RT->Config->Get('SendmailArguments');
+ open (MAIL, "|$cmd") || return(0);
print MAIL $entity->as_string;
close(MAIL);
}
@@ -570,7 +571,7 @@
# Since this needs loading, no matter what
- foreach ( @mail_plugins ) {
+ foreach ( grep $_, @mail_plugins ) {
my $Code;
my $NewAuthStat;
if ( ref($_) eq "CODE" ) {
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Principal_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Principal_Overlay.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Principal_Overlay.pm Sat Jan 21 01:54:06 2006
@@ -50,12 +50,10 @@
use strict;
use warnings;
-no warnings qw(redefine);
-
use Cache::Simple::TimedExpiry;
-
+use RT;
use RT::Group;
use RT::User;
@@ -74,12 +72,10 @@
sub IsGroup {
my $self = shift;
- if ($self->PrincipalType eq 'Group') {
- return(1);
- }
- else {
- return undef;
+ if ( $self->PrincipalType eq 'Group' ) {
+ return 1;
}
+ return undef;
}
# }}}
@@ -116,18 +112,18 @@
sub Object {
my $self = shift;
- unless ($self->{'object'}) {
- if ($self->IsUser) {
- $self->{'object'} = RT::User->new($self->CurrentUser);
- }
- elsif ($self->IsGroup) {
- $self->{'object'} = RT::Group->new($self->CurrentUser);
- }
- else {
- $RT::Logger->crit("Found a principal (".$self->Id.") that was neither a user nor a group");
- return(undef);
- }
- $self->{'object'}->Load($self->ObjectId());
+ unless ( $self->{'object'} ) {
+ if ( $self->IsUser ) {
+ $self->{'object'} = RT::User->new($self->CurrentUser);
+ }
+ elsif ( $self->IsGroup ) {
+ $self->{'object'} = RT::Group->new($self->CurrentUser);
+ }
+ else {
+ $RT::Logger->crit("Found a principal (".$self->Id.") that was neither a user nor a group");
+ return(undef);
+ }
+ $self->{'object'}->Load( $self->ObjectId() );
}
return ($self->{'object'});
@@ -494,11 +490,7 @@
sub _RolesForObject {
my $self = shift;
my $type = shift;
- my $id = shift;
-
- unless ($id) {
- $id = '0';
- }
+ my $id = shift || 0;
# This should never be true.
unless ($id =~ /^\d+$/) {
@@ -528,8 +520,9 @@
sub InvalidateACLCache {
$_ACL_CACHE = Cache::Simple::TimedExpiry->new();
- $_ACL_CACHE->expire_after(RT->Config->Get('ACLCacheLifetime')||60);
-
+ my $lifetime;
+ $lifetime = $RT::Config->Get('ACLCacheLifetime') if $RT::Config;
+ $_ACL_CACHE->expire_after( $lifetime || 60 );
}
# }}}
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Record.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Record.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Record.pm Sat Jan 21 01:54:06 2006
@@ -71,17 +71,15 @@
use RT::Base;
use strict;
-use vars qw/@ISA $_TABLE_ATTR/;
- at ISA = qw(RT::Base);
-
-if ( RT->Config->Get('DontCacheSearchBuilderRecords') ) {
- require DBIx::SearchBuilder::Record;
- push @ISA, 'DBIx::SearchBuilder::Record';
-} else {
- require DBIx::SearchBuilder::Record::Cachable;
- push @ISA, 'DBIx::SearchBuilder::Record::Cachable';
+our $_TABLE_ATTR;
+our @ISA = qw(RT::Base);
+my $base = 'DBIx::SearchBuilder::Record::Cachable';
+if ( $RT::Config && $RT::Config->Get('DontCacheSearchBuilderRecords') ) {
+ $base = 'DBIx::SearchBuilder::Record';
}
+eval "require $base" or die $@;
+push @ISA, $base;
# {{{ sub _Init
Modified: rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in (original)
+++ rt/branches/3.7-EXPERIMENTAL/sbin/rt-setup-database.in Sat Jan 21 01:54:06 2006
@@ -54,21 +54,13 @@
#This drags in RT's config.pm
# We do it in a begin block because RT::Handle needs to know the type to do its
# inheritance
-use RT;
+BEGIN {
+ use RT;
+ RT::LoadConfig();
+ RT::InitClasses();
+}
use Carp;
-use RT::User;
-use RT::CurrentUser;
-use RT::Template;
-use RT::ScripAction;
-use RT::ACE;
-use RT::Group;
-use RT::User;
-use RT::Queue;
-use RT::ScripCondition;
-use RT::CustomField;
-use RT::Scrip;
-RT::LoadConfig();
use Term::ReadKey;
use Getopt::Long;
More information about the Rt-commit
mailing list