dolibarr 22.0.5
step5.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2015-2016 Raphaƫl Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
40define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
41include_once 'inc.php';
42
48if (file_exists($conffile)) {
49 include_once $conffile;
50}
68require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
69require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash
70require_once $dolibarr_main_document_root.'/core/lib/functions2.lib.php';
71
72'
73@phan-var-force ?string $modulesdir
74@phan-var-force ?string $dolibarr_main_db_encryption
75@phan-var-force ?string $dolibarr_main_db_cryptkey
76';
77
78global $langs;
79
80$versionfrom = GETPOST("versionfrom", 'alpha', 3) ? GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
81$versionto = GETPOST("versionto", 'alpha', 3) ? GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
82$setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[3]) ? 'auto' : $argv[3]);
83$langs->setDefaultLang($setuplang);
84$action = GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : (empty($argv[4]) ? '' : $argv[4]);
85
86// Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
87// or MAIN_VERSION_LAST_UPGRADE for upgrade.
88$targetversion = DOL_VERSION; // If it's latest upgrade
89if (!empty($action) && preg_match('/upgrade/i', $action)) {
90 // If it's an old upgrade
91 $tmp = explode('_', $action, 2);
92 if ($tmp[0] == 'upgrade') {
93 if (!empty($tmp[1])) {
94 $targetversion = $tmp[1]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
95 } else {
96 $targetversion = DOL_VERSION; // if $action = 'upgrade', we use DOL_VERSION
97 }
98 }
99}
100
101$langs->loadLangs(array("admin", "install"));
102
103$login = GETPOST('login', 'alpha') ? GETPOST('login', 'alpha') : (empty($argv[5]) ? '' : $argv[5]);
104$pass = GETPOST('pass', 'alpha') ? GETPOST('pass', 'alpha') : (empty($argv[6]) ? '' : $argv[6]);
105$pass_verif = GETPOST('pass_verif', 'alpha') ? GETPOST('pass_verif', 'alpha') : (empty($argv[7]) ? '' : $argv[7]);
106$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (GETPOST('installlock', 'aZ09') ? GETPOST('installlock', 'aZ09') : (empty($argv[8]) ? '' : $argv[8])));
107
108$success = 0;
109
110$useforcedwizard = false;
111$forcedfile = "./install.forced.php";
112if ($conffile == "/etc/dolibarr/conf.php") {
113 $forcedfile = "/etc/dolibarr/install.forced.php";
114}
115if (@file_exists($forcedfile)) {
116 $useforcedwizard = true;
117 include_once $forcedfile;
137 // If forced install is enabled, replace post values. These are empty because form fields are disabled.
138 if ($force_install_noedit == 2) {
139 if (!empty($force_install_dolibarrlogin)) {
140 $login = $force_install_dolibarrlogin;
141 }
142 }
143}
144
145dolibarr_install_syslog("--- step5: entering step5.php page ".$versionfrom." ".$versionto);
146
147$error = 0;
148
149
150/*
151 * Actions
152 */
153
154// If install, check password and password_verification used to create admin account
155if ($action == "set") { // Test on permissions not required here
156 if ($pass != $pass_verif) {
157 header("Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
158 exit;
159 }
160
161 if (dol_strlen(trim($pass)) == 0) {
162 header("Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
163 exit;
164 }
165
166 if (dol_strlen(trim($login)) == 0) {
167 header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
168 exit;
169 }
170}
171
172
173/*
174 * View
175 */
176
177$morehtml = '';
178
179pHeader($langs->trans("DolibarrSetup").' - '.$langs->trans("SetupEnd"), "step5", 'set', '', '', 'main-inside main-inside-borderbottom no-bottom');
180print '<br>';
181
182// Test if we can run a first install process
183if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
184 print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
185 pFooter(1, $setuplang, 'jscheckparam');
186 exit;
187}
188
189// Ensure $modulesdir is set and array
190if (!isset($modulesdir) || !is_array($modulesdir)) {
191 $modulesdir = array();
192}
193
194if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
195 $error = 0;
196
197 // If password is encoded, we decode it
198 if ((!empty($dolibarr_main_db_pass) && preg_match('/(crypted|dolcrypt):/i', (string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
199 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
200 if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', (string) $dolibarr_main_db_pass)) {
201 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', (string) $dolibarr_main_db_pass);
202 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
203 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_pass);
204 } elseif (preg_match('/dolcrypt:/i', (string) $dolibarr_main_db_pass)) {
205 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
206 $dolibarr_main_db_pass = dolDecrypt((string) $dolibarr_main_db_pass);
207 } else {
208 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
209 }
210 }
211
212 $conf->db->type = $dolibarr_main_db_type;
213 $conf->db->host = $dolibarr_main_db_host;
214 $conf->db->port = $dolibarr_main_db_port;
215 $conf->db->name = $dolibarr_main_db_name;
216 $conf->db->user = $dolibarr_main_db_user;
217 $conf->db->pass = $dolibarr_main_db_pass;
218 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
219 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey : '';
220
221 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
222
223 // Create the global $hookmanager object
224 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
225 $hookmanager = new HookManager($db);
226
227 $ok = 0;
228
229 // If first install
230 if ($action == "set") {
231 // Active module user
232 $modName = 'modUser';
233 $file = $modName.".class.php";
234 dolibarr_install_syslog('step5: load module user '.DOL_DOCUMENT_ROOT."/core/modules/".$file, LOG_INFO);
235 include_once DOL_DOCUMENT_ROOT."/core/modules/".$file;
236 $objMod = new $modName($db);
237 $result = $objMod->init();
238 if (!$result) {
239 print "ERROR: failed to init module file = ".$file;
240 }
241
242 if ($db->connected) {
243 $conf->setValues($db);
244 // Reset forced setup after the setValues
245 if (defined('SYSLOG_FILE')) {
246 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
247 }
248 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
249
250 // Create admin user
251 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
252
253 // Set default encryption to yes, generate a salt and set default encryption algorithm (but only if there is no user yet into database)
254 $sql = "SELECT u.rowid, u.pass, u.pass_crypted";
255 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
256 $resql = $db->query($sql);
257 if ($resql) {
258 $numrows = $db->num_rows($resql);
259 if ($numrows == 0) {
260 // Define default setup for password encryption
261 dolibarr_set_const($db, "DATABASE_PWD_ENCRYPTED", "1", 'chaine', 0, '', $conf->entity);
262 dolibarr_set_const($db, "MAIN_SECURITY_SALT", dol_print_date(dol_now(), 'dayhourlog'), 'chaine', 0, '', 0); // All entities
263 if (function_exists('password_hash')) {
264 dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'password_hash', 'chaine', 0, '', 0); // All entities
265 } else {
266 dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'sha1md5', 'chaine', 0, '', 0); // All entities
267 }
268 }
269
270 dolibarr_install_syslog('step5: DATABASE_PWD_ENCRYPTED = ' . getDolGlobalString('DATABASE_PWD_ENCRYPTED').' MAIN_SECURITY_HASH_ALGO = ' . getDolGlobalString('MAIN_SECURITY_HASH_ALGO'), LOG_INFO);
271 }
272
273 // Create user used to create the admin user
274 $createuser = new User($db);
275 $createuser->id = 0;
276 $createuser->admin = 1;
277
278 // Set admin user
279 $newuser = new User($db);
280 $newuser->lastname = 'SuperAdmin';
281 $newuser->firstname = '';
282 $newuser->login = $login;
283 $newuser->pass = $pass;
284 $newuser->admin = 1;
285 $newuser->entity = 0;
286
287 $conf->global->USER_MAIL_REQUIRED = 0; // Force global option to be sure to create a new user with no email
288 $conf->global->USER_PASSWORD_GENERATED = ''; // To not use any rule for password validation
289
290 $result = $newuser->create($createuser, 1);
291 if ($result > 0) {
292 print $langs->trans("AdminLoginCreatedSuccessfuly", $login)."<br>";
293 $success = 1;
294 } else {
295 if ($result == -6) { //login or email already exists
296 dolibarr_install_syslog('step5: AdminLoginAlreadyExists', LOG_WARNING);
297 print '<br><div class="warning">'.$newuser->error."</div><br>";
298 $success = 1;
299 } else {
300 dolibarr_install_syslog('step5: FailedToCreateAdminLogin '.$newuser->error, LOG_ERR);
301 setEventMessages($langs->trans("FailedToCreateAdminLogin").' '.$newuser->error, null, 'errors');
302 //header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
303 print '<br><div class="error">'.$langs->trans("FailedToCreateAdminLogin").': '.$newuser->error.'</div><br><br>';
304 print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
305 }
306 }
307
308 if ($success) {
309 // Insert MAIN_VERSION_FIRST_INSTALL in a dedicated transaction. So if it fails (when first install was already done), we can do other following requests.
310 $db->begin();
311 dolibarr_install_syslog('step5: set MAIN_VERSION_FIRST_INSTALL const to '.$targetversion, LOG_DEBUG);
312 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity) values(".$db->encrypt('MAIN_VERSION_FIRST_INSTALL').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version when first install', 0)");
313 if ($resql) {
314 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
315 $db->commit();
316 } else {
317 //if (! $resql) dol_print_error($db,'Error in setup program'); // We ignore errors. Key may already exists
318 $db->commit();
319 }
320
321 $db->begin();
322
323 dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG);
324 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_INSTALL'");
325 if (!$resql) {
326 dol_print_error($db, 'Error in setup program');
327 }
328 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version when last install', 0)");
329 if (!$resql) {
330 dol_print_error($db, 'Error in setup program');
331 }
332 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
333
334 if ($useforcedwizard) {
335 dolibarr_install_syslog('step5: set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG);
336 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_REMOVE_INSTALL_WARNING'");
337 if (!$resql) {
338 dol_print_error($db, 'Error in setup program');
339 }
340 // The install.lock file is created few lines later if version is last one or if option MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE is on
341 /* No need to enable this
342 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING').", ".$db->encrypt(1).", 'chaine', 1, 'Disable install warnings', 0)");
343 if (!$resql) {
344 dol_print_error($db, 'Error in setup program');
345 }
346 $conf->global->MAIN_REMOVE_INSTALL_WARNING = 1;
347 */
348 }
349
350 // List of modules to enable
351 $tmparray = array();
352
353 // If we ask to force some modules to be enabled
354 if (!empty($force_install_module)) {
355 if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
356 define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
357 }
358
359 $tmparray = explode(',', $force_install_module);
360 }
361
362 $modNameLoaded = array();
363
364 // Search modules dirs
365 $modulesdir[] = $dolibarr_main_document_root.'/core/modules/';
366
367 foreach ($modulesdir as $dir) {
368 // Load modules attributes in arrays (name, numero, orders) from dir directory
369 //print $dir."\n<br>";
370 dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
371 $handle = @opendir($dir);
372 if (is_resource($handle)) {
373 while (($file = readdir($handle)) !== false) {
374 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
375 $modName = substr($file, 0, dol_strlen($file) - 10);
376 if ($modName) {
377 if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
378 $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
379 setEventMessages($mesg, null, 'warnings');
380 dol_syslog($mesg, LOG_ERR);
381 continue;
382 }
383
384 try {
385 $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
386 if (class_exists($modName)) {
387 $objMod = new $modName($db);
388 $modNameLoaded[$modName] = $dir;
389 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
390 $tmparray[] = $file;
391 }
392 }
393 } catch (Exception $e) {
394 dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
395 }
396 }
397 }
398 }
399 }
400 }
401
402 // Loop on each modules to activate it
403 if (!empty($tmparray)) {
404 foreach ($tmparray as $modtoactivate) {
405 $modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate);
406 //print $langs->trans("ActivateModule", $modtoactivatenew).'<br>';
407
408 $file = $modtoactivatenew.'.class.php';
409 dolibarr_install_syslog('step5: activate module file='.$file);
410 $res = dol_include_once("/core/modules/".$file);
411
412 $res = activateModule($modtoactivatenew, 1);
413 if (!empty($res['errors'])) {
414 print 'ERROR: failed to activateModule() file='.$file;
415 }
416 }
417 //print '<br>';
418 }
419
420 // Now delete the flag that say installation is not complete
421 dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const');
422 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
423 if (!$resql) {
424 dol_print_error($db, 'Error in setup program');
425 }
426
427 // May fail if parameter already defined
428 dolibarr_install_syslog('step5: set the default language');
429 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) VALUES (".$db->encrypt('MAIN_LANG_DEFAULT').", ".$db->encrypt($setuplang).", 'chaine', 0, 'Default language', 1)");
430 //if (! $resql) dol_print_error($db,'Error in setup program');
431
432 $db->commit();
433 }
434 } else {
435 print $langs->trans("ErrorFailedToConnect")."<br>";
436 }
437 } elseif (empty($action) || preg_match('/upgrade/i', $action)) {
438 // If upgrade
439 if ($db->connected) {
440 $conf->setValues($db);
441 // Reset forced setup after the setValues
442 if (defined('SYSLOG_FILE')) {
443 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
444 }
445 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
446
447 // Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
448 $tagdatabase = false;
449 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE')) {
450 $tagdatabase = true; // We don't know what it was before, so now we consider we at the chosen version.
451 } else {
452 $mainversionlastupgradearray = preg_split('/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
453 $targetversionarray = preg_split('/[.-]/', $targetversion);
454 if (versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
455 $tagdatabase = true;
456 }
457 }
458
459 if ($tagdatabase) {
460 dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion);
461 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_UPGRADE'");
462 if (!$resql) {
463 dol_print_error($db, 'Error in setup program');
464 }
465 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity) VALUES (".$db->encrypt('MAIN_VERSION_LAST_UPGRADE').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version for last upgrade', 0)");
466 if (!$resql) {
467 dol_print_error($db, 'Error in setup program');
468 }
469 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
470 } else {
471 dolibarr_install_syslog('step5: we run an upgrade to version '.$targetversion.' but database was already upgraded to ' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'. We keep MAIN_VERSION_LAST_UPGRADE as it is.');
472
473 // Force the delete of the flag that say installation is not complete
474 dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
475 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
476 if (!$resql) {
477 dol_print_error($db, 'Error in setup program');
478 }
479 }
480 } else {
481 print $langs->trans("ErrorFailedToConnect")."<br>";
482 }
483 } else {
484 dol_print_error(null, 'step5.php: unknown choice of action');
485 }
486
487 $db->close();
488}
489
490
491
492// Create lock file
493
494// If first install
495if ($action == "set") {
496 if ($success) {
497 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
498 // Install is finished (database is on same version than files)
499 print '<br>'.$langs->trans("SystemIsInstalled")."<br>";
500
501 // Create install.lock file
502 // No need for the moment to create it automatically, creation by web assistant means permissions are given
503 // to the web user, it is better to show a warning to say to create it manually with correct user/permission (not erasable by a web process)
504 $createlock = 0;
505 if (!empty($force_install_lockinstall) || getDolGlobalString('MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
506 // Install is finished, we create the "install.lock" file, so install won't be possible anymore.
507 // TODO Upgrade will be still be possible if a file "upgrade.unlock" is present
508 $lockfile = DOL_DATA_ROOT.'/install.lock';
509 $fp = @fopen($lockfile, "w");
510 if ($fp) {
511 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
512 $force_install_lockinstall = '444'; // For backward compatibility
513 }
514 fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
515 fclose($fp);
516 dolChmod($lockfile, $force_install_lockinstall);
517
518 $createlock = 1;
519 }
520 }
521 if (empty($createlock)) {
522 print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
523 }
524
525 print "<br>";
526
527 print $langs->trans("YouNeedToPersonalizeSetup")."<br><br><br>";
528
529 print '<div class="center">&gt; <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ? '&username='.urlencode($login) : '').'">';
530 print '<span class="fas fa-external-link-alt"></span> '.$langs->trans("GoToSetupArea");
531 print '</a></div><br>';
532 } else {
533 // If here MAIN_VERSION_LAST_UPGRADE is not empty
534 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
535 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b><br>';
536 print $langs->trans("MigrationNotFinished").'<br>';
537 print "<br>";
538
539 print '<div class="center"><a href="'.$dolibarr_main_url_root.'/install/index.php">';
540 print '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
541 print '</a></div>';
542 }
543 }
544} elseif (empty($action) || preg_match('/upgrade/i', $action)) {
545 // If upgrade
546 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') == DOL_VERSION) {
547 // Upgrade is finished (database is on the same version than files)
548 print '<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="30" alt="Configuration">';
549 print ' <span class="valignmiddle">'.$langs->trans("SystemIsUpgraded")."</span><br>";
550
551 // Create install.lock file if it does not exists.
552 // Note: it should always exists. A better solution to allow upgrade will be to add an upgrade.unlock file
553 $createlock = 0;
554 if (!empty($force_install_lockinstall) || getDolGlobalString('MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
555 // Upgrade is finished, we modify the lock file
556 $lockfile = DOL_DATA_ROOT.'/install.lock';
557 $fp = @fopen($lockfile, "w");
558 if ($fp) {
559 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
560 $force_install_lockinstall = '444'; // For backward compatibility
561 }
562 fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
563 fclose($fp);
564 dolChmod($lockfile, $force_install_lockinstall);
565
566 $createlock = 1;
567 }
568 }
569 if (empty($createlock)) {
570 print '<br><div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
571 }
572
573 // Delete the upgrade.unlock file it it exists
574 $unlockupgradefile = DOL_DATA_ROOT.'/upgrade.unlock';
575 dol_delete_file($unlockupgradefile, 0, 0, 0, null, false, 0);
576
577 print "<br>";
578
579 $morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ? '&username='.urlencode($login) : '').'">';
580 $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToDolibarr").'...';
581 $morehtml .= '</a></div><br>';
582 } else {
583 // If here MAIN_VERSION_LAST_UPGRADE is not empty
584 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
585 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
586
587 print "<br>";
588
589 $morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
590 $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
591 $morehtml .= '</a></div>';
592 }
593} else {
594 dol_print_error(null, 'step5.php: unknown choice of action='.$action.' in create lock file seaction');
595}
596
597// Clear cache files
598clearstatcache();
599
600$ret = 0;
601if ($error && isset($argv[1])) {
602 $ret = 1;
603}
604dolibarr_install_syslog("Exit ".$ret);
605
606dolibarr_install_syslog("--- step5: Dolibarr setup finished");
607
608pFooter(1, $setuplang, '', 0, $morehtml);
609
610// Return code if ran from command line
611if ($ret) {
612 exit($ret);
613}
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
activateModule($value, $withdeps=1, $noconfverification=0)
Enable a module.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:71
Class to manage hooks.
Class to manage Dolibarr users.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:538
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:631
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:695
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.