Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / htetc / handler.pl
index 77b9346..3c68e83 100644 (file)
@@ -7,6 +7,23 @@ use warnings;
 use FS::Mason qw( mason_interps );
 use FS::Trace;
 
+if ( %%%RT_ENABLED%%% ) {
+
+  require RT;
+
+  $> = scalar(getpwnam('freeside'));
+
+  RT::LoadConfig();
+  RT::Init();
+
+  # disconnect DB before fork:
+  #   (avoid 'prepared statement "dbdpg_p\d+_\d+" already exists' errors?)
+  $RT::Handle->dbh(undef);
+  undef $RT::Handle;
+
+  $> = $<;
+}
+
 #use vars qw($r);
 
 # Bring in ApacheHandler, necessary for mod_perl integration.
@@ -141,7 +158,9 @@ sub handler
 
     FS::Trace->log('done');
 
-    FS::Trace->dumpfile("%%%FREESIDE_EXPORT%%%/profile/$$.".time, $r->filename)
+    FS::Trace->dumpfile( "%%%FREESIDE_EXPORT%%%/profile/$$.".time,
+                         FS::Trace->total. ' '. $r->filename
+                       )
       if FS::Trace->total > 5; #10?
 
     FS::Trace->reset;
@@ -149,19 +168,10 @@ sub handler
     $status;
 }
 
-my $rt_initialized = 0;
-
 sub my_rt_init {
   return unless $RT::VERSION;
-
-  if ( $rt_initialized ) {
-    RT::ConnectToDatabase();
-    RT::InitSignalHandlers();
-  } else {
-    RT::LoadConfig();
-    RT::Init();
-    $rt_initialized++;
-  }
+  RT::ConnectToDatabase();
+  RT::InitSignalHandlers();
 }
 
 1;