beginning of RT integration
authorivan <ivan>
Thu, 8 Apr 2004 12:00:05 +0000 (12:00 +0000)
committerivan <ivan>
Thu, 8 Apr 2004 12:00:05 +0000 (12:00 +0000)
Makefile
htetc/handler.pl
rt/FREESIDE_MODIFIED
rt/etc/RT_SiteConfig.pm
rt/sbin/rt-setup-database
rt/sbin/rt-setup-database.in

index e5ef70d..70e5882 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -56,10 +56,18 @@ SELFSERVICE_USER = fs_selfservice
 SELFSERVICE_MACHINES = localhost
 # SELFSERVICE_MACHINES = web1.example.com web2.example.com
 
+#RT_ENABLED = 0
+RT_ENABLED = 1
+RT_DOMAIN = example.com
+RT_TIMEZONE = 'US/Pacific';
+#RT_TIMEZONE = 'US/Eastern';
+
 #---
 
 #not changable yet
 FREESIDE_CONF = /usr/local/etc/freeside
+#rt/config.layout.in
+RT_PATH = /opt/rt3
 
 VERSION=1.5.0pre4
 TAG=freeside_1_5_0pre4
@@ -125,6 +133,7 @@ install-docs: docs
        [ "${TEMPLATE}" = "mason" ] && \
          perl -p -i -e "\
            s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g; \
+           s'%%%RT_ENABLED%%%'${RT_ENABLED}'g; \
          " ${MASON_HANDLER} || true
        [ "${TEMPLATE}" = "mason" -a ! -e ${MASONDATA} ] && mkdir ${MASONDATA} || true
        [ "${TEMPLATE}" = "mason" ] && chown -R freeside ${MASONDATA} || true
@@ -148,7 +157,7 @@ install-init:
          s/%%%SELFSERVICE_MACHINES%%%/${SELFSERVICE_MACHINES}/g;\
        " ${INIT_FILE}
 
-install: install-perl-modules install-docs install-init
+install: install-perl-modules install-docs install-init install-rt
 
 deploy: install
        ${HTTPD_RESTART}
@@ -191,20 +200,35 @@ configure-rt:
          s'%%%FREESIDE_DOCUMENT_ROOT%%%'${FREESIDE_DOCUMENT_ROOT}'g;\
          s'%%%MASONDATA%%%'${MASONDATA}'g;\
        " config.layout; \
-       ./configure --with-layout=Freeside\
+       ./configure --enable-layout=Freeside\
                    --with-db-type=Pg \
+                   --with-db-dba=${DB_USER} \
                    --with-db-database=freeside \
                    --with-db-rt-user=${DB_USER} \
                    --with-db-rt-pass=${DB_PASSWORD} \
                    --with-web-user=freeside \
-                   --with-web-group=www
+                   --with-web-group=freeside \
+                   --with-rt-group=freeside
 
 create-rt: configure-rt
        cd rt; make install
-       rt/sbin/rt-setup-database --action schema
-       rt/sbin/rt-setup-database --action insert_initial
-       rt/sbin/rt-setup-database --action insert --datafile rt/etc/initialdata
+       echo -e "${DB_PASSWORD}\n\\d sessions"\
+        | psql -UW ${DB_USER} freeside 2>&1\
+        | grep '^Did not find'\
+        && rt/sbin/rt-setup-database --dba '${DB_USER}' \
+                                    --dba-password '${DB_PASSWORD}' \
+                                    --action schema \
+        || true
+       rt/sbin/rt-setup-database --action insert_initial \
+       && rt/sbin/rt-setup-database --action insert --datafile ${RT_PATH}/etc/initialdata \
+       || true
+       perl -p -i -e "\
+         s'%%%RT_DOMAIN%%%'${RT_DOMAIN}'g;\
+         s'%%%RT_TIMEZONE%%%'${RT_TIMEZONE}'g;\
+       " ${RT_PATH}/etc/RT_SiteConfig.pm
 
+install-rt:
+       [ ${RT_ENABLED} ] && cd rt; make install
 
 clean:
        rm -rf aspdocs masondocs
index b81606a..d425c22 100644 (file)
@@ -35,12 +35,37 @@ use strict;
 #                                      data_dir=>'/usr/local/etc/freeside/masondata',
 #                                      out_mode=>'stream',
 #                                     );
+
+use vars qw($r);
+
+if ( %%%RT_ENABLED%%% ) {
+ eval '
+   use lib ("/opt/rt3/local/lib", "/opt/rt3/lib");
+   use RT;
+   use vars qw($Nobody $SystemUser);
+   RT::LoadConfig();
+ ';
+ die $@ if $@;
+
+
+}
+
+
 my $ah = new HTML::Mason::ApacheHandler (
   #interp => $interp,
   #auto_send_headers => 0,
-  comp_root=>'%%%FREESIDE_DOCUMENT_ROOT%%%',
+  comp_root=> [
+                [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%'    ],
+                [ 'rt'       => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
+              ],
   data_dir=>'/usr/local/etc/freeside/masondata',
   #out_mode=>'stream',
+
+  #RT
+  args_method => 'CGI',
+  default_escape_flags => 'h',
+  allow_globals => [qw(%session)],
+  #autoflush => 1,
 );
 
 # Activate the following if running httpd as root (the normal case).
@@ -50,7 +75,7 @@ my $ah = new HTML::Mason::ApacheHandler (
 
 sub handler
 {
-    my ($r) = @_;
+    ($r) = @_;
 
     # If you plan to intermix images in the same directory as
     # components, activate the following to prevent Mason from
@@ -62,7 +87,8 @@ sub handler
     { package HTML::Mason::Commands;
       use strict;
       use vars qw( $cgi $p );
-      use CGI 2.47;
+      use vars qw( %session );
+      use CGI 2.47 qw(-private_tempfiles);
       #use CGI::Carp qw(fatalsToBrowser);
       use Date::Format;
       use Date::Parse;
@@ -125,6 +151,32 @@ sub handler
       use FS::export_svc;
       use FS::msgcat;
 
+      if ( %%%RT_ENABLED%%% ) {
+        eval '
+          use RT::Tickets;
+          use RT::Transactions;
+          use RT::Users;
+          use RT::CurrentUser;
+          use RT::Templates;
+          use RT::Queues;
+          use RT::ScripActions;
+          use RT::ScripConditions;
+          use RT::Scrips;
+          use RT::Groups;
+          use RT::GroupMembers;
+          use RT::CustomFields;
+          use RT::CustomFieldValues;
+          use RT::TicketCustomFieldValues;
+      
+          use RT::Interface::Web;
+          use MIME::Entity;
+          use Text::Wrapper;
+          use CGI::Cookie;
+          use Time::ParseDate;
+        ';
+        die $@ if $@;
+      }
+
       *CGI::redirect = sub {
         my( $self, $location ) = @_;
         use vars qw($m);
@@ -205,7 +257,43 @@ sub handler
 
 #    $r->send_http_header;
 
-    my $status = $ah->handle_request($r);
+    #$ah->interp->remove_escape('h');
+
+    if ( $r->filename =~ /\/rt\// ) { #RT
+      #warn "processing RT file". $r->filename. "; escaping for RT\n";
+
+      # MasonX::Request::ExtendedCompRoot
+      #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
+
+      $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
+
+      local $SIG{__WARN__};
+      local $SIG{__DIE__};
+
+      RT::Init();
+
+      # We don't need to handle non-text items
+      return -1 if defined( $r->content_type ) && $r->content_type !~ m|^text/|io;
+
+    } else {
+      $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
+    }
+
+    my %session;
+    my $status;
+    eval { $status = $ah->handle_request($r); };
+#!!
+#    if ( $@ ) {
+#      $RT::Logger->crit($@);
+#    }
+
+    undef %session;
+
+#!!
+#    if ($RT::Handle->TransactionDepth) {
+#      $RT::Handle->ForceRollback;
+#      $RT::Logger->crit("Transaction not committed. Usually indicates a software fault. Data loss may have occurred") ;
+#    }
 
     $status;
 }
index cab7db3..84a9f5e 100644 (file)
@@ -1,3 +1,5 @@
 sbin/rt-setup-database
+sbin/rt-setup-database.in
 config.layout
 config.layout.in
+etc/RT_SiteConfig.pm
index 0afc604..572a2ba 100644 (file)
@@ -1 +1,13 @@
+$RT::rtname = '%%%RT_DOMAIN%%%';
+$RT::Organization = '%%%RT_DOMAIN%%%';
+
+$RT::Timezone = '%%%RT_TIMEZONE%%%';
+
+$RT::WebBaseURL = '';
+$RT::WebPath = '/freeside/rt';
+
+$RT::WebExternalAuth = 1;
+$RT::WebFallbackToInternal = 1; #no
+$RT::WebExternalAuto = 1;
+
 1;
index 83e0827..434e686 100644 (file)
@@ -592,6 +592,10 @@ $0: Set up RT's database
 --action        init    Initialize the database
                 drop    Drop the database. 
                         This will ERASE ALL YOUR DATA
+                insert_initial 
+                        Insert RT's core system objects
+                insert_initial 
+                        Insert RT's core system objects
                 insert  Insert data into RT's database. 
                         By default, will use RT's installation data.
                         To use a local or supplementary datafile, specify it
index 9e990e5..f37c69d 100644 (file)
@@ -110,6 +110,9 @@ elsif ( $args{'action'} eq 'drop' ) {
     }
     drop_db();
 }
+elsif ( $args{'action'} eq 'insert_initial' ) {
+    insert_initial_data();
+}
 elsif ( $args{'action'} eq 'insert' ) {
     insert_data( $args{'datafile'} );
 }
@@ -589,6 +592,10 @@ $0: Set up RT's database
 --action        init    Initialize the database
                 drop    Drop the database. 
                         This will ERASE ALL YOUR DATA
+                insert_initial 
+                        Insert RT's core system objects
+                insert_initial 
+                        Insert RT's core system objects
                 insert  Insert data into RT's database. 
                         By default, will use RT's installation data.
                         To use a local or supplementary datafile, specify it