42require_once $dolibarr_main_document_root.
'/blockedlog/lib/blockedlog.lib.php';
43require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
44require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
45require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
56$err = error_reporting();
62$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
63$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
64$langs->setDefaultLang($setuplang);
66$langs->loadLangs(array(
"admin",
"install"));
72if ($dolibarr_main_db_type ==
"mysqli") {
75if ($dolibarr_main_db_type ==
"pgsql") {
78if ($dolibarr_main_db_type ==
"mssql") {
81if ($dolibarr_main_db_type ==
"sqlite") {
84if ($dolibarr_main_db_type ==
"sqlite3") {
92$useforcedwizard =
false;
93$forcedfile =
"./install.forced.php";
94if (
$conffile ==
"/etc/dolibarr/conf.php") {
95 $forcedfile =
"/etc/dolibarr/install.forced.php";
97if (@file_exists($forcedfile)) {
98 $useforcedwizard =
true;
99 include_once $forcedfile;
101 if (!empty($argv[1]) && $argv[1] ==
"set") {
109'@phan-var-force string $dolibarr_main_db_prefix';
123pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"CreateDatabaseObjects"),
"step4");
127 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
128 pFooter(1, $setuplang,
'jscheckparam');
132if ($action ==
"set") {
133 print
'<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
135 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
140 if (
$db->connected) {
142 print $langs->trans(
"ServerConnection").
" : ".
$conf->db->host.
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
145 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
149 if (
$db->database_selected) {
153 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
159 $versionarray = array();
162 $version =
$db->getVersion();
163 $versionarray =
$db->getVersionArray();
164 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
165 print
'<td>'.$version.
'</td></tr>';
168 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
169 print
'<td>'.$db->database_name.
'</td></tr>';
177 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
178 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
179 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
180 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
184 if (property_exists($db,
'unescapeslashquot')) {
185 $db->unescapeslashquot =
true;
194 if ($ok && $createtables) {
196 $dir =
"mysql/tables/";
199 $handle = opendir($dir);
200 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
202 $tabledata = array();
203 if (is_resource($handle)) {
204 while (($file = readdir($handle)) !==
false) {
205 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
207 $tabledata[] = $file;
215 foreach ($tabledata as $file) {
216 $name = substr($file, 0,
dol_strlen($file) - 4);
218 $fp = fopen($dir.$file,
"r");
221 $buf = fgets($fp, 4096);
222 if (substr($buf, 0, 2) !=
'--') {
223 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
229 $buffer = trim($buffer);
230 if (
$conf->db->type ==
'mysql' ||
$conf->db->type ==
'mysqli') {
231 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
235 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
236 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
240 if ($dolibarr_main_db_prefix !=
'llx_') {
241 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
248 $resql =
$db->query($buffer, 0,
'dml');
253 if (
$db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
254 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
257 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
258 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.
$db->lastquery;
260 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".
$db->errno().
" ".
$db->error().
'</span></td></tr>';
265 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
267 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
276 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
280 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
292 if ($ok && $createkeys && $db !==
null) {
294 $dir =
"mysql/tables/";
297 $handle = opendir($dir);
298 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
300 $tabledata = array();
301 if (is_resource($handle)) {
302 while (($file = readdir($handle)) !==
false) {
303 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
305 $tabledata[] = $file;
313 foreach ($tabledata as $file) {
314 $name = substr($file, 0,
dol_strlen($file) - 4);
317 $fp = fopen($dir.$file,
"r");
320 $buf = fgets($fp, 4096);
324 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
325 $versioncommande = explode(
'.', $reg[1]);
328 if (count($versioncommande) && count($versionarray)
331 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
336 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
337 $versioncommande = explode(
'.', $reg[1]);
340 if (count($versioncommande) && count($versionarray)
343 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
349 if (!preg_match(
'/^--/i', $buf)) {
356 $listesql = explode(
';', $buffer);
357 foreach ($listesql as $req) {
358 $buffer = trim($req);
361 if ($dolibarr_main_db_prefix !=
'llx_') {
362 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
369 $resql =
$db->query($buffer, 0,
'dml');
374 if (
$db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
375 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
376 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
377 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
378 preg_match(
'/duplicate key name/i',
$db->error())) {
382 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
383 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.
$db->lastqueryerror();
385 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".
$db->errno().
" ".
$db->error().
'</span></td></tr>';
392 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
394 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
400 if ($tablefound && $error == 0) {
402 print $langs->trans(
"OtherKeysCreation").
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
413 if ($ok && $createfunctions) {
417 $dir =
"mysql/functions/";
418 } elseif ($choix == 2) {
419 $dir =
"pgsql/functions/";
420 } elseif ($choix == 3) {
421 $dir =
"mssql/functions/";
422 } elseif ($choix == 4) {
423 $dir =
"sqlite3/functions/";
427 $file =
"functions.sql";
428 if ($dir !==
null && file_exists($dir.$file)) {
429 $fp = fopen($dir.$file,
"r");
430 dolibarr_install_syslog(
"step2: open function file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
434 $buf = fgets($fp, 4096);
435 if (substr($buf, 0, 2) !=
'--') {
444 $listesql = explode(
'§', $buffer);
445 foreach ($listesql as $buffer) {
446 $buffer = trim($buffer);
449 if ($dolibarr_main_db_prefix !=
'llx_') {
450 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
453 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
454 $resql =
$db->query($buffer, 0,
'dml');
459 if (
$db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
460 ||
$db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
465 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
466 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
468 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".
$db->errno().
" ".
$db->error().
'</span></td></tr>';
475 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
477 print
'<td>'.img_picto(
'OK',
'tick').
'</td></tr>';
479 print
'<td>'.img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
491 if ($ok && $createdata) {
493 $dir =
"mysql/data/";
496 $handle = opendir($dir);
497 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
499 $tabledata = array();
500 if (is_resource($handle)) {
501 while (($file = readdir($handle)) !==
false) {
502 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
503 if (preg_match(
'/^llx_accounting_account_/', $file)) {
508 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
510 $tabledata[] = $file;
519 foreach ($tabledata as $file) {
520 $name = substr($file, 0,
dol_strlen($file) - 4);
521 $fp = fopen($dir.$file,
"r");
522 dolibarr_install_syslog(
"step2: open data file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
524 $arrayofrequests = array();
531 $buffer = fgets($fp, 4096);
532 $buffer = trim($buffer);
534 if (substr($buffer, 0, 2) ==
'--') {
538 if ($linefound && ($linefound % $sizeofgroup) == 0) {
541 if (empty($arrayofrequests[$linegroup])) {
542 $arrayofrequests[$linegroup] = $buffer;
544 $arrayofrequests[$linegroup] .=
" ".$buffer;
558 foreach ($arrayofrequests as $buffer) {
560 if ($dolibarr_main_db_prefix !=
'llx_') {
561 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
565 $buffer = preg_replace(
'/__ENTITY__/i',
'1', $buffer);
568 $resql =
$db->query($buffer, 1);
572 if (
$db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
577 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".
$db->lasterrno().
" - ".
$db->lastqueryerror().
" - ".
$db->lasterror().
"</span><br>";
590 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
592 print
'<td>'.img_picto(
'OK',
'tick').
'</td></tr>';
594 print
'<td>'.img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
600 print
'Parameter action=set not defined';
605if (!$ok && isset($argv[1])) {
616$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);
621$out .=
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
622$out .=
'<label for="dolibarrpingno" class="opacitymedium">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
624$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
625$out .=
'<script type="text/javascript">';
626$out .=
'jQuery(document).ready(function(){';
627$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
628$out .=
' jQuery("#dolibarrpingno").click(function() {';
629$out .=
' if (! $(this).is(\':checked\')) {';
630$out .=
' console.log("We uncheck anonymous ping");';
631$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
632$out .=
' } else {'.
"\n";
633$out .=
' console.log("We check anonymous ping");';
634$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
642pFooter($ok ? 0 : 1, $setuplang);
644if (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,...
getHashUniqueIdOfRegistration($algo='sha256')
Return a hash unique identifier of the registration (used to identify the registration of instance wi...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.