Merge branch 'patch-1' of https://github.com/gjones2/Freeside
[freeside.git] / rt / lib / RT.pm
index ec2e6cc..4372a56 100644 (file)
@@ -319,6 +319,7 @@ sub InitLogging {
 sub InitSignalHandlers {
 
     my %arg = @_;
+    return if $arg{'NoSignalHandlers'};
 
 # Signal handlers
 ## This is the default handling of warnings and die'ings in the code
@@ -326,32 +327,28 @@ sub InitSignalHandlers {
 ## Mason).  It will log all problems through the standard logging
 ## mechanism (see above).
 
-    unless ( $arg{'NoSignalHandlers'} ) {
-
-        $SIG{__WARN__} = sub {
-            # The 'wide character' warnings has to be silenced for now, at least
-            # until HTML::Mason offers a sane way to process both raw output and
-            # unicode strings.
-            # use 'goto &foo' syntax to hide ANON sub from stack
-            if( index($_[0], 'Wide character in ') != 0 ) {
-                unshift @_, $RT::Logger, qw(level warning message);
-                goto &Log::Dispatch::log;
-            }
-        };
-
-        #When we call die, trap it and log->crit with the value of the die.
+    $SIG{__WARN__} = sub {
+        # The 'wide character' warnings has to be silenced for now, at least
+        # until HTML::Mason offers a sane way to process both raw output and
+        # unicode strings.
+        # use 'goto &foo' syntax to hide ANON sub from stack
+        if( index($_[0], 'Wide character in ') != 0 ) {
+            unshift @_, $RT::Logger, qw(level warning message);
+            goto &Log::Dispatch::log;
+        }
+    };
 
-        $SIG{__DIE__}  = sub {
-            # if we are not in eval and perl is not parsing code
-            # then rollback transactions and log RT error
-            unless ($^S || !defined $^S ) {
-                $RT::Handle->Rollback(1) if $RT::Handle;
-                $RT::Logger->crit("$_[0]") if $RT::Logger;
-            }
-            die $_[0];
-        };
+#When we call die, trap it and log->crit with the value of the die.
 
-    }
+    $SIG{__DIE__}  = sub {
+        # if we are not in eval and perl is not parsing code
+        # then rollback transactions and log RT error
+        unless ($^S || !defined $^S ) {
+            $RT::Handle->Rollback(1) if $RT::Handle;
+            $RT::Logger->crit("$_[0]") if $RT::Logger;
+        }
+        die $_[0];
+    };
 }
 
 
@@ -425,6 +422,7 @@ sub InitClasses {
     require RT::Approval;
     require RT::Lifecycle;
     require RT::Link;
+    require RT::Links;
     require RT::Article;
     require RT::Articles;
     require RT::Class;
@@ -688,11 +686,21 @@ sub InitPlugins {
 sub InstallMode {
     my $self = shift;
     if (@_) {
-         $_INSTALL_MODE = shift;
-         if($_INSTALL_MODE) {
-             require RT::CurrentUser;
-            $SystemUser = RT::CurrentUser->new();
-         }
+        my ($integrity, $state, $msg) = RT::Handle->CheckIntegrity;
+        if ($_[0] and $integrity) {
+            # Trying to turn install mode on but we have a good DB!
+            require Carp;
+            $RT::Logger->error(
+                Carp::longmess("Something tried to turn on InstallMode but we have DB integrity!")
+            );
+        }
+        else {
+            $_INSTALL_MODE = shift;
+            if($_INSTALL_MODE) {
+                require RT::CurrentUser;
+               $SystemUser = RT::CurrentUser->new();
+            }
+        }
     }
     return $_INSTALL_MODE;
 }
@@ -745,7 +753,7 @@ sub CanonicalizeGeneratedPaths {
 =head2 AddJavaScript
 
 helper method to add js files to C<JSFiles> config.
-to add extra css files, you can add the following line
+to add extra js files, you can add the following line
 in the plugin's main file:
 
     RT->AddJavaScript( 'foo.js', 'bar.js' );