93function usage($program, $header)
96 echo
" php ".$program.
" [options] [script options]\n";
98 echo
"Script syntax when using step2.php:\n";
99 echo
" php ".$program.
" [options] [action] [selectlang]\n";
102 echo
" Specify the action to execute for the file among the following ones.\n";
103 echo
" - set: Create tables, keys, functions and data for the instance.\n";
105 echo
" selectlang:\n";
106 echo
" Setup the default lang to use, default to 'auto'.\n";
108 echo
"Script syntax when using upgrade.php:\n";
109 echo
" php ".$program.
" [options] previous_version new_version [script options]\n";
111 echo
" dirmodule:\n";
112 echo
" Specify dirmodule to provide a path for an external module\n";
113 echo
" so the migration is done using a script from a module.\n";
115 echo
" ignoredbversion:\n";
116 echo
" Allow to run migration even if database version does\n";
117 echo
" not match start version of migration.\n";
119 echo
"Script syntax when using upgrade2.php:\n";
120 echo
" php ".$program.
" [options] previous_version new_version [module list]\n";
122 echo
" MAIN_MODULE_NAME1,MAIN_MODULE_NAME2:\n";
123 echo
" Specify a list of module-name to enable, in upper case, with MAIN_MODULE_ prefix, joined by comma.\n";
126 echo
" -c, --config <filename>:\n";
127 echo
" Provide a different conf.php file to use.\n";
129 echo
" -h, --help:\n";
130 echo
" Display this help message.\n";
133if (php_sapi_name() ===
"cli" && (
float) PHP_VERSION > 7.0) {
135 $opts = getopt($short_options, $long_options, $rest_index);
137 foreach ($opts as $opt => $arg)
switch ($opt) {
141 $conffiletoshow = $arg;
145 usage($argv[0],
"Usage:");
150 $args_options = array_filter(array_slice($argv, 0, $rest_index),
function ($arg) {
151 return strlen($arg) >= 2 && $arg[0] ==
'-';
153 $parsed_options = array_map(
function ($arg) {
154 if (strlen($arg) > 1)
157 }, array_keys($opts));
160 $unknown_options = array_diff($args_options, $parsed_options);
166 if (count($unknown_options) > 0) {
167 echo
"Unknown option: ".array_values($unknown_options)[0].
"\n";
168 usage($argv[0],
"Usage:");
176 $argv = array_merge(array($argv[0]), array_slice($argv, $rest_index));
177 $argc = count($argv);
181if (!defined(
'DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) {
182 $result = include_once $conffile;
184 if (empty($dolibarr_main_db_type)) {
185 $dolibarr_main_db_type =
'mysqli';
189 if ($dolibarr_main_db_type ==
'mysql') {
190 $dolibarr_main_db_type =
'mysqli';
193 if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type ==
'mysqli')) {
194 $dolibarr_main_db_port =
'3306';
198 $dolibarr_main_data_root = isset($dolibarr_main_data_root) ?trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.
'/../documents';
199 $dolibarr_main_url_root = isset($dolibarr_main_url_root) ?trim($dolibarr_main_url_root) :
'';
200 $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ?trim($dolibarr_main_url_root_alt) :
'';
201 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ?trim($dolibarr_main_document_root) :
'';
202 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) :
'';
205 if (!empty($dolibarr_main_document_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root)) {
206 $dolibarr_main_document_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root);
208 if (!empty($dolibarr_main_url_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root)) {
209 $dolibarr_main_url_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root);
211 if (!empty($dolibarr_main_data_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_data_root)) {
212 $dolibarr_main_data_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_data_root);
214 if (!empty($dolibarr_main_document_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
215 $dolibarr_main_document_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root_alt);
217 if (!empty($dolibarr_main_url_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
218 $dolibarr_main_url_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root_alt);
222 if (!empty($dolibarr_main_document_root)) {
223 $result =
conf($dolibarr_main_document_root);
227 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
228 $result = include_once $dolibarr_main_document_root.
"/core/db/".$dolibarr_main_db_type.
'.class.php';
230 $includeconferror =
'ErrorBadValueForDolibarrMainDBType';
234 $includeconferror =
'ErrorBadValueForDolibarrMainDocumentRoot';
237 $includeconferror =
'ErrorBadFormatForConfFile';
240$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
243if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
244 $dolibarr_main_db_prefix =
'llx_';
246define(
'MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix :
''));
248define(
'DOL_CLASS_PATH',
'class/');
249define(
'DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.
'/../documents'));
250define(
'DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root :
''));
251$uri = preg_replace(
'/^http(s?):\/\//i',
'', constant(
'DOL_MAIN_URL_ROOT'));
252$suburi = strstr($uri,
'/');
256define(
'DOL_URL_ROOT', $suburi);
259if (empty($conf->file->character_set_client)) {
260 $conf->file->character_set_client =
"utf-8";
262if (empty($conf->db->character_set)) {
263 $conf->db->character_set =
'utf8';
265if (empty($conf->db->dolibarr_main_db_collation)) {
266 $conf->db->dolibarr_main_db_collation =
'utf8_unicode_ci';
268if (empty($conf->db->dolibarr_main_db_encryption)) {
269 $conf->db->dolibarr_main_db_encryption = 0;
271if (empty($conf->db->dolibarr_main_db_cryptkey)) {
272 $conf->db->dolibarr_main_db_cryptkey =
'';
274if (empty($conf->db->user)) {
275 $conf->db->user =
'';
279$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
280if (!empty($dolibarr_main_document_root_alt)) {
282 $values = preg_split(
'/[;,]/', $dolibarr_main_document_root_alt);
283 foreach ($values as $value) {
284 $conf->file->dol_document_root[] = $value;
291$lockfile = DOL_DATA_ROOT.
'/install.lock';
292$lockfile2 = DOL_DOCUMENT_ROOT.
'/install.lock';
293$upgradeunlockfile = DOL_DATA_ROOT.
'/upgrade.unlock';
294$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.
'/upgrade.unlock';
295if (constant(
'DOL_DATA_ROOT') ===
null) {
298 $lockfile =
'../../documents/install.lock';
299 $upgradeunlockfile =
'../../documents/upgrade.unlock';
302if (@file_exists($lockfile) || @file_exists($lockfile2)) {
303 if (!defined(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
310 if (!isset($langs) || !is_object($langs)) {
312 $langs->setDefaultLang(
'auto');
314 $langs->load(
"install");
316 header(
"X-Content-Type-Options: nosniff");
317 header(
"X-Frame-Options: SAMEORIGIN");
319 if (
GETPOST(
'action') !=
'upgrade') {
320 print $langs->trans(
"YouTryInstallDisabledByFileLock").
'<br>';
322 print $langs->trans(
"YouTryUpgradeDisabledByMissingFileUnLock").
'<br>';
324 if (!empty($dolibarr_main_url_root)) {
325 if (
GETPOST(
'action') !=
'upgrade') {
326 print $langs->trans(
"ClickOnLinkOrRemoveManualy").
'<br>';
328 print $langs->trans(
"ClickOnLinkOrCreateUnlockFileManualy").
'<br>';
330 print
'<a href="'.$dolibarr_main_url_root.
'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
331 print $langs->trans(
"ClickHereToGoToApp");
334 print
'If you always reach this page, you must remove the install.lock file manually.<br>';
341$conf->modules[
'syslog'] =
'syslog';
342$conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
343if (!defined(
'SYSLOG_HANDLERS')) {
344 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
346if (!defined(
'SYSLOG_FILE')) {
347 if (@is_writable(
'/tmp')) {
348 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
349 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
350 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
351 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
352 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
353 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
354 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
355 } elseif (@is_writable(
'../../')) {
356 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
360if (defined(
'SYSLOG_FILE')) {
361 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
363if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
364 define(
'SYSLOG_FILE_NO_ERROR', 1);
367$handlers = array(
'mod_syslog_file');
368foreach ($handlers as $handler) {
369 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
370 if (!file_exists($file)) {
371 throw new Exception(
'Missing log handler file '.$handler.
'.php');
375 $loghandlerinstance =
new $handler();
377 throw new Exception(
'Log handler does not extend LogHandlerInterface');
380 if (empty($conf->loghandlers[$handler])) {
381 $conf->loghandlers[$handler] = $loghandlerinstance;
388 $langs->setDefaultLang(
GETPOST(
'lang',
'aZ09'));
400function conf($dolibarr_main_document_root)
403 global $dolibarr_main_db_type;
404 global $dolibarr_main_db_host;
405 global $dolibarr_main_db_port;
406 global $dolibarr_main_db_name;
407 global $dolibarr_main_db_user;
408 global $dolibarr_main_db_pass;
409 global $character_set_client;
410 global $dolibarr_main_instance_unique_id;
411 global $dolibarr_main_cookie_cryptkey;
413 $return = include_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
419 $conf->db->type = trim($dolibarr_main_db_type);
420 $conf->db->host = trim($dolibarr_main_db_host);
421 $conf->db->port = trim($dolibarr_main_db_port);
422 $conf->db->name = trim($dolibarr_main_db_name);
423 $conf->db->user = trim($dolibarr_main_db_user);
424 $conf->db->pass = (empty($dolibarr_main_db_pass) ?
'' : trim($dolibarr_main_db_pass));
427 if ($conf->db->type ==
'mysql') {
428 $conf->db->type =
'mysqli';
430 if (empty($character_set_client)) {
431 $character_set_client =
"UTF-8";
433 $conf->file->character_set_client = strtoupper($character_set_client);
435 $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;
436 if (empty($dolibarr_main_db_character_set)) {
437 $dolibarr_main_db_character_set = ($conf->db->type ==
'mysqli' ?
'utf8' :
'');
439 $conf->db->character_set = $dolibarr_main_db_character_set;
440 if (empty($dolibarr_main_db_collation)) {
441 $dolibarr_main_db_collation = ($conf->db->type ==
'mysqli' ?
'utf8_unicode_ci' :
'');
443 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
444 if (empty($dolibarr_main_db_encryption)) {
445 $dolibarr_main_db_encryption = 0;
447 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
448 if (empty($dolibarr_main_db_cryptkey)) {
449 $dolibarr_main_db_cryptkey =
'';
451 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
454 $conf->modules[
'syslog'] =
'syslog';
455 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
456 if (!defined(
'SYSLOG_HANDLERS')) {
457 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
459 if (!defined(
'SYSLOG_FILE')) {
460 if (@is_writable(
'/tmp')) {
461 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
462 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
463 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
464 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
465 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
466 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
467 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
468 } elseif (@is_writable(
'../../')) {
469 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
473 if (defined(
'SYSLOG_FILE')) {
474 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
476 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
477 define(
'SYSLOG_FILE_NO_ERROR', 1);
480 $handlers = array(
'mod_syslog_file');
481 foreach ($handlers as $handler) {
482 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
483 if (!file_exists($file)) {
484 throw new Exception(
'Missing log handler file '.$handler.
'.php');
488 $loghandlerinstance =
new $handler();
490 throw new Exception(
'Log handler does not extend LogHandlerInterface');
493 if (empty($conf->loghandlers[$handler])) {
494 $conf->loghandlers[$handler] = $loghandlerinstance;