3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Main Galette initialisation
10 * Copyright © 2013-2014 The Galette Team
12 * This file is part of Galette (http://galette.eu).
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.
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.
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/>.
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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.8
38 use Galette\Core\Install
as GaletteInstall
;
39 use Galette\Core\Db
as GaletteDb
;
42 //set a flag saying we work from installer
43 //that way, in galette.inc.php, we'll only include relevant parts
45 define('GALETTE_ROOT', __DIR__
. '/../');
48 require_once GALETTE_ROOT
. '/vendor/autoload.php';
49 require_once GALETTE_ROOT
. 'config/versions.inc.php';
51 if (version_compare(PHP_VERSION
, GALETTE_PHP_MIN
, '<') ||
!extension_loaded('intl')) {
52 header('location: compat_test.php');
56 //specific logfile for installer
57 $logfile = 'galette_install';
58 define('GALETTE_BASE_PATH', '../');
59 define('GALETTE_THEME_DIR', './themes/default/');
61 require_once '../includes/galette.inc.php';
64 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION
);
65 $session = &$_SESSION['galette'][$session_name];
69 'templates.path' => GALETTE_ROOT
. 'templates/default/',
73 require_once '../includes/dependencies.php';
75 if (isset($_POST['abort_btn'])) {
76 if (isset($session[md5(GALETTE_ROOT
)])) {
77 unset($session[md5(GALETTE_ROOT
)]);
79 header('location: ' . GALETTE_BASE_PATH
);
83 if (isset($session[md5(GALETTE_ROOT
)]) && !isset($_GET['raz'])) {
84 $install = unserialize($session[md5(GALETTE_ROOT
)]);
86 $install = new GaletteInstall();
89 $error_detected = array();
92 * Initialize database constants to connect
94 * @param Install $install Installer
98 function initDbConstants($install)
100 define('TYPE_DB', $install->getDbType());
101 define('PREFIX_DB', $install->getTablesPrefix());
102 define('USER_DB', $install->getDbUser());
103 define('PWD_DB', $install->getDbPass());
104 define('HOST_DB', $install->getDbHost());
105 define('PORT_DB', $install->getDbPort());
106 define('NAME_DB', $install->getDbName());
109 if ($install->isStepPassed(GaletteInstall
::STEP_TYPE
)) {
110 define('GALETTE_LOGGER_CHECKED', true);
112 $now = new \
DateTime();
113 $dbg_log_path = GALETTE_LOGS_PATH
. 'galette_debug_' .
114 $now->format('Y-m-d') . '.log';
115 $galette_debug_log = \Analog\Handler\File
::init($dbg_log_path);
117 if (GALETTE_MODE
=== 'DEV') {
118 //logs everything in PHP logs (per chance /var/log/http/error_log or /var/log/php-fpm/error.log)
119 $galette_run_log = \Analog\Handler\Stderr
::init();
121 $logfile = 'galette_install';
122 $log_path = GALETTE_LOGS_PATH
. $logfile . '.log';
123 $galette_run_log = \Analog\Handler\File
::init($log_path);
127 \Analog\Handler\Multi
::init(
129 Analog
::NOTICE
=> \Analog\Handler\Threshold
::init(
133 Analog
::DEBUG
=> $galette_debug_log
139 if (isset($_POST['stepback_btn'])) {
140 $install->atPreviousStep();
141 } elseif (isset($_POST['install_permsok']) && $_POST['install_permsok'] == 1) {
142 $install->atTypeStep();
143 } elseif (isset($_POST['install_type'])) {
144 $install->setMode($_POST['install_type']);
145 $install->atDbStep();
146 } elseif (isset($_POST['install_dbtype'])) {
147 $install->setDbType($_POST['install_dbtype'], $error_detected);
149 if (empty($_POST['install_dbhost'])) {
150 $error_detected[] = _T("No host");
152 if (empty($_POST['install_dbport'])) {
153 $error_detected[] = _T("No port");
155 if (empty($_POST['install_dbuser'])) {
156 $error_detected[] = _T("No user name");
158 if (empty($_POST['install_dbpass'])) {
159 $error_detected[] = _T("No password");
161 if (empty($_POST['install_dbname'])) {
162 $error_detected[] = _T("No database name");
165 if (count($error_detected) == 0) {
167 $_POST['install_dbhost'],
168 $_POST['install_dbport'],
169 $_POST['install_dbname'],
170 $_POST['install_dbuser'],
171 $_POST['install_dbpass']
173 $install->setTablesPrefix(
174 $_POST['install_dbprefix']
176 $install->atDbCheckStep();
178 } elseif (isset($_POST['install_dbperms_ok'])) {
179 if ($install->isInstall()) {
180 $install->atDbInstallStep();
181 } elseif ($install->isUpgrade()) {
182 $install->atVersionSelection();
184 } elseif (isset($_POST['previous_version'])) {
185 $install->setInstalledVersion($_POST['previous_version']);
186 $install->atDbUpgradeStep();
187 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isInstall()) {
188 $install->atAdminStep();
189 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isUpgrade()) {
190 $install->atGaletteInitStep();
191 } elseif (isset($_POST['install_adminlogin'])
192 && isset($_POST['install_adminpass'])
193 && $install->isInstall()
195 if ($_POST['install_adminlogin'] == '') {
196 $error_detected[] = _T("No user name");
198 if (strpos($_POST['install_adminlogin'], '@') != false) {
199 $error_detected[] = _T("The username cannot contain the @ character");
201 if ($_POST['install_adminpass'] == '') {
202 $error_detected[] = _T("No password");
204 if (! isset($_POST['install_passwdverified'])
206 $_POST['install_adminpass'],
207 $_POST['install_adminpass_verif']
210 $error_detected[] = _T("Passwords mismatch");
212 if (count($error_detected) == 0) {
213 $install->setAdminInfos(
214 $_POST['install_adminlogin'],
215 $_POST['install_adminpass']
217 $install->atGaletteInitStep();
219 } elseif (isset($_POST['install_prefs_ok'])) {
220 $install->atEndStep();
223 if (!$install->isEndStep()
224 && ($install->postCheckDb() ||
$install->isDbCheckStep())
226 //if we have passed database configuration, define required constants
227 initDbConstants($install);
229 if ($install->postCheckDb()) {
230 //while before check db, connection is not checked
231 $zdb = new GaletteDb();
235 header('Content-Type: text/html; charset=UTF-8');
238 <html lang
="<?php echo $i18n->getAbbrev(); ?>">
240 <title
><?php
echo _T("Galette Installation") . ' - ' . $install->getStepTitle(); ?
></title
>
241 <meta charset
="UTF-8"/>
242 <link rel
="stylesheet" type
="text/css" href
="./themes/default/galette.css"/>
243 <link rel
="stylesheet" type
="text/css" href
="./themes/default/install.css"/>
244 <link rel
="stylesheet" type
="text/css" href
="./themes/default/jquery-ui/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>.custom.css"/>
245 <link rel
="stylesheet" type
="text/css" href
="./js/selectize-0.12.6/css/selectize.css" />
246 <link rel
="stylesheet" type
="text/css" href
="./js/selectize-0.12.6/css/selectize.default.css" />
247 <script type
="text/javascript" src
="./js/jquery/jquery-<?php echo JQUERY_VERSION; ?>.min.js"></script
>
248 <script type
="text/javascript" src
="./js/jquery/jquery-migrate-<?php echo JQUERY_MIGRATE_VERSION; ?>.min.js"></script
>
249 <script type
="text/javascript" src
="./js/jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.widget.min.js"></script
>
250 <script type
="text/javascript" src
="./js//jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.button.min.js"></script
>
251 <script type
="text/javascript" src
="./js/jquery/jquery-ui-<?php echo JQUERY_UI_VERSION; ?>/jquery.ui.tooltip.min.js"></script
>
252 <script type
="text/javascript" src
="./js/selectize-0.12.6/js/standalone/selectize.min.js"></script
>
253 <script type
="text/javascript" src
="./js/jquery/jquery.bgFade.js"></script
>
254 <script type
="text/javascript" src
="./js/common.js"></script
>
255 <link rel
="shortcut icon" href
="./themes/default/images/favicon.png" />
261 <?php
echo _T("Galette installation") . ' - ' . $install->getStepTitle(); ?
>
265 <select id
="lang_selector" name
="ui_pref_lang">
267 foreach ($i18n->getList() as $langue) {
269 <option value
="<?php echo $langue->getID(); ?>" lang
="<?php echo $langue->getAbbrev(); ?>"<?php
if ($i18n->getAbbrev() == $langue->getAbbrev()) { echo ' selected="selected"'; } ?
>><?php
echo $langue->getName(); ?
></option
>
275 <input type
="submit" name
="{_T string="Change language
"}" />
280 if (count($error_detected) > 0) {
284 <h1
><?php
echo _T("- ERROR -"); ?
></h1
>
287 foreach ($error_detected as $error) {
289 <li
><?php
echo $error; ?
></li
>
300 if ($install->isCheckStep()) {
301 include_once __DIR__
. '/../install/steps/check.php';
302 } elseif ($install->isTypeStep()) {
303 include_once __DIR__
. '/../install/steps/type.php';
304 } elseif ($install->isDbStep()) {
305 include_once __DIR__
. '/../install/steps/db.php';
306 } elseif ($install->isDbCheckStep()) {
307 include_once __DIR__
. '/../install/steps/db_checks.php';
308 } elseif ($install->isVersionSelectionStep()) {
309 include_once __DIR__
. '/../install/steps/db_select_version.php';
310 } elseif ($install->isDbinstallStep() ||
$install->isDbUpgradeStep()) {
311 include_once __DIR__
. '/../install/steps/db_install.php';
312 } elseif ($install->isAdminStep()) {
313 include_once __DIR__
. '/../install/steps/admin.php';
314 } elseif ($install->isGaletteInitStep()) {
315 include_once __DIR__
. '/../install/steps/galette.php';
316 } elseif ($install->isEndStep()) {
317 include_once __DIR__
. '/../install/steps/end.php';
322 <p
><?php
echo _T("Steps:"); ?
></p
>
324 <li
<?php
if ($install->isCheckStep()) echo ' class="current"'; ?
>><?php
echo _T("Checks"); ?
> - </li
>
325 <li
<?php
if ($install->isTypeStep()) echo ' class="current"'; ?
>><?php
echo _T("Installation mode"); ?
> - </li
>
326 <li
<?php
if ($install->isDbStep()) echo ' class="current"'; ?
>><?php
echo _T("Database"); ?
> - </li
>
327 <li
<?php
if ($install->isDbCheckStep()) echo ' class="current"'; ?
>><?php
echo _T("Database access/permissions"); ?
> - </li
>
329 if ( $install->isUpgrade() ) {
331 <li
<?php
if ($install->isVersionSelectionStep()) echo ' class="current"'; ?
>><?php
echo _T("Version selection"); ?
> - </li
>
332 <li
<?php
if ($install->isDbUpgradeStep()) echo ' class="current"'; ?
>><?php
echo _T("Database upgrade"); ?
> - </li
>
336 <li
<?php
if ($install->isDbinstallStep()) echo ' class="current"'; ?
>><?php
echo _T("Database installation"); ?
> - </li
>
340 if ( !$install->isUpgrade() ) {
342 <li
<?php
if ($install->isAdminStep()) echo ' class="current"'; ?
>><?php
echo _T("Admin parameters"); ?
> - </li
>
346 <li
<?php
if ($install->isGaletteInitStep()) echo ' class="current"'; ?
>><?php
echo _T("Galette initialisation"); ?
> - </li
>
347 <li
<?php
if ($install->isEndStep()) echo ' class="current"'; ?
>><?php
echo _T("End!"); ?
></li
>
351 <a id
="copyright" href
="http://galette.eu/">Galette
<?php
echo GALETTE_VERSION
; ?
></a
>
355 if (!$install->isEndStep()) {
356 $session[md5(GALETTE_ROOT
)] = serialize($install);
359 if (isset($profiler)) {