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