40require_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
41require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
42require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
52$err = error_reporting();
58$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') : (empty($argv[1]) ?
'' : $argv[1]);
59$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[2]) ?
'auto' : $argv[2]);
60$langs->setDefaultLang($setuplang);
62$langs->loadLangs(array(
"admin",
"install"));
68if ($dolibarr_main_db_type ==
"mysqli") {
71if ($dolibarr_main_db_type ==
"pgsql") {
74if ($dolibarr_main_db_type ==
"mssql") {
77if ($dolibarr_main_db_type ==
"sqlite") {
80if ($dolibarr_main_db_type ==
"sqlite3") {
88$useforcedwizard =
false;
89$forcedfile =
"./install.forced.php";
90if (
$conffile ==
"/etc/dolibarr/conf.php") {
91 $forcedfile =
"/etc/dolibarr/install.forced.php";
93if (@file_exists($forcedfile)) {
94 $useforcedwizard =
true;
95 include_once $forcedfile;
97 if (!empty($argv[1]) && $argv[1] ==
"set") {
104'@phan-var-force string $dolibarr_main_db_prefix';
118pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"CreateDatabaseObjects"),
"step4");
122 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
123 pFooter(1, $setuplang,
'jscheckparam');
127if ($action ==
"set") {
128 print
'<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> '.$langs->trans(
"Database").
'</h3>';
130 print
'<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
133 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
135 if ($db->connected) {
137 print $langs->trans(
"ServerConnection").
" : ".$conf->db->host.
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
140 print
"<tr><td>Failed to connect to server : ".$conf->db->host.
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
144 if ($db->database_selected) {
148 print
"<tr><td>Failed to select database ".$conf->db->name.
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
154 $versionarray = array();
157 $version = $db->getVersion();
158 $versionarray = $db->getVersionArray();
159 print
'<tr><td>'.$langs->trans(
"DatabaseVersion").
'</td>';
160 print
'<td>'.$version.
'</td></tr>';
163 print
'<tr><td>'.$langs->trans(
"DatabaseName").
'</td>';
164 print
'<td>'.$db->database_name.
'</td></tr>';
172 $createtables = GETPOSTISSET(
'createtables') ?
GETPOST(
'createtables') : 1;
173 $createkeys = GETPOSTISSET(
'createkeys') ?
GETPOST(
'createkeys') : 1;
174 $createfunctions = GETPOSTISSET(
'createfunctions') ?
GETPOST(
'createfunction') : 1;
175 $createdata = GETPOSTISSET(
'createdata') ?
GETPOST(
'createdata') : 1;
179 if (property_exists($db,
'unescapeslashquot')) {
180 $db->unescapeslashquot =
true;
189 if ($ok && $createtables) {
191 $dir =
"mysql/tables/";
194 $handle = opendir($dir);
195 dolibarr_install_syslog(
"step2: open tables directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
197 $tabledata = array();
198 if (is_resource($handle)) {
199 while (($file = readdir($handle)) !==
false) {
200 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
202 $tabledata[] = $file;
210 foreach ($tabledata as $file) {
211 $name = substr($file, 0,
dol_strlen($file) - 4);
213 $fp = fopen($dir.$file,
"r");
216 $buf = fgets($fp, 4096);
217 if (substr($buf, 0, 2) !=
'--') {
218 $buf = preg_replace(
'/--(.+)*/',
'', $buf);
224 $buffer = trim($buffer);
225 if ($conf->db->type ==
'mysql' || $conf->db->type ==
'mysqli') {
226 $buffer = preg_replace(
'/type=innodb/i',
'ENGINE=innodb', $buffer);
230 $buffer = preg_replace(
'/type=innodb/i',
'', $buffer);
231 $buffer = preg_replace(
'/ENGINE=innodb/i',
'', $buffer);
235 if ($dolibarr_main_db_prefix !=
'llx_') {
236 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
243 $resql = $db->query($buffer, 0,
'dml');
248 if ($db->errno() ==
'DB_ERROR_TABLE_ALREADY_EXISTS' ||
249 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
252 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
253 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer.
' <br>Executed query : '.$db->lastquery;
255 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
260 print
"<tr><td>".$langs->trans(
"CreateTableAndPrimaryKey", $name);
262 print
'<td><span class="error">'.$langs->trans(
"Error").
' Failed to open file '.$dir.$file.
'</span></td></tr>';
271 print $langs->trans(
"TablesAndPrimaryKeysCreation").
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
275 print
'<tr><td>'.$langs->trans(
"ErrorFailedToFindSomeFiles", $dir).
'</td><td>'.
img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
287 if ($ok && $createkeys) {
289 $dir =
"mysql/tables/";
292 $handle = opendir($dir);
293 dolibarr_install_syslog(
"step2: open keys directory ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
295 $tabledata = array();
296 if (is_resource($handle)) {
297 while (($file = readdir($handle)) !==
false) {
298 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && preg_match(
'/\.key\.sql$/i', $file) && !preg_match(
'/\-/', $file)) {
300 $tabledata[] = $file;
308 foreach ($tabledata as $file) {
309 $name = substr($file, 0,
dol_strlen($file) - 4);
312 $fp = fopen($dir.$file,
"r");
315 $buf = fgets($fp, 4096);
319 if ($choix == 1 && preg_match(
'/^--\sV([0-9\.]+)/i', $buf, $reg)) {
320 $versioncommande = explode(
'.', $reg[1]);
323 if (count($versioncommande) && count($versionarray)
326 $buf = preg_replace(
'/^--\sV([0-9\.]+)/i',
'', $buf);
331 if ($choix == 2 && preg_match(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
332 $versioncommande = explode(
'.', $reg[1]);
335 if (count($versioncommande) && count($versionarray)
338 $buf = preg_replace(
'/^--\sPOSTGRESQL\sV([0-9\.]+)/i',
'', $buf);
344 if (!preg_match(
'/^--/i', $buf)) {
351 $listesql = explode(
';', $buffer);
352 foreach ($listesql as $req) {
353 $buffer = trim($req);
356 if ($dolibarr_main_db_prefix !=
'llx_') {
357 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
364 $resql = $db->query($buffer, 0,
'dml');
369 if ($db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
370 $db->errno() ==
'DB_ERROR_CANNOT_CREATE' ||
371 $db->errno() ==
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
372 $db->errno() ==
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
373 preg_match(
'/duplicate key name/i', $db->error())) {
377 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
378 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$db->lastqueryerror();
380 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
387 print
"<tr><td>".$langs->trans(
"CreateOtherKeysForTable", $name);
389 print
'<td><span class="error">'.$langs->trans(
"Error").
" Failed to open file ".$dir.$file.
"</span></td></tr>";
395 if ($tablefound && $error == 0) {
397 print $langs->trans(
"OtherKeysCreation").
'</td><td>'.
img_picto(
'OK',
'tick').
'</td></tr>';
408 if ($ok && $createfunctions) {
412 $dir =
"mysql/functions/";
413 } elseif ($choix == 2) {
414 $dir =
"pgsql/functions/";
415 } elseif ($choix == 3) {
416 $dir =
"mssql/functions/";
417 } elseif ($choix == 4) {
418 $dir =
"sqlite3/functions/";
422 $file =
"functions.sql";
423 if ($dir !==
null && file_exists($dir.$file)) {
424 $fp = fopen($dir.$file,
"r");
425 dolibarr_install_syslog(
"step2: open function file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
429 $buf = fgets($fp, 4096);
430 if (substr($buf, 0, 2) !=
'--') {
439 $listesql = explode(
'§', $buffer);
440 foreach ($listesql as $buffer) {
441 $buffer = trim($buffer);
444 if ($dolibarr_main_db_prefix !=
'llx_') {
445 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
448 print
"<!-- Insert line : ".$buffer.
"<br>-->\n";
449 $resql = $db->query($buffer, 0,
'dml');
454 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS'
455 || $db->errno() ==
'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
460 print
"<tr><td>".$langs->trans(
"FunctionsCreation");
461 print
"<br>\n".$langs->trans(
"Request").
' '.$requestnb.
' : '.$buffer;
463 print
'<td><span class="error">'.$langs->trans(
"ErrorSQL").
" ".$db->errno().
" ".$db->error().
'</span></td></tr>';
470 print
"<tr><td>".$langs->trans(
"FunctionsCreation").
"</td>";
472 print
'<td>'.img_picto(
'OK',
'tick').
'</td></tr>';
474 print
'<td>'.img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
486 if ($ok && $createdata) {
488 $dir =
"mysql/data/";
491 $handle = opendir($dir);
492 dolibarr_install_syslog(
"step2: open directory data ".$dir.
" handle=".(is_bool($handle) ? json_encode($handle) : $handle));
494 $tabledata = array();
495 if (is_resource($handle)) {
496 while (($file = readdir($handle)) !==
false) {
497 if (preg_match(
'/\.sql$/i', $file) && preg_match(
'/^llx_/i', $file) && !preg_match(
'/\-/', $file)) {
498 if (preg_match(
'/^llx_accounting_account_/', $file)) {
503 if (is_numeric($createdata) || preg_match(
'/'.preg_quote($createdata).
'/i', $file)) {
505 $tabledata[] = $file;
514 foreach ($tabledata as $file) {
515 $name = substr($file, 0,
dol_strlen($file) - 4);
516 $fp = fopen($dir.$file,
"r");
517 dolibarr_install_syslog(
"step2: open data file ".$dir.$file.
" handle=".(is_bool($fp) ? json_encode($fp) : $fp));
519 $arrayofrequests = array();
526 $buffer = fgets($fp, 4096);
527 $buffer = trim($buffer);
529 if (substr($buffer, 0, 2) ==
'--') {
533 if ($linefound && ($linefound % $sizeofgroup) == 0) {
536 if (empty($arrayofrequests[$linegroup])) {
537 $arrayofrequests[$linegroup] = $buffer;
539 $arrayofrequests[$linegroup] .=
" ".$buffer;
553 foreach ($arrayofrequests as $buffer) {
555 if ($dolibarr_main_db_prefix !=
'llx_') {
556 $buffer = preg_replace(
'/llx_/i', $dolibarr_main_db_prefix, $buffer);
560 $buffer = preg_replace(
'/__ENTITY__/i',
'1', $buffer);
563 $resql = $db->query($buffer, 1);
567 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
572 print
'<span class="error">'.$langs->trans(
"ErrorSQL").
" : ".$db->lasterrno().
" - ".$db->lastqueryerror().
" - ".$db->lasterror().
"</span><br>";
585 print
"<tr><td>".$langs->trans(
"ReferenceDataLoading").
"</td>";
587 print
'<td>'.img_picto(
'OK',
'tick').
'</td></tr>';
589 print
'<td>'.img_picto(
'Error',
'warning',
'class="error"').
'</td></tr>';
595 print
'Parameter action=set not defined';
600if (!$ok && isset($argv[1])) {
611$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);
613$hash_unique_id =
dol_hash(
'dolibarr'.$conf->file->instance_unique_id,
'sha256');
616$out .=
'<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString(
'MAIN_FIRST_PING_OK_ID') ==
'disabled') ?
'' :
' value="checked" checked="true"').
'> ';
617$out .=
'<label for="dolibarrpingno">'.$langs->trans(
"MakeAnonymousPing").
'</label>';
619$out .=
'<!-- Add js script to manage the uncheck of option to not send the ping -->';
620$out .=
'<script type="text/javascript">';
621$out .=
'jQuery(document).ready(function(){';
622$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
623$out .=
' jQuery("#dolibarrpingno").click(function() {';
624$out .=
' if (! $(this).is(\':checked\')) {';
625$out .=
' console.log("We uncheck anonymous ping");';
626$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=1; path=/"'.
"\n";
627$out .=
' } else {'.
"\n";
628$out .=
' console.log("We check anonymous ping");';
629$out .=
' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.
'=0; path=/"'.
"\n";
637pFooter($ok ? 0 : 1, $setuplang);
639if (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,...
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.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.