rt 4.2.16
[freeside.git] / rt / share / html / Install / DatabaseDetails.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
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
16 %# from www.gnu.org.
17 %#
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.
22 %#
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., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <&| Elements/Wrapper, Title => loc('Step [_1] of [_2]', 2, 7 ) .': '. loc('Check Database Credentials') &> 
49
50 % if ( @errors ) {
51 <& Elements/Errors, Errors => \@errors &>
52 <p>
53 <&|/l&>Tell us a little about how to find the database RT will be using</&>
54 <p>
55 <&|/l&>We need to know the name of the database RT will use and where to find it.  We also need to know the username and password of the user RT should use. RT can create the database and user for you, which is why we ask for the username and password of a user with DBA privileges.  During step 6 of the installation process we will use this information to create and initialize RT's database.</&>
56 </p>
57 <p>
58 <&|/l&>When you click on 'Check Database Connectivity' there may be a small delay while RT tries to connect to your database</&>
59
60 % } elsif ( @results ) {
61 <& /Elements/ListActions, actions => \@results &>
62
63 <p>
64 <&|/l&>We are able to find your database and connect as the DBA.  You can click on 'Customize Basics' to continue customizing RT.</&>
65
66 % }
67
68 <form method="post">
69 <input type="hidden" name="Run" value="1">
70 % if ( @results && !@errors ) {
71 <& /Elements/Submit,
72     Label => loc('Next') .': '. loc('Customize Basics'),
73     Back => 1, BackLabel => loc('Back') .': '. loc('Select Database Type'),
74     Name => 'Next',
75 &>
76 % } else {
77 <& /Widgets/BulkEdit, Types => \@Types, Meta => $RT::Installer->{Meta},
78     CurrentValue => { %{RT::Installer->CurrentValues(@Types)},
79         DatabaseAdmin =>
80             RT::Installer->CurrentValue( 'DatabaseAdmin' ) ||
81             $RT::Installer->{InstallConfig}{DatabaseAdmin} ||
82             ( $db_type eq 'mysql' ? 'root'
83               : $db_type eq 'Pg' ? 'postgres'
84               : '' ),
85         }
86                     &>
87 <& /Elements/Submit,
88     Label => loc('Check Database Connectivity'),
89     Back => 1, BackLabel => loc('Back') .': '. loc('Choose Database Engine'),
90 &>
91 % }
92
93 </form>
94 </&>
95
96 <%init>
97 my (@results, @errors);
98 my $ConnectionSucceeded;
99
100 my @Types = 'DatabaseName';
101
102 my $db_type = $RT::Installer->{InstallConfig}{DatabaseType};
103
104 unless ( $db_type eq 'SQLite' ) {
105     push @Types, 'DatabaseHost', 'DatabasePort', 'DatabaseAdmin',
106         'DatabaseAdminPassword', 'DatabaseUser', 'DatabasePassword';
107 }
108
109
110 if ( $Run ) {
111
112     if ( $Back ) {
113         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
114 'Install/DatabaseType.html');
115     }
116     
117     if ( $ARGS{Next} ) {
118         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
119 'Install/Basics.html');
120     }
121
122     $m->comp('/Widgets/BulkProcess', Types => \@Types, Arguments => \%ARGS, 
123             Store => $RT::Installer->{InstallConfig}, 
124             Meta => $RT::Installer->{Meta}, KeepUndef => 1 ); 
125
126
127     my ( $status, $msg ) = RT::Installer->SaveConfig;
128     if ( $status ) {
129         RT->LoadConfig;
130         RT::Handle->FinalizeDatabaseType();
131     # dba connect systemdsn
132         my $dbh = DBI->connect(
133             RT::Handle->SystemDSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
134         );
135     
136         if ( $dbh ) {
137             push @results, loc('Connection succeeded');
138             # dba connect dsn, which has table info
139             $dbh = DBI->connect(
140                 RT::Handle->DSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
141             );
142
143             if ( $dbh and $db_type eq "Oracle") {
144                 # The database _existing_ is itself insufficient for Oracle -- we need to check for the RT user
145                 my $sth = $dbh->prepare('SELECT username FROM dba_users WHERE username = ?');
146                 $sth->execute( $ARGS{DatabaseUser} );
147                 undef $dbh unless $sth->fetchrow_array;
148
149                 push @errors, loc("Oracle users cannot have empty passwords")
150                     unless $ARGS{DatabasePassword};
151             }
152
153             if ( $dbh ) {
154                 # check if table Users exists
155                 eval {
156                     my $dbh = DBI->connect(
157                         RT::Handle->DSN,
158                         $ARGS{DatabaseAdmin},
159                         $ARGS{DatabaseAdminPassword},
160                         { RaiseError => 1, PrintError => 0 },
161                     );
162
163                     my $sth = $dbh->prepare('select * from Users');
164                     $sth->execute();
165                 };
166
167                 unless ( $@ ) {
168     
169                     my $sth = $dbh->prepare('select id from Users where Name=?');
170                     $sth->execute('RT_System'); 
171                     if ( $sth->fetchrow_array ) {
172                         $RT::Installer->{DatabaseAction} = 'none';
173                         push @results, loc("[_1] appears to be fully initialized.  We won't need to create any tables or insert metadata, but you can continue to customize RT by clicking 'Customize Basics' below", $RT::DatabaseName);
174                     }
175                     else {
176                         $RT::Installer->{DatabaseAction} = 'acl,coredata,insert';
177                         push @results, loc("[_1] already exists and has RT's tables in place, but does not contain RT's metadata. The 'Initialize Database' step later on can insert metadata into this existing database. If this is acceptable, click 'Customize Basics' below to continue customizing RT.", $RT::DatabaseName);
178                     }
179                 }
180                 else {
181                     $RT::Installer->{DatabaseAction} = 'schema,acl,coredata,insert';
182                     push @results, loc("[_1] already exists, but does not contain RT's tables or metadata. The 'Initialize Database' step later on can insert tables and metadata into this existing database. if this is acceptable, click 'Customize Basic' below to continue customizing RT.", $RT::DatabaseName );
183                 }
184
185             }
186             else {
187                 $RT::Installer->{DatabaseAction} =
188     'create,schema,acl,coredata,insert';
189             }
190         }
191         else {
192             $RT::Installer->{DatabaseAction} = 'error';
193             push @errors, loc("Failed to connect to database: [_1]",
194                     $DBI::errstr );
195         }
196     }
197     else {
198         push @results, loc($msg);
199     }
200
201 }
202
203 </%init>
204
205 <%args>
206 $Run => undef
207 $Back => undef
208 </%args>