rt 4.2.14 (#13852)
[freeside.git] / rt / lib / RT / Installer.pm
index 0cf4d01..372c33d 100644 (file)
@@ -2,7 +2,7 @@
 #
 # COPYRIGHT:
 #
-# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
 #                                          <sales@bestpractical.com>
 #
 # (Except where explicitly superseded by other copyright notices)
@@ -50,6 +50,8 @@ package RT::Installer;
 use strict;
 use warnings;
 
+use DateTime;
+
 require UNIVERSAL::require;
 my %Meta = (
     DatabaseType => {
@@ -95,6 +97,7 @@ my %Meta = (
         },
     },
     DatabaseAdmin => {
+        SkipWrite       => 1,
         Widget          => '/Widgets/Form/String',
         WidgetArguments => {
             Default => 1,
@@ -104,6 +107,7 @@ my %Meta = (
         },
     },
     DatabaseAdminPassword => {
+        SkipWrite       => 1,
         Widget          => '/Widgets/Form/String',
         WidgetArguments => {
             Description => 'DBA password',  #loc
@@ -127,12 +131,6 @@ my %Meta = (
             Hints       => 'The password RT should use to connect to the database.',
         },
     },
-    DatabaseRequireSSL => {
-        Widget          => '/Widgets/Form/Boolean',
-        WidgetArguments => {
-            Description => 'Use SSL?',    # loc
-        },
-    },
     rtname => {
         Widget          => '/Widgets/Form/String',
         WidgetArguments => {
@@ -147,6 +145,7 @@ my %Meta = (
         },
     },
     Password => {
+        SkipWrite       => 1,
         Widget          => '/Widgets/Form/String',
         WidgetArguments => {
             Description => 'Administrative password', #loc
@@ -184,27 +183,7 @@ my %Meta = (
             Description => 'Path to sendmail', #loc
         },
     },
-    WebDomain => {
-        Widget          => '/Widgets/Form/String',
-        WidgetArguments => {
-            Description => 'Domain name',                  #loc
-            Hints => "Don't include http://, just something like 'localhost', 'rt.example.com'", #loc
-        },
-    },
-    WebPort => {
-        Widget          => '/Widgets/Form/Integer',
-        WidgetArguments => {
-            Description => 'Web port',                     #loc
-            Hints => 'which port your web server will listen to, e.g. 8080', #loc
-        },
-    },
-
-);
-
-my $HAS_DATETIME_TZ = eval { require DateTime::TimeZone };
-
-if ($HAS_DATETIME_TZ) {
-    $Meta{Timezone} = {
+    Timezone => {
         Widget          => '/Widgets/Form/Select',
         WidgetArguments => {
             Description => 'Timezone',                              #loc
@@ -212,30 +191,34 @@ if ($HAS_DATETIME_TZ) {
                 my $ret;
                 $ret->{Values} = ['', DateTime::TimeZone->all_names];
 
-                my $has_datetime = eval { require DateTime };
-                if ( $has_datetime ) {
-                    my $dt = DateTime->now;
-                    for my $tz ( DateTime::TimeZone->all_names ) {
-                        $dt->set_time_zone( $tz );
-                        $ret->{ValuesLabel}{$tz} =
-                            $tz . ' ' . $dt->strftime('%z');
-                    }
+                my $dt = DateTime->now;
+                for my $tz ( DateTime::TimeZone->all_names ) {
+                    $dt->set_time_zone( $tz );
+                    $ret->{ValuesLabel}{$tz} =
+                        $tz . ' ' . $dt->strftime('%z');
                 }
                 $ret->{ValuesLabel}{''} = 'System Default'; #loc
 
                 return $ret;
             },
         },
-    };
-}
-else {
-    $Meta{Timezone} = {
+    },
+    WebDomain => {
         Widget          => '/Widgets/Form/String',
         WidgetArguments => {
-            Description => 'Timezone',                              #loc
+            Description => 'Domain name',                  #loc
+            Hints => "Don't include http://, just something like 'localhost', 'rt.example.com'", #loc
         },
-    };
-}
+    },
+    WebPort => {
+        Widget          => '/Widgets/Form/Integer',
+        WidgetArguments => {
+            Description => 'Web port',                     #loc
+            Hints => 'which port your web server will listen to, e.g. 8080', #loc
+        },
+    },
+
+);
 
 sub Meta {
     my $class = shift;
@@ -266,7 +249,7 @@ sub CurrentValues {
 
 sub ConfigFile {
     require File::Spec;
-    return File::Spec->catfile( $RT::EtcPath, 'RT_SiteConfig.pm' );
+    return $ENV{RT_SITE_CONFIG} || File::Spec->catfile( $RT::EtcPath, 'RT_SiteConfig.pm' );
 }
 
 sub SaveConfig {
@@ -288,10 +271,10 @@ sub SaveConfig {
       $RT::Installer->{InstallConfig}{rtname};
 
     if ( open my $fh, '>', $file ) {
-        for ( keys %{ $RT::Installer->{InstallConfig} } ) {
+        for ( sort keys %{ $RT::Installer->{InstallConfig} } ) {
 
             # we don't want to store root's password in config.
-            next if $_ eq 'Password';
+            next if $class->Meta($_) and $class->Meta($_)->{SkipWrite};
 
             $RT::Installer->{InstallConfig}{$_} = ''
               unless defined $RT::Installer->{InstallConfig}{$_};
@@ -299,7 +282,9 @@ sub SaveConfig {
             # remove obsolete settings we'll add later
             $content =~ s/^\s* Set \s* \( \s* \$$_ .*$//xm;
 
-            $content .= "Set( \$$_, '$RT::Installer->{InstallConfig}{$_}' );\n";
+            my $value = $RT::Installer->{InstallConfig}{$_};
+            $value =~ s/(['\\])/\\$1/g;
+            $content .= "Set( \$$_, '$value' );\n";
         }
         $content .= "1;\n";
         print $fh $content;