]> git.agnieray.net Git - galette.git/blob - galette/install/steps/db_checks.php
455fa97efe28e3cfd50bfb2d2a144f64002fbeec
[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-2023 The Galette Team
11 *
12 * This file is part of Galette (https://galette.eu).
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-2023 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 https://galette.eu
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 $supported_db = true;
48
49 if (!isset($show_form)) {
50 $show_form = true;
51 }
52
53 if ($db_connected === true) {
54 if (!isset($zdb)) {
55 $zdb = new GaletteDb();
56 }
57
58 if (!$zdb->isEngineSUpported()) {
59 $supported_db = false;
60 }
61
62 if ($supported_db) {
63 /** FIXME: when tables already exists and DROP not allowed at this time
64 * the showed error is about CREATE, whenever CREATE is allowed */
65 //We delete the table if exists, no error at this time
66 $zdb->dropTestTable();
67
68 $results = $zdb->grantCheck($install->getMode());
69
70 $result = array();
71 $error = false;
72
73 //test returned values
74 if ($results['create'] instanceof Exception) {
75 $result[] = array(
76 'message' => _T("CREATE operation not allowed"),
77 'debug' => $results['create']->getMessage(),
78 'res' => false
79 );
80 $error = true;
81 } elseif ($results['create'] != '') {
82 $result[] = array(
83 'message' => _T("CREATE operation allowed"),
84 'res' => true
85 );
86 }
87
88 if ($results['insert'] instanceof Exception) {
89 $result[] = array(
90 'message' => _T("INSERT operation not allowed"),
91 'debug' => $results['insert']->getMessage(),
92 'res' => false
93 );
94 $error = true;
95 } elseif ($results['insert'] != '') {
96 $result[] = array(
97 'message' => _T("INSERT operation allowed"),
98 'res' => true
99 );
100 }
101
102 if ($results['update'] instanceof Exception) {
103 $result[] = array(
104 'message' => _T("UPDATE operation not allowed"),
105 'debug' => $results['update']->getMessage(),
106 'res' => false
107 );
108 $error = true;
109 } elseif ($results['update'] != '') {
110 $result[] = array(
111 'message' => _T("UPDATE operation allowed"),
112 'res' => true
113 );
114 }
115
116 if ($results['select'] instanceof Exception) {
117 $result[] = array(
118 'message' => _T("SELECT operation not allowed"),
119 'debug' => $results['select']->getMessage(),
120 'res' => false
121 );
122 $error = true;
123 } elseif ($results['select'] != '') {
124 $result[] = array(
125 'message' => _T("SELECT operation allowed"),
126 'res' => true
127 );
128 }
129
130 if ($results['delete'] instanceof Exception) {
131 $result[] = array(
132 'message' => _T("DELETE operation not allowed"),
133 'debug' => $results['delete']->getMessage(),
134 'res' => false
135 );
136 $error = true;
137 } elseif ($results['delete'] != '') {
138 $result[] = array(
139 'message' => _T("DELETE operation allowed"),
140 'res' => true
141 );
142 }
143
144 if ($results['drop'] instanceof Exception) {
145 $result[] = array(
146 'message' => _T("DROP operation not allowed"),
147 'debug' => $results['drop']->getMessage(),
148 'res' => false
149 );
150 $error = true;
151 } elseif ($results['drop'] != '') {
152 $result[] = array(
153 'message' => _T("DROP operation allowed"),
154 'res' => true
155 );
156 }
157
158 if ($install->isUpgrade()) {
159 if ($results['alter'] instanceof Exception) {
160 $result[] = array(
161 'message' => _T("ALTER operation not allowed"),
162 'debug' => $results['alter']->getMessage(),
163 'res' => false
164 );
165 $error = true;
166 } elseif ($results['alter'] != '') {
167 $result[] = array(
168 'message' => _T("ALTER operation allowed"),
169 'res' => true
170 );
171 }
172 }
173
174 if ($error) {
175 $permsdb_ok = false;
176 }
177 }
178 }
179 ?>
180 <div class="ui segment">
181 <div class="content field">
182 <div class="ui text container">
183
184
185 <?php
186 if (!isset($install_plugin)) {
187 ?>
188 <h2><?php echo _T("Check of the database"); ?></h2>
189 <?php
190 echo '<p>' . _T("Database exists and connection parameters are OK.") . '</p>';
191 }
192
193 if ($supported_db === false) {
194 echo '<p class="ui red message">' . _T("Incompatible database version.") .
195 '<br/>' . $zdb->getUnsupportedMessage() . '</p>';
196 } else if ($db_connected === true && $permsdb_ok === true) {
197 if (!isset($install_plugin)) {
198 echo '<p class="ui green message">' . _T("Connection to database successfull") .
199 '<br/>' . _T("Permissions to database are OK.") . '</p>';
200
201 } else {
202 echo '<p class="ui green message">' . _T("Permissions to database are OK.") . '</p>';
203 }
204 }
205 if ($db_connected !== true) {
206 $conndb_ok = false;
207 echo '<div class="ui red message">';
208 echo '<div class="ui small header">' . _T("Unable to connect to the database") . '</div>';
209 echo '<p>' . $db_connected->getMessage() . '</p>';
210 echo '</div>';
211 }
212
213 if (!$conndb_ok) {
214 ?>
215 <p><?php echo _T("Database can't be reached. Please go back to enter the connection parameters again."); ?></p>
216 <?php
217 } elseif ($supported_db === true) {
218 if (!isset($install_plugin)) {
219 ?>
220 <h2><?php echo _T("Permissions on the base"); ?></h2>
221 <?php
222 }
223 if (!$permsdb_ok) {
224 echo '<div class="ui red message">';
225 echo '<h1>';
226 if ($install->isInstall()) {
227 echo _T("GALETTE hasn't got enough permissions on the database to continue the installation.");
228 } elseif ($install->isUpgrade()) {
229 echo _T("GALETTE hasn't got enough permissions on the database to continue the update.");
230 }
231 echo '</h1>';
232 echo '</div>';
233 }
234 ?>
235 <ul class="leaders">
236 <?php
237 foreach ($result as $r) {
238 ?>
239 <li>
240 <span><?php echo $r['message'] ?></span>
241 <span><?php echo $install->getValidationImage($r['res']); ?></span>
242 </li>
243 <?php
244 }
245 ?>
246 </ul>
247 <?php
248 }
249 ?>
250 </div>
251 </div>
252 </div>
253
254 <?php
255 if (!isset($install_plugin)) {
256 ?>
257 <form action="installer.php" method="POST" class="ui form">
258 <div class="ui mobile tablet computer reversed equal width grid">
259 <div class="right aligned column">
260 <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>
261 <?php
262 if ($conndb_ok && $permsdb_ok) {
263 ?>
264
265 <input type="hidden" name="install_dbperms_ok" value="1"/>
266 <?php
267 }
268 ?>
269 </div>
270 <div class="left aligned column">
271 <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>
272 </div>
273 </div>
274 </form>
275 <?php
276 }
277 ?>