1 # {{{ BEGIN BPS TAGGED BLOCK
5 # This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # CONTRIBUTION SUBMISSION POLICY:
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
45 # }}} END BPS TAGGED BLOCK
52 use vars qw($VERSION $System $SystemUser $Nobody $Handle $Logger
63 $MasonLocalComponentRoot
68 $VERSION = '@RT_VERSION_MAJOR@.@RT_VERSION_MINOR@.@RT_VERSION_PATCH@';
69 $CORE_CONFIG_FILE = "@CONFIG_FILE_PATH@/RT_Config.pm";
70 $SITE_CONFIG_FILE = "@CONFIG_FILE_PATH@/RT_SiteConfig.pm";
74 $BasePath = '@RT_PATH@';
76 $EtcPath = '@RT_ETC_PATH@';
77 $VarPath = '@RT_VAR_PATH@';
78 $LocalPath = '@RT_LOCAL_PATH@';
79 $LocalEtcPath = '@LOCAL_ETC_PATH@';
80 $LocalLexiconPath = '@LOCAL_LEXICON_PATH@';
82 # $MasonComponentRoot is where your rt instance keeps its mason html files
84 $MasonComponentRoot = '@MASON_HTML_PATH@';
86 # $MasonLocalComponentRoot is where your rt instance keeps its site-local
89 $MasonLocalComponentRoot = '@MASON_LOCAL_HTML_PATH@';
91 # $MasonDataDir Where mason keeps its datafiles
93 $MasonDataDir = '@MASON_DATA_PATH@';
95 # RT needs to put session data (for preserving state between connections
96 # via the web interface)
97 $MasonSessionDir = '@MASON_SESSION_PATH@';
107 A fully featured request tracker package
116 Load RT's config file. First, go after the core config file.
117 After that, go after the site config.
122 local *Set = sub { $_[0] = $_[1] unless defined $_[0] };
123 if ( -f "$SITE_CONFIG_FILE" ) {
124 require $SITE_CONFIG_FILE
125 || die ("Couldn't load RT config file '$SITE_CONFIG_FILE'\n$@");
127 require $CORE_CONFIG_FILE
128 || die ("Couldn't load RT config file '$CORE_CONFIG_FILE'\n$@");
134 Conenct to the database, set up logging.
140 #Get a database connection
143 #RT's system user is a genuine database user. its id lives here
144 $SystemUser = new RT::CurrentUser();
145 $SystemUser->LoadByName('RT_System');
147 #RT's "nobody user" is a genuine database user. its ID lives here.
148 $Nobody = new RT::CurrentUser();
149 $Nobody->LoadByName('Nobody');
151 $System = RT::System->new();
157 =head2 ConnectToDatabase
159 Get a database connection
163 sub ConnectToDatabase {
165 unless ($Handle && $Handle->dbh && $Handle->dbh->ping) {
166 $Handle = RT::Handle->new();
173 Create the RT::Logger object.
178 # We have to set the record seperator ($, man perlvar)
179 # or Log::Dispatch starts getting
180 # really pissy, as some other module we use unsets it.
183 use Log::Dispatch 1.6;
185 unless ($RT::Logger) {
187 $RT::Logger=Log::Dispatch->new();
189 if ($RT::LogToFile) {
190 my ($filename, $logdir);
191 if ($RT::LogToFileNamed =~ m![/\\]!) {
192 # looks like an absolute path.
193 $filename = $RT::LogToFileNamed;
194 ($logdir) = $RT::LogToFileNamed =~ m!^(.*[/\\])!;
197 $filename = "$RT::LogDir/$RT::LogToFileNamed";
198 $logdir = $RT::LogDir;
201 unless ( -d $logdir && ( ( -f $filename && -w $filename ) || -w $logdir ) ) {
202 # localizing here would be hard when we don't have a current user yet
203 # die $self->loc("Log directory [_1] not found or couldn't be written.\n RT can't run.", $RT::LogDir);
204 die ("Log file $filename couldn't be written or created.\n RT can't run.");
207 require Log::Dispatch::File;
210 $RT::Logger->add(Log::Dispatch::File->new
212 min_level=> $RT::LogToFile,
213 filename=> $filename,
215 callbacks => sub { my %p = @_;
216 my ($package, $filename, $line) = caller(5);
217 return "[".gmtime(time)."] [".$p{level}."]: $p{message} ($filename:$line)\n"}
223 if ($RT::LogToScreen) {
224 require Log::Dispatch::Screen;
225 $RT::Logger->add(Log::Dispatch::Screen->new
227 min_level => $RT::LogToScreen,
228 callbacks => sub { my %p = @_;
229 my ($package, $filename, $line) = caller(5);
230 return "[".gmtime(time)."] [".$p{level}."]: $p{message} ($filename:$line)\n"
236 if ($RT::LogToSyslog) {
237 require Log::Dispatch::Syslog;
238 $RT::Logger->add(Log::Dispatch::Syslog->new
241 min_level => $RT::LogToSyslog,
242 callbacks => sub { my %p = @_;
243 my ($package, $filename, $line) = caller(5);
245 # syswrite() cannot take utf8; turn it off here.
246 Encode::_utf8_off($p{message});
248 if ($p{level} eq 'debug') {
250 return "$p{message}\n" }
252 return "$p{message} ($filename:$line)\n"}
262 # {{{ Signal handlers
264 ## This is the default handling of warnings and die'ings in the code
265 ## (including other used modules - maybe except for errors catched by
266 ## Mason). It will log all problems through the standard logging
267 ## mechanism (see above).
269 $SIG{__WARN__} = sub {$RT::Logger->warning($_[0])};
271 #When we call die, trap it and log->crit with the value of the die.
273 $SIG{__DIE__} = sub {
274 unless ($^S || !defined $^S ) {
275 $RT::Handle->Rollback();
276 $RT::Logger->crit("$_[0]");
280 #Get out of here if we're in an eval
305 Please report them to rt-bugs@fsck.com, if you know what's broken and have at least
306 some idea of what needs to be fixed.
308 If you're not sure what's going on, report them rt-devel@lists.bestpractical.com.
313 L<DBIx::SearchBuilder>
320 ok ($RT::Nobody->Name() eq 'Nobody', "Nobody is nobody");
321 ok ($RT::Nobody->Name() ne 'root', "Nobody isn't named root");
322 ok ($RT::SystemUser->Name() eq 'RT_System', "The system user is RT_System");
323 ok ($RT::SystemUser->Name() ne 'noname', "The system user isn't noname");
330 eval "require RT_Local";
331 die $@ if ($@ && $@ !~ qr{^Can't locate RT_Local.pm});