]> git.agnieray.net Git - galette.git/blob - galette/install/steps/db_checks.php
Few buttons fixes
[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 $db_connected = $install->testDbConnexion();
41 $conndb_ok = true;
42 $permsdb_ok = true;
43
44 if (!isset($show_form)) {
45 $show_form = true;
46 }
47
48 if ($db_connected === true) {
49 if (!isset($zdb)) {
50 $zdb = new GaletteDb();
51 }
52
53 /** FIXME: when tables already exists and DROP not allowed at this time
54 the showed error is about CREATE, whenever CREATE is allowed */
55 //We delete the table if exists, no error at this time
56 $zdb->dropTestTable();
57
58 $results = $zdb->grantCheck($install->getMode());
59
60 $result = array();
61 $error = false;
62
63 //test returned values
64 if ($results['create'] instanceof Exception) {
65 $result[] = array(
66 'message' => _T("CREATE operation not allowed"),
67 'debug' => $results['create']->getMessage(),
68 'res' => false
69 );
70 $error = true;
71 } elseif ($results['create'] != '') {
72 $result[] = array(
73 'message' => _T("CREATE operation allowed"),
74 'res' => true
75 );
76 }
77
78 if ($results['insert'] instanceof Exception) {
79 $result[] = array(
80 'message' => _T("INSERT operation not allowed"),
81 'debug' => $results['insert']->getMessage(),
82 'res' => false
83 );
84 $error = true;
85 } elseif ($results['insert'] != '') {
86 $result[] = array(
87 'message' => _T("INSERT operation allowed"),
88 'res' => true
89 );
90 }
91
92 if ($results['update'] instanceof Exception) {
93 $result[] = array(
94 'message' => _T("UPDATE operation not allowed"),
95 'debug' => $results['update']->getMessage(),
96 'res' => false
97 );
98 $error = true;
99 } elseif ($results['update'] != '') {
100 $result[] = array(
101 'message' => _T("UPDATE operation allowed"),
102 'res' => true
103 );
104 }
105
106 if ($results['select'] instanceof Exception) {
107 $result[] = array(
108 'message' => _T("SELECT operation not allowed"),
109 'debug' => $results['select']->getMessage(),
110 'res' => false
111 );
112 $error = true;
113 } elseif ($results['select'] != '') {
114 $result[] = array(
115 'message' => _T("SELECT operation allowed"),
116 'res' => true
117 );
118 }
119
120 if ($results['delete'] instanceof Exception) {
121 $result[] = array(
122 'message' => _T("DELETE operation not allowed"),
123 'debug' => $results['delete']->getMessage(),
124 'res' => false
125 );
126 $error = true;
127 } elseif ($results['delete'] != '') {
128 $result[] = array(
129 'message' => _T("DELETE operation allowed"),
130 'res' => true
131 );
132 }
133
134 if ($results['drop'] instanceof Exception) {
135 $result[] = array(
136 'message' => _T("DROP operation not allowed"),
137 'debug' => $results['drop']->getMessage(),
138 'res' => false
139 );
140 $error = true;
141 } elseif ($results['drop'] != '') {
142 $result[] = array(
143 'message' => _T("DROP operation allowed"),
144 'res' => true
145 );
146 }
147
148 if ($install->isUpgrade()) {
149 if ($results['alter'] instanceof Exception) {
150 $result[] = array(
151 'message' => _T("ALTER operation not allowed"),
152 'debug' => $results['alter']->getMessage(),
153 'res' => false
154 );
155 $error = true;
156 } elseif ($results['alter'] != '') {
157 $result[] = array(
158 'message' => _T("ALTER operation allowed"),
159 'res' => true
160 );
161 }
162 }
163
164 if ($error) {
165 $permsdb_ok = false;
166 }
167 }
168
169 if (!isset($install_plugin)) {
170 ?>
171 <h2><?php echo $install->getStepTitle() ?></h2>
172 <?php
173 }
174
175 if ($db_connected === true && $permsdb_ok === true) {
176 if (!isset($install_plugin)) {
177 echo '<p id="infobox">' . _T("Connection to database successfull") .
178 '<br/>' . _T("Permissions to database are OK.") . '</p>';
179 } else {
180 echo '<p id="infobox">' . _T("Permissions to database are OK.") . '</p>';
181 }
182 }
183
184 if (!isset($install_plugin)) {
185 ?>
186 <h3><?php echo _T("Check of the database"); ?></h3>
187 <?php
188 }
189
190 if ($db_connected !== true) {
191 $conndb_ok = false;
192 echo '<div id="errorbox">';
193 echo '<h1>' . _T("Unable to connect to the database") . '</h1>';
194 echo '<p class="debuginfos">' . $db_connected->getMessage() . '<span>' .
195 $db_connected->getTraceAsString() . '</span></p>';
196 echo '</div>';
197 }
198
199 if (!$conndb_ok) {
200 ?>
201 <p><?php echo _T("Database can't be reached. Please go back to enter the connection parameters again."); ?></p>
202 <?php
203 } else {
204 if (!isset($install_plugin)) {
205 ?>
206 <p><?php echo _T("Database exists and connection parameters are OK."); ?></p>
207 <h3><?php echo _T("Permissions on the base"); ?></h3>
208 <?php
209 }
210 if (!$permsdb_ok) {
211 echo '<div id="errorbox">';
212 echo '<h1>';
213 if ($install->isInstall()) {
214 echo _T("GALETTE hasn't got enough permissions on the database to continue the installation.");
215 } elseif ($install->isUpgrade()) {
216 echo _T("GALETTE hasn't got enough permissions on the database to continue the update.");
217 }
218 echo '</h1>';
219 echo '</div>';
220 }
221 ?>
222 <ul class="leaders">
223 <?php
224 foreach ($result as $r) {
225 ?>
226 <li>
227 <span><?php echo $r['message'] ?></span>
228 <span><?php echo $install->getValidationImage($r['res']); ?></span>
229 </li>
230 <?php
231 }
232 ?>
233 </ul>
234 <?php
235 }
236
237 if (!isset($install_plugin)) {
238 ?>
239 <form action="installer.php" method="POST">
240 <p id="btn_box">
241 <button id="next_btn" type="submit"<?php if (!$conndb_ok || !$permsdb_ok) { echo ' disabled="disabled"'; } ?>><?php echo _T("Next step"); ?> <i class="fas fa-forward"></i></button>
242 <?php
243 if ($conndb_ok && $permsdb_ok) {
244 ?>
245
246 <input type="hidden" name="install_dbperms_ok" value="1"/>
247 <?php
248 }
249 ?>
250 <button type="submit" id="btnback" name="stepback_btn" formnovalidate><i class="fas fa-backward"></i> <?php echo _T("Back"); ?></button>
251 </p>
252 </form>
253 <?php
254 }
255 ?>