29require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
30require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
31require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
42$err = error_reporting();
48$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
49$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
50$langs->setDefaultLang($setuplang);
52$langs->loadLangs(array(
"admin",
"install"));
58if ($dolibarr_main_db_type ==
"mysqli") {
61if ($dolibarr_main_db_type ==
"pgsql") {
64if ($dolibarr_main_db_type ==
"mssql") {
67if ($dolibarr_main_db_type ==
"sqlite") {
70if ($dolibarr_main_db_type ==
"sqlite3") {
78$useforcedwizard =
false;
79$forcedfile =
"./install.forced.php";
80if ($conffile ==
"/etc/dolibarr/conf.php") {
81 $forcedfile =
"/etc/dolibarr/install.forced.php";
83if (@file_exists($forcedfile)) {
84 $useforcedwizard =
true;
85 include_once $forcedfile;
87 if (!empty($argv[1]) && $argv[1] ==
"set") {
94'@phan-var-force string $dolibarr_main_db_prefix';
108pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"CreateDatabaseObjects"),
"step4");
111if (!is_writable($conffile)) {
112 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
113 pFooter(1, $setuplang,
'jscheckparam');
117if ($action ==
"set") {
118 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
120 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
125 if ($db->connected) {
127 print $langs->trans(
"ServerConnection").
" : ".
$conf->db->host.
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
130 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
134 if ($db->database_selected) {
138 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
144 $versionarray = array();
147 $version = $db->getVersion();
148 $versionarray = $db->getVersionArray();
149 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
150 print
'<td>'.$version.
'</td></tr>';
153 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
154 print
'<td>'.$db->database_name.
'</td></tr>';
162 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
163 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
164 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
165 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
169 if (property_exists($db,
'unescapeslashquot')) {
170 $db->unescapeslashquot =
true;
179 if ($ok && $createtables) {
181 $dir =
"mysql/tables/";
184 $handle = opendir($dir);
185 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
187 $tabledata = array();
188 if (is_resource($handle)) {
189 while (($file = readdir($handle)) !==
false) {
190 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
192 $tabledata[] = $file;
200 foreach ($tabledata as $file) {
201 $name = substr($file, 0,
dol_strlen($file) - 4);
203 $fp = fopen($dir.$file,
"r");
206 $buf = fgets($fp, 4096);
207 if (substr($buf, 0, 2) !=
'--') {
208 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
214 $buffer = trim($buffer);
215 if (
$conf->db->type ==
'mysql' ||
$conf->db->type ==
'mysqli') {
216 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
220 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
221 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
225 if ($dolibarr_main_db_prefix !=
'llx_') {
226 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
233 $resql = $db->query($buffer, 0,
'dml');
238 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
239 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
242 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
243 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
245 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
250 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
252 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
261 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
265 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
277 if ($ok && $createkeys) {
279 $dir =
"mysql/tables/";
282 $handle = opendir($dir);
283 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
285 $tabledata = array();
286 if (is_resource($handle)) {
287 while (($file = readdir($handle)) !==
false) {
288 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
290 $tabledata[] = $file;
298 foreach ($tabledata as $file) {
299 $name = substr($file, 0,
dol_strlen($file) - 4);
302 $fp = fopen($dir.$file,
"r");
305 $buf = fgets($fp, 4096);
309 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
310 $versioncommande = explode(
'.', $reg[1]);
313 if (count($versioncommande) && count($versionarray)
316 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
321 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
322 $versioncommande = explode(
'.', $reg[1]);
325 if (count($versioncommande) && count($versionarray)
328 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
334 if (!preg_match(
'/^--/i', $buf)) {
341 $listesql = explode(
';', $buffer);
342 foreach ($listesql as $req) {
343 $buffer = trim($req);
346 if ($dolibarr_main_db_prefix !=
'llx_') {
347 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
354 $resql = $db->query($buffer, 0,
'dml');
359 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
360 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
361 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
362 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
363 preg_match(
'/duplicate key name/i', $db->error())) {
367 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
368 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
370 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
377 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
379 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
385 if ($tablefound && $error == 0) {
387 print $langs->trans(
"OtherKeysCreation").
'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
398 if ($ok && $createfunctions) {
402 $dir =
"mysql/functions/";
403 } elseif ($choix == 2) {
404 $dir =
"pgsql/functions/";
405 } elseif ($choix == 3) {
406 $dir =
"mssql/functions/";
407 } elseif ($choix == 4) {
408 $dir =
"sqlite3/functions/";
412 $file =
"functions.sql";
413 if ($dir !==
null && file_exists($dir.$file)) {
414 $fp = fopen($dir.$file,
"r");
415 dolibarr_install_syslog(
"step2: open function file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
419 $buf = fgets($fp, 4096);
420 if (substr($buf, 0, 2) !=
'--') {
429 $listesql = explode(
'§', $buffer);
430 foreach ($listesql as $buffer) {
431 $buffer = trim($buffer);
434 if ($dolibarr_main_db_prefix !=
'llx_') {
435 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
438 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
439 $resql = $db->query($buffer, 0,
'dml');
444 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
445 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
450 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
451 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
453 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
460 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
462 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
464 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
476 if ($ok && $createdata) {
478 $dir =
"mysql/data/";
481 $handle = opendir($dir);
482 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
484 $tabledata = array();
485 if (is_resource($handle)) {
486 while (($file = readdir($handle)) !==
false) {
487 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
488 if (preg_match(
'/^llx_accounting_account_/', $file)) {
493 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
495 $tabledata[] = $file;
504 foreach ($tabledata as $file) {
505 $name = substr($file, 0,
dol_strlen($file) - 4);
506 $fp = fopen($dir.$file,
"r");
507 dolibarr_install_syslog(
"step2: open data file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
509 $arrayofrequests = array();
516 $buffer = fgets($fp, 4096);
517 $buffer = trim($buffer);
519 if (substr($buffer, 0, 2) ==
'--') {
523 if ($linefound && ($linefound % $sizeofgroup) == 0) {
526 if (empty($arrayofrequests[$linegroup])) {
527 $arrayofrequests[$linegroup] = $buffer;
529 $arrayofrequests[$linegroup] .=
" ".$buffer;
543 foreach ($arrayofrequests as $buffer) {
545 if ($dolibarr_main_db_prefix !=
'llx_') {
546 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
550 $buffer = preg_replace(
'/__ENTITY__/i',
'1', $buffer);
553 $resql = $db->query($buffer, 1);
557 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
562 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
575 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
577 print
'<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
579 print
'<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
585 print
'Parameter action=set not defined';
590if (!$ok && isset($argv[1])) {
601$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);
603$hash_unique_id =
dol_hash(
'dolibarr'.
$conf->file->instance_unique_id,
'sha256');
605$out =
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
606$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
608$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
609$out .=
'<script type="text/javascript">';
610$out .=
'jQuery(document).ready(function(){';
611$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
612$out .=
' jQuery("#dolibarrpingno").click(function() {';
613$out .=
' if (! $(this).is(\':checked\')) {';
614$out .=
' console.log("We uncheck anonymous ping");';
615$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
616$out .=
' } else {'.
"\n";
617$out .=
' console.log("We check anonymous ping");';
618$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
626pFooter($ok ? 0 : 1, $setuplang);
628if (isset($db) && is_object($db)) {
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.