]> git.agnieray.net Git - galette.git/blob - galette/install/steps/db_checks.php
Fix display issue on connection failure
[galette.git] / galette / install / steps / db_checks.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette installation, database checks step
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Core
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.8 - 2013-01-11
35 */
36
37 use Galette\Core\Install as GaletteInstall;
38 use Galette\Core\Db as GaletteDb;
39
40 try {
41 $db_connected = $install->testDbConnexion();
42 } catch (Throwable $e) {
43 $db_connected = $e;
44 }
45 $conndb_ok = true;
46 $permsdb_ok = true;
47
48 if (!isset($show_form)) {
49 $show_form = true;
50 }
51
52 if ($db_connected === true) {
53 if (!isset($zdb)) {
54 $zdb = new GaletteDb();
55 }
56
57 /** FIXME: when tables already exists and DROP not allowed at this time
58 the showed error is about CREATE, whenever CREATE is allowed */
59 //We delete the table if exists, no error at this time
60 $zdb->dropTestTable();
61
62 $results = $zdb->grantCheck($install->getMode());
63
64 $result = array();
65 $error = false;
66
67 //test returned values
68 if ($results['create'] instanceof Exception) {
69 $result[] = array(
70 'message' => _T("CREATE operation not allowed"),
71 'debug' => $results['create']->getMessage(),
72 'res' => false
73 );
74 $error = true;
75 } elseif ($results['create'] != '') {
76 $result[] = array(
77 'message' => _T("CREATE operation allowed"),
78 'res' => true
79 );
80 }
81
82 if ($results['insert'] instanceof Exception) {
83 $result[] = array(
84 'message' => _T("INSERT operation not allowed"),
85 'debug' => $results['insert']->getMessage(),
86 'res' => false
87 );
88 $error = true;
89 } elseif ($results['insert'] != '') {
90 $result[] = array(
91 'message' => _T("INSERT operation allowed"),
92 'res' => true
93 );
94 }
95
96 if ($results['update'] instanceof Exception) {
97 $result[] = array(
98 'message' => _T("UPDATE operation not allowed"),
99 'debug' => $results['update']->getMessage(),
100 'res' => false
101 );
102 $error = true;
103 } elseif ($results['update'] != '') {
104 $result[] = array(
105 'message' => _T("UPDATE operation allowed"),
106 'res' => true
107 );
108 }
109
110 if ($results['select'] instanceof Exception) {
111 $result[] = array(
112 'message' => _T("SELECT operation not allowed"),
113 'debug' => $results['select']->getMessage(),
114 'res' => false
115 );
116 $error = true;
117 } elseif ($results['select'] != '') {
118 $result[] = array(
119 'message' => _T("SELECT operation allowed"),
120 'res' => true
121 );
122 }
123
124 if ($results['delete'] instanceof Exception) {
125 $result[] = array(
126 'message' => _T("DELETE operation not allowed"),
127 'debug' => $results['delete']->getMessage(),
128 'res' => false
129 );
130 $error = true;
131 } elseif ($results['delete'] != '') {
132 $result[] = array(
133 'message' => _T("DELETE operation allowed"),
134 'res' => true
135 );
136 }
137
138 if ($results['drop'] instanceof Exception) {
139 $result[] = array(
140 'message' => _T("DROP operation not allowed"),
141 'debug' => $results['drop']->getMessage(),
142 'res' => false
143 );
144 $error = true;
145 } elseif ($results['drop'] != '') {
146 $result[] = array(
147 'message' => _T("DROP operation allowed"),
148 'res' => true
149 );
150 }
151
152 if ($install->isUpgrade()) {
153 if ($results['alter'] instanceof Exception) {
154 $result[] = array(
155 'message' => _T("ALTER operation not allowed"),
156 'debug' => $results['alter']->getMessage(),
157 'res' => false
158 );
159 $error = true;
160 } elseif ($results['alter'] != '') {
161 $result[] = array(
162 'message' => _T("ALTER operation allowed"),
163 'res' => true
164 );
165 }
166 }
167
168 if ($error) {
169 $permsdb_ok = false;
170 }
171 }
172 ?>
173 <div class="ui segment">
174 <div class="content field">
175 <div class="ui text container">
176
177
178 <?php
179 if ($db_connected === true && $permsdb_ok === true) {
180 if (!isset($install_plugin)) {
181 echo '<p class="ui green message">' . _T("Connection to database successfull") .
182 '<br/>' . _T("Permissions to database are OK.") . '</p>';
183 } else {
184 echo '<p class="ui green message">' . _T("Permissions to database are OK.") . '</p>';
185 }
186 }
187
188 if (!isset($install_plugin)) {
189 ?>
190 <h2><?php echo _T("Check of the database"); ?></h2>
191 <?php
192 }
193
194 if ($db_connected !== true) {
195 $conndb_ok = false;
196 echo '<div class="ui red message">';
197 echo '<div class="ui small header">' . _T("Unable to connect to the database") . '</div>';
198 echo '<p>' . $db_connected->getMessage() . '</p>';
199 echo '</div>';
200 }
201
202 if (!$conndb_ok) {
203 ?>
204 <p><?php echo _T("Database can't be reached. Please go back to enter the connection parameters again."); ?></p>
205 <?php
206 } else {
207 if (!isset($install_plugin)) {
208 ?>
209 <p><?php echo _T("Database exists and connection parameters are OK."); ?></p>
210 <h2><?php echo _T("Permissions on the base"); ?></h2>
211 <?php
212 }
213 if (!$permsdb_ok) {
214 echo '<div class="ui red message">';
215 echo '<h1>';
216 if ($install->isInstall()) {
217 echo _T("GALETTE hasn't got enough permissions on the database to continue the installation.");
218 } elseif ($install->isUpgrade()) {
219 echo _T("GALETTE hasn't got enough permissions on the database to continue the update.");
220 }
221 echo '</h1>';
222 echo '</div>';
223 }
224 ?>
225 <ul class="leaders">
226 <?php
227 foreach ($result as $r) {
228 ?>
229 <li>
230 <span><?php echo $r['message'] ?></span>
231 <span><?php echo $install->getValidationImage($r['res']); ?></span>
232 </li>
233 <?php
234 }
235 ?>
236 </ul>
237 <?php
238 }
239 ?>
240 </div>
241 </div>
242 </div>
243
244 <?php
245 if (!isset($install_plugin)) {
246 ?>
247 <form action="installer.php" method="POST" class="ui form">
248 <div class="ui mobile tablet computer reversed equal width grid">
249 <div class="right aligned column">
250 <button type="submit"<?php if (!$conndb_ok || !$permsdb_ok) { echo ' disabled="disabled"'; } ?> class="ui right labeled icon button"><i class="angle double right icon"></i> <?php echo _T("Next step"); ?></button>
251 <?php
252 if ($conndb_ok && $permsdb_ok) {
253 ?>
254
255 <input type="hidden" name="install_dbperms_ok" value="1"/>
256 <?php
257 }
258 ?>
259 </div>
260 <div class="left aligned column">
261 <button type="submit" id="btnback" name="stepback_btn" formnovalidate class="ui labeled icon button"><i class="angle double left icon"></i> <?php echo _T("Back"); ?></button>
262 </div>
263 </div>
264 </form>
265 <?php
266 }
267 ?>