94function usage($program, $header)
97 echo
" php ".$program.
" [options] [script options]\n";
99 echo
"Script syntax when using step2.php:\n";
100 echo
" php ".$program.
" [options] [action] [selectlang]\n";
103 echo
" Specify the action to execute for the file among the following ones.\n";
104 echo
" - set: Create tables, keys, functions and data for the instance.\n";
106 echo
" selectlang:\n";
107 echo
" Setup the default lang to use, default to 'auto'.\n";
109 echo
"Script syntax when using upgrade.php:\n";
110 echo
" php ".$program.
" [options] previous_version new_version [script options]\n";
112 echo
" dirmodule:\n";
113 echo
" Specify dirmodule to provide a path for an external module\n";
114 echo
" so the migration is done using a script from a module.\n";
116 echo
" ignoredbversion:\n";
117 echo
" Allow to run migration even if database version does\n";
118 echo
" not match start version of migration.\n";
120 echo
"Script syntax when using upgrade2.php:\n";
121 echo
" php ".$program.
" [options] previous_version new_version [module list]\n";
123 echo
" MAIN_MODULE_NAME1,MAIN_MODULE_NAME2:\n";
124 echo
" Specify a list of module-name to enable, in upper case, with MAIN_MODULE_ prefix, joined by comma.\n";
127 echo
" -c, --config <filename>:\n";
128 echo
" Provide a different conf.php file to use.\n";
130 echo
" -h, --help:\n";
131 echo
" Display this help message.\n";
134if (php_sapi_name() ===
"cli" && (
float) PHP_VERSION > 7.0) {
136 $opts = getopt($short_options, $long_options, $rest_index);
138 foreach ($opts as $opt => $arg) {
143 $conffiletoshow = $arg;
147 usage($argv[0],
"Usage:");
153 $args_options = array_filter(
154 array_slice($argv, 0, $rest_index),
159 static function ($arg) {
160 return strlen($arg) >= 2 && $arg[0] ==
'-';
163 $parsed_options = array_map(
169 static function ($arg) {
170 if (strlen($arg) > 1) {
179 $unknown_options = array_diff($args_options, $parsed_options);
185 if (count($unknown_options) > 0) {
186 echo
"Unknown option: ".array_values($unknown_options)[0].
"\n";
187 usage($argv[0],
"Usage:");
195 $argv = array_merge(array($argv[0]), array_slice($argv, $rest_index));
196 $argc = count($argv);
200if (!defined(
'DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) {
201 $result = include_once $conffile;
203 if (empty($dolibarr_main_db_type)) {
204 $dolibarr_main_db_type =
'mysqli';
208 if ($dolibarr_main_db_type ==
'mysql') {
209 $dolibarr_main_db_type =
'mysqli';
212 if (!isset($dolibarr_main_db_port) && ($dolibarr_main_db_type ==
'mysqli')) {
213 $dolibarr_main_db_port =
'3306';
217 $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.
'/../documents';
218 $dolibarr_main_url_root = isset($dolibarr_main_url_root) ? trim($dolibarr_main_url_root) :
'';
219 $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) :
'';
220 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) :
'';
221 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) :
'';
224 if (!empty($dolibarr_main_document_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root)) {
225 $dolibarr_main_document_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root);
227 if (!empty($dolibarr_main_url_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root)) {
228 $dolibarr_main_url_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root);
230 if (!empty($dolibarr_main_data_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_data_root)) {
231 $dolibarr_main_data_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_data_root);
233 if (!empty($dolibarr_main_document_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
234 $dolibarr_main_document_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root_alt);
236 if (!empty($dolibarr_main_url_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
237 $dolibarr_main_url_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root_alt);
241 if (!empty($dolibarr_main_document_root)) {
242 $result =
conf($dolibarr_main_document_root);
246 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
247 $result = include_once $dolibarr_main_document_root.
"/core/db/".$dolibarr_main_db_type.
'.class.php';
249 $includeconferror =
'ErrorBadValueForDolibarrMainDBType';
253 $includeconferror =
'ErrorBadValueForDolibarrMainDocumentRoot';
256 $includeconferror =
'ErrorBadFormatForConfFile';
260$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
263if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
264 $dolibarr_main_db_prefix =
'llx_';
266define(
'MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix :
''));
268define(
'DOL_CLASS_PATH',
'class/');
269define(
'DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.
'/../documents'));
270define(
'DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root :
''));
271$uri = preg_replace(
'/^http(s?):\/\//i',
'', constant(
'DOL_MAIN_URL_ROOT'));
272$suburi = strstr($uri,
'/');
276define(
'DOL_URL_ROOT', $suburi);
279if (empty($conf->file->character_set_client)) {
280 $conf->file->character_set_client =
"utf-8";
282if (empty($conf->db->character_set)) {
283 $conf->db->character_set =
'utf8';
285if (empty($conf->db->dolibarr_main_db_collation)) {
286 $conf->db->dolibarr_main_db_collation =
'utf8_unicode_ci';
288if (empty($conf->db->dolibarr_main_db_encryption)) {
289 $conf->db->dolibarr_main_db_encryption = 0;
291if (empty($conf->db->dolibarr_main_db_cryptkey)) {
292 $conf->db->dolibarr_main_db_cryptkey =
'';
294if (empty($conf->db->user)) {
295 $conf->db->user =
'';
299$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
300if (!empty($dolibarr_main_document_root_alt)) {
302 $values = preg_split(
'/[;,]/', $dolibarr_main_document_root_alt);
303 foreach ($values as $value) {
304 $conf->file->dol_document_root[] = $value;
311$lockfile = DOL_DATA_ROOT.
'/install.lock';
312$lockfile2 = DOL_DOCUMENT_ROOT.
'/install.lock';
313$upgradeunlockfile = DOL_DATA_ROOT.
'/upgrade.unlock';
314$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.
'/upgrade.unlock';
315if (constant(
'DOL_DATA_ROOT') ===
null) {
318 $lockfile =
'../../documents/install.lock';
319 $upgradeunlockfile =
'../../documents/upgrade.unlock';
322if (@file_exists($lockfile) || @file_exists($lockfile2)) {
323 if (!defined(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
330 if (!isset($langs) || !is_object($langs)) {
332 $langs->setDefaultLang(
'auto');
334 $langs->load(
"install");
336 header(
"X-Content-Type-Options: nosniff");
337 header(
"X-Frame-Options: SAMEORIGIN");
339 if (
GETPOST(
'action') !=
'upgrade') {
340 print $langs->trans(
"YouTryInstallDisabledByFileLock").
'<br>';
342 print $langs->trans(
"YouTryUpgradeDisabledByMissingFileUnLock").
'<br>';
344 if (!empty($dolibarr_main_url_root)) {
345 if (
GETPOST(
'action') !=
'upgrade' && (!file_exists($conffile) || !isset($dolibarr_main_url_root))) {
346 print $langs->trans(
"ClickOnLinkOrRemoveManualy").
'<br>';
348 print $langs->trans(
"ClickOnLinkOrCreateUnlockFileManualy").
'<br>';
350 print
'<a href="'.$dolibarr_main_url_root.
'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
351 print $langs->trans(
"ClickHereToGoToApp");
354 print
'If you always reach this page, you must remove the install.lock file manually.<br>';
361$conf->modules[
'syslog'] =
'syslog';
362$conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
363if (!defined(
'SYSLOG_HANDLERS')) {
364 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
366if (!defined(
'SYSLOG_FILE')) {
367 if (@is_writable(
'/tmp')) {
368 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
369 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
370 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
371 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
372 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
373 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
374 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
375 } elseif (@is_writable(
'../../')) {
376 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
380if (defined(
'SYSLOG_FILE')) {
381 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
383if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
384 define(
'SYSLOG_FILE_NO_ERROR', 1);
387$handlers = array(
'mod_syslog_file');
388foreach ($handlers as $handler) {
389 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
390 if (!file_exists($file)) {
391 throw new Exception(
'Missing log handler file '.$handler.
'.php');
395 $loghandlerinstance =
new $handler();
396 if (!$loghandlerinstance instanceof
LogHandler) {
397 throw new Exception(
'Log handler does not extend LogHandler');
400 if (empty($conf->loghandlers[$handler])) {
401 $conf->loghandlers[$handler] = $loghandlerinstance;
408 $langs->setDefaultLang(
GETPOST(
'lang',
'aZ09'));
420function conf($dolibarr_main_document_root)
423 global $dolibarr_main_db_type;
424 global $dolibarr_main_db_host;
425 global $dolibarr_main_db_port;
426 global $dolibarr_main_db_name;
427 global $dolibarr_main_db_user;
428 global $dolibarr_main_db_pass;
429 global $dolibarr_main_db_collation;
430 global $dolibarr_main_db_character_set;
431 global $character_set_client;
432 global $dolibarr_main_instance_unique_id;
433 global $dolibarr_main_cookie_cryptkey;
435 $return = include_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
441 $conf->db->type = trim($dolibarr_main_db_type);
442 $conf->db->host = trim($dolibarr_main_db_host);
443 $conf->db->port = trim($dolibarr_main_db_port);
444 $conf->db->name = trim($dolibarr_main_db_name);
445 $conf->db->user = trim($dolibarr_main_db_user);
446 $conf->db->pass = (empty($dolibarr_main_db_pass) ?
'' : trim($dolibarr_main_db_pass));
449 if ($conf->db->type ==
'mysql') {
450 $conf->db->type =
'mysqli';
452 if (empty($character_set_client)) {
453 $character_set_client =
"UTF-8";
455 $conf->file->character_set_client = strtoupper($character_set_client);
457 $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
458 if (empty($dolibarr_main_db_character_set)) {
459 $dolibarr_main_db_character_set = ($conf->db->type ==
'mysqli' ?
'utf8' :
'');
461 $conf->db->character_set = $dolibarr_main_db_character_set;
462 if (empty($dolibarr_main_db_collation)) {
463 $dolibarr_main_db_collation = ($conf->db->type ==
'mysqli' ?
'utf8_unicode_ci' :
'');
465 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
466 if (empty($dolibarr_main_db_encryption)) {
467 $dolibarr_main_db_encryption = 0;
469 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
470 if (empty($dolibarr_main_db_cryptkey)) {
471 $dolibarr_main_db_cryptkey =
'';
473 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
476 $conf->modules[
'syslog'] =
'syslog';
477 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
478 if (!defined(
'SYSLOG_HANDLERS')) {
479 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
481 if (!defined(
'SYSLOG_FILE')) {
482 if (@is_writable(
'/tmp')) {
483 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
484 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
485 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
486 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
487 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
488 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
489 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
490 } elseif (@is_writable(
'../../')) {
491 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
495 if (defined(
'SYSLOG_FILE')) {
496 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
498 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
499 define(
'SYSLOG_FILE_NO_ERROR', 1);
502 $handlers = array(
'mod_syslog_file');
503 foreach ($handlers as $handler) {
504 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
505 if (!file_exists($file)) {
506 throw new Exception(
'Missing log handler file '.$handler.
'.php');
510 $loghandlerinstance =
new $handler();
511 if (!$loghandlerinstance instanceof
LogHandler) {
512 throw new Exception(
'Log handler does not extend LogHandler');
515 if (empty($conf->loghandlers[$handler])) {
516 $conf->loghandlers[$handler] = $loghandlerinstance;