import rt 3.8.7
[freeside.git] / rt / share / html / Install / DatabaseDetails.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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 if ( $db_type eq 'Pg' ) {
109     push @Types, 'DatabaseRequireSSL';
110 }
111
112
113 if ( $Run ) {
114
115     if ( $Back ) {
116         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
117 'Install/DatabaseType.html');
118     }
119     
120     if ( $ARGS{Next} ) {
121         RT::Interface::Web::Redirect(RT->Config->Get('WebURL') .
122 'Install/Basics.html');
123     }
124
125     $m->comp('/Widgets/BulkProcess', Types => \@Types, Arguments => \%ARGS, 
126             Store => $RT::Installer->{InstallConfig}, 
127             Meta => $RT::Installer->{Meta}, KeepUndef => 1 ); 
128
129
130     my ( $status, $msg ) = RT::Installer->SaveConfig;
131     if ( $status ) {
132         delete $INC{'RT_SiteConfig.pm'};
133         RT->LoadConfig;
134         RT::Handle->FinalizeDatabaseType();
135     # dba connect systemdsn
136         my $dbh = DBI->connect(
137             RT::Handle->SystemDSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
138         );
139     
140         if ( $dbh ) {
141             push @results, loc('Connection succeeded');
142             # dba connect dsn, which has table info
143             $dbh = DBI->connect(
144                 RT::Handle->DSN, $ARGS{DatabaseAdmin}, $ARGS{DatabaseAdminPassword}, { RaiseError => 0, PrintError => 0 },
145             );
146     
147             if ( $dbh ) {
148                 # check if table Users exists
149                 eval {
150                     my $dbh = DBI->connect(
151                         RT::Handle->DSN,
152                         $ARGS{DatabaseAdmin},
153                         $ARGS{DatabaseAdminPassword},
154                         { RaiseError => 1, PrintError => 0 },
155                     );
156
157                     my $sth = $dbh->prepare('select * from Users');
158                 };
159
160                 unless ( $@ ) {
161     
162                     my $sth = $dbh->prepare('select id from Users where Name=?');
163                     $sth->execute('RT_System'); 
164                     if ( $sth->fetchrow_array ) {
165                         $RT::Installer->{DatabaseAction} = 'none';
166                         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);
167                     }
168                     else {
169                         $RT::Installer->{DatabaseAction} = 'acl,coredata,insert';
170                         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);
171                     }
172                 }
173                 else {
174                     $RT::Installer->{DatabaseAction} = 'schema,acl,coredata,insert';
175                     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 );
176                 }
177
178             }
179             else {
180                 $RT::Installer->{DatabaseAction} =
181     'create,schema,acl,coredata,insert';
182             }
183         }
184         else {
185             $RT::Installer->{DatabaseAction} = 'error';
186             push @errors, loc("Failed to connect to database: [_1]",
187                     $DBI::errstr );
188         }
189     }
190     else {
191         push @results, loc($msg);
192     }
193
194 }
195
196 </%init>
197
198 <%args>
199 $Run => undef
200 $Back => undef
201 </%args>