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