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) {
142 $conffiletoshow = $arg;
146 usage($argv[0],
"Usage:");
152 $args_options = array_filter(array_slice($argv, 0, $rest_index),
function ($arg) {
153 return strlen($arg) >= 2 && $arg[0] ==
'-';
155 $parsed_options = array_map(
function ($arg) {
156 if (strlen($arg) > 1) {
160 }, array_keys($opts));
163 $unknown_options = array_diff($args_options, $parsed_options);
169 if (count($unknown_options) > 0) {
170 echo
"Unknown option: ".array_values($unknown_options)[0].
"\n";
171 usage($argv[0],
"Usage:");
179 $argv = array_merge(array($argv[0]), array_slice($argv, $rest_index));
180 $argc = count($argv);
184if (!defined(
'DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) {
185 $result = include_once $conffile;
187 if (empty($dolibarr_main_db_type)) {
188 $dolibarr_main_db_type =
'mysqli';
192 if ($dolibarr_main_db_type ==
'mysql') {
193 $dolibarr_main_db_type =
'mysqli';
196 if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type ==
'mysqli')) {
197 $dolibarr_main_db_port =
'3306';
201 $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.
'/../documents';
202 $dolibarr_main_url_root = isset($dolibarr_main_url_root) ? trim($dolibarr_main_url_root) :
'';
203 $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) :
'';
204 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) :
'';
205 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ? trim($dolibarr_main_document_root_alt) :
'';
208 if (!empty($dolibarr_main_document_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root)) {
209 $dolibarr_main_document_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root);
211 if (!empty($dolibarr_main_url_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root)) {
212 $dolibarr_main_url_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root);
214 if (!empty($dolibarr_main_data_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_data_root)) {
215 $dolibarr_main_data_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_data_root);
217 if (!empty($dolibarr_main_document_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
218 $dolibarr_main_document_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root_alt);
220 if (!empty($dolibarr_main_url_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
221 $dolibarr_main_url_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root_alt);
225 if (!empty($dolibarr_main_document_root)) {
226 $result =
conf($dolibarr_main_document_root);
230 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
231 $result = include_once $dolibarr_main_document_root.
"/core/db/".$dolibarr_main_db_type.
'.class.php';
233 $includeconferror =
'ErrorBadValueForDolibarrMainDBType';
237 $includeconferror =
'ErrorBadValueForDolibarrMainDocumentRoot';
240 $includeconferror =
'ErrorBadFormatForConfFile';
243$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
246if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
247 $dolibarr_main_db_prefix =
'llx_';
249define(
'MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix :
''));
251define(
'DOL_CLASS_PATH',
'class/');
252define(
'DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.
'/../documents'));
253define(
'DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root :
''));
254$uri = preg_replace(
'/^http(s?):\/\//i',
'', constant(
'DOL_MAIN_URL_ROOT'));
255$suburi = strstr($uri,
'/');
259define(
'DOL_URL_ROOT', $suburi);
262if (empty($conf->file->character_set_client)) {
263 $conf->file->character_set_client =
"utf-8";
265if (empty($conf->db->character_set)) {
266 $conf->db->character_set =
'utf8';
268if (empty($conf->db->dolibarr_main_db_collation)) {
269 $conf->db->dolibarr_main_db_collation =
'utf8_unicode_ci';
271if (empty($conf->db->dolibarr_main_db_encryption)) {
272 $conf->db->dolibarr_main_db_encryption = 0;
274if (empty($conf->db->dolibarr_main_db_cryptkey)) {
275 $conf->db->dolibarr_main_db_cryptkey =
'';
277if (empty($conf->db->user)) {
278 $conf->db->user =
'';
282$conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
283if (!empty($dolibarr_main_document_root_alt)) {
285 $values = preg_split(
'/[;,]/', $dolibarr_main_document_root_alt);
286 foreach ($values as $value) {
287 $conf->file->dol_document_root[] = $value;
294$lockfile = DOL_DATA_ROOT.
'/install.lock';
295$lockfile2 = DOL_DOCUMENT_ROOT.
'/install.lock';
296$upgradeunlockfile = DOL_DATA_ROOT.
'/upgrade.unlock';
297$upgradeunlockfile2 = DOL_DOCUMENT_ROOT.
'/upgrade.unlock';
298if (constant(
'DOL_DATA_ROOT') ===
null) {
301 $lockfile =
'../../documents/install.lock';
302 $upgradeunlockfile =
'../../documents/upgrade.unlock';
305if (@file_exists($lockfile) || @file_exists($lockfile2)) {
306 if (!defined(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND') || (! @file_exists($upgradeunlockfile) && ! @file_exists($upgradeunlockfile2))) {
313 if (!isset($langs) || !is_object($langs)) {
315 $langs->setDefaultLang(
'auto');
317 $langs->load(
"install");
319 header(
"X-Content-Type-Options: nosniff");
320 header(
"X-Frame-Options: SAMEORIGIN");
322 if (
GETPOST(
'action') !=
'upgrade') {
323 print $langs->trans(
"YouTryInstallDisabledByFileLock").
'<br>';
325 print $langs->trans(
"YouTryUpgradeDisabledByMissingFileUnLock").
'<br>';
327 if (!empty($dolibarr_main_url_root)) {
328 if (
GETPOST(
'action') !=
'upgrade' && (!file_exists($conffile) || !isset($dolibarr_main_url_root))) {
329 print $langs->trans(
"ClickOnLinkOrRemoveManualy").
'<br>';
331 print $langs->trans(
"ClickOnLinkOrCreateUnlockFileManualy").
'<br>';
333 print
'<a href="'.$dolibarr_main_url_root.
'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
334 print $langs->trans(
"ClickHereToGoToApp");
337 print
'If you always reach this page, you must remove the install.lock file manually.<br>';
344$conf->modules[
'syslog'] =
'syslog';
345$conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
346if (!defined(
'SYSLOG_HANDLERS')) {
347 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
349if (!defined(
'SYSLOG_FILE')) {
350 if (@is_writable(
'/tmp')) {
351 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
352 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
353 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
354 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
355 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
356 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
357 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
358 } elseif (@is_writable(
'../../')) {
359 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
363if (defined(
'SYSLOG_FILE')) {
364 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
366if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
367 define(
'SYSLOG_FILE_NO_ERROR', 1);
370$handlers = array(
'mod_syslog_file');
371foreach ($handlers as $handler) {
372 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
373 if (!file_exists($file)) {
374 throw new Exception(
'Missing log handler file '.$handler.
'.php');
378 $loghandlerinstance =
new $handler();
380 throw new Exception(
'Log handler does not extend LogHandlerInterface');
383 if (empty($conf->loghandlers[$handler])) {
384 $conf->loghandlers[$handler] = $loghandlerinstance;
391 $langs->setDefaultLang(
GETPOST(
'lang',
'aZ09'));
403function conf($dolibarr_main_document_root)
406 global $dolibarr_main_db_type;
407 global $dolibarr_main_db_host;
408 global $dolibarr_main_db_port;
409 global $dolibarr_main_db_name;
410 global $dolibarr_main_db_user;
411 global $dolibarr_main_db_pass;
412 global $character_set_client;
413 global $dolibarr_main_instance_unique_id;
414 global $dolibarr_main_cookie_cryptkey;
416 $return = include_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
422 $conf->db->type = trim($dolibarr_main_db_type);
423 $conf->db->host = trim($dolibarr_main_db_host);
424 $conf->db->port = trim($dolibarr_main_db_port);
425 $conf->db->name = trim($dolibarr_main_db_name);
426 $conf->db->user = trim($dolibarr_main_db_user);
427 $conf->db->pass = (empty($dolibarr_main_db_pass) ?
'' : trim($dolibarr_main_db_pass));
430 if ($conf->db->type ==
'mysql') {
431 $conf->db->type =
'mysqli';
433 if (empty($character_set_client)) {
434 $character_set_client =
"UTF-8";
436 $conf->file->character_set_client = strtoupper($character_set_client);
438 $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;
439 if (empty($dolibarr_main_db_character_set)) {
440 $dolibarr_main_db_character_set = ($conf->db->type ==
'mysqli' ?
'utf8' :
'');
442 $conf->db->character_set = $dolibarr_main_db_character_set;
443 if (empty($dolibarr_main_db_collation)) {
444 $dolibarr_main_db_collation = ($conf->db->type ==
'mysqli' ?
'utf8_unicode_ci' :
'');
446 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
447 if (empty($dolibarr_main_db_encryption)) {
448 $dolibarr_main_db_encryption = 0;
450 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
451 if (empty($dolibarr_main_db_cryptkey)) {
452 $dolibarr_main_db_cryptkey =
'';
454 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
457 $conf->modules[
'syslog'] =
'syslog';
458 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
459 if (!defined(
'SYSLOG_HANDLERS')) {
460 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
462 if (!defined(
'SYSLOG_FILE')) {
463 if (@is_writable(
'/tmp')) {
464 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
465 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
466 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
467 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
468 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
469 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
470 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
471 } elseif (@is_writable(
'../../')) {
472 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
476 if (defined(
'SYSLOG_FILE')) {
477 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
479 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
480 define(
'SYSLOG_FILE_NO_ERROR', 1);
483 $handlers = array(
'mod_syslog_file');
484 foreach ($handlers as $handler) {
485 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
486 if (!file_exists($file)) {
487 throw new Exception(
'Missing log handler file '.$handler.
'.php');
491 $loghandlerinstance =
new $handler();
493 throw new Exception(
'Log handler does not extend LogHandlerInterface');
496 if (empty($conf->loghandlers[$handler])) {
497 $conf->loghandlers[$handler] = $loghandlerinstance;