step2.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Cedric GROSS <c.gross@kreiz-it.fr>
  5. * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/install/step2.php
  22. * \ingroup install
  23. * \brief Create tables, primary keys, foreign keys, indexes and functions into database and then load reference data
  24. */
  25. include 'inc.php';
  26. require_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  27. require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
  28. require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
  29. global $langs;
  30. $step = 2;
  31. $ok = 0;
  32. // This page can be long. We increase the time allowed. / Cette page peut etre longue. On augmente le delai autorise.
  33. // Only works if you are not in safe_mode. / Ne fonctionne que si on est pas en safe_mode.
  34. $err = error_reporting();
  35. error_reporting(0); // Disable all errors
  36. //error_reporting(E_ALL);
  37. @set_time_limit(1800); // Need 1800 on some very slow OS like Windows 7/64
  38. error_reporting($err);
  39. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : (empty($argv[1]) ? '' : $argv[1]);
  40. $setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[2]) ? 'auto' : $argv[2]);
  41. $langs->setDefaultLang($setuplang);
  42. $langs->loadLangs(array("admin", "install"));
  43. // Choice of DBMS
  44. $choix = 0;
  45. if ($dolibarr_main_db_type == "mysqli") {
  46. $choix = 1;
  47. }
  48. if ($dolibarr_main_db_type == "pgsql") {
  49. $choix = 2;
  50. }
  51. if ($dolibarr_main_db_type == "mssql") {
  52. $choix = 3;
  53. }
  54. if ($dolibarr_main_db_type == "sqlite") {
  55. $choix = 4;
  56. }
  57. if ($dolibarr_main_db_type == "sqlite3") {
  58. $choix = 5;
  59. }
  60. //if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into step2.php page');
  61. // Now we load forced values from install.forced.php file.
  62. $useforcedwizard = false;
  63. $forcedfile = "./install.forced.php";
  64. if ($conffile == "/etc/dolibarr/conf.php") {
  65. $forcedfile = "/etc/dolibarr/install.forced.php";
  66. }
  67. if (@file_exists($forcedfile)) {
  68. $useforcedwizard = true;
  69. include_once $forcedfile;
  70. // test for travis
  71. if (!empty($argv[1]) && $argv[1] == "set") {
  72. $action = "set";
  73. }
  74. }
  75. dolibarr_install_syslog("--- step2: entering step2.php page");
  76. /*
  77. * View
  78. */
  79. pHeader($langs->trans("CreateDatabaseObjects"), "step4");
  80. // Test if we can run a first install process
  81. if (!is_writable($conffile)) {
  82. print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  83. pFooter(1, $setuplang, 'jscheckparam');
  84. exit;
  85. }
  86. if ($action == "set") {
  87. print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans("Database").'</h3>';
  88. print '<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
  89. $error = 0;
  90. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
  91. if ($db->connected) {
  92. print "<tr><td>";
  93. print $langs->trans("ServerConnection")." : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  94. $ok = 1;
  95. } else {
  96. print "<tr><td>Failed to connect to server : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  97. }
  98. if ($ok) {
  99. if ($db->database_selected) {
  100. dolibarr_install_syslog("step2: successful connection to database: ".$conf->db->name);
  101. } else {
  102. dolibarr_install_syslog("step2: failed connection to database :".$conf->db->name, LOG_ERR);
  103. print "<tr><td>Failed to select database ".$conf->db->name.'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  104. $ok = 0;
  105. }
  106. }
  107. // Display version / Affiche version
  108. if ($ok) {
  109. $version = $db->getVersion();
  110. $versionarray = $db->getVersionArray();
  111. print '<tr><td>'.$langs->trans("DatabaseVersion").'</td>';
  112. print '<td>'.$version.'</td></tr>';
  113. //print '<td class="right">'.join('.',$versionarray).'</td></tr>';
  114. print '<tr><td>'.$langs->trans("DatabaseName").'</td>';
  115. print '<td>'.$db->database_name.'</td></tr>';
  116. //print '<td class="right">'.join('.',$versionarray).'</td></tr>';
  117. }
  118. $requestnb = 0;
  119. // To disable some code, so you can call step2 with url like
  120. // http://localhost/dolibarrnew/install/step2.php?action=set&token='.newToken().'&createtables=0&createkeys=0&createfunctions=0&createdata=llx_20_c_departements
  121. $createtables = GETPOSTISSET('createtables') ? GETPOST('createtables') : 1;
  122. $createkeys = GETPOSTISSET('createkeys') ? GETPOST('createkeys') : 1;
  123. $createfunctions = GETPOSTISSET('createfunctions') ? GETPOST('createfunction') : 1;
  124. $createdata = GETPOSTISSET('createdata') ? GETPOST('createdata') : 1;
  125. // To say that SQL we pass to query are already escaped for mysql, so we need to unescape them
  126. if (property_exists($db, 'unescapeslashquot')) {
  127. $db->unescapeslashquot = true;
  128. }
  129. /**************************************************************************************
  130. *
  131. * Load files tables/*.sql (not the *.key.sql). Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  132. * To do before the files *.key.sql
  133. *
  134. ***************************************************************************************/
  135. if ($ok && $createtables) {
  136. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  137. $dir = "mysql/tables/";
  138. $ok = 0;
  139. $handle = opendir($dir);
  140. dolibarr_install_syslog("step2: open tables directory ".$dir." handle=".$handle);
  141. $tablefound = 0;
  142. $tabledata = array();
  143. if (is_resource($handle)) {
  144. while (($file = readdir($handle)) !== false) {
  145. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  146. $tablefound++;
  147. $tabledata[] = $file;
  148. }
  149. }
  150. closedir($handle);
  151. }
  152. // Sort list of sql files on alphabetical order (load order is important)
  153. sort($tabledata);
  154. foreach ($tabledata as $file) {
  155. $name = substr($file, 0, dol_strlen($file) - 4);
  156. $buffer = '';
  157. $fp = fopen($dir.$file, "r");
  158. if ($fp) {
  159. while (!feof($fp)) {
  160. $buf = fgets($fp, 4096);
  161. if (substr($buf, 0, 2) != '--') {
  162. $buf = preg_replace('/--(.+)*/', '', $buf);
  163. $buffer .= $buf;
  164. }
  165. }
  166. fclose($fp);
  167. $buffer = trim($buffer);
  168. if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb
  169. $buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer);
  170. } else {
  171. // Keyword ENGINE is MySQL-specific, so scrub it for
  172. // other database types (mssql, pgsql)
  173. $buffer = preg_replace('/type=innodb/i', '', $buffer);
  174. $buffer = preg_replace('/ENGINE=innodb/i', '', $buffer);
  175. }
  176. // Replace the prefix tables
  177. if ($dolibarr_main_db_prefix != 'llx_') {
  178. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  179. }
  180. //print "<tr><td>Creation of table $name/td>";
  181. $requestnb++;
  182. dolibarr_install_syslog("step2: request: ".$buffer);
  183. $resql = $db->query($buffer, 0, 'dml');
  184. if ($resql) {
  185. // print "<td>OK request ==== $buffer</td></tr>";
  186. $db->free($resql);
  187. } else {
  188. if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' ||
  189. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
  190. //print "<td>already existing</td></tr>";
  191. } else {
  192. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  193. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer.' <br>Executed query : '.$db->lastquery;
  194. print "\n</td>";
  195. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  196. $error++;
  197. }
  198. }
  199. } else {
  200. print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
  201. print "</td>";
  202. print '<td><span class="error">'.$langs->trans("Error").' Failed to open file '.$dir.$file.'</span></td></tr>';
  203. $error++;
  204. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  205. }
  206. }
  207. if ($tablefound) {
  208. if ($error == 0) {
  209. print '<tr><td>';
  210. print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  211. $ok = 1;
  212. }
  213. } else {
  214. print '<tr><td>'.$langs->trans("ErrorFailedToFindSomeFiles", $dir).'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  215. dolibarr_install_syslog("step2: failed to find files to create database in directory ".$dir, LOG_ERR);
  216. }
  217. }
  218. /***************************************************************************************
  219. *
  220. * Load files tables/*.key.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  221. * To do after the files *.sql
  222. *
  223. ***************************************************************************************/
  224. if ($ok && $createkeys) {
  225. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  226. $dir = "mysql/tables/";
  227. $okkeys = 0;
  228. $handle = opendir($dir);
  229. dolibarr_install_syslog("step2: open keys directory ".$dir." handle=".$handle);
  230. $tablefound = 0;
  231. $tabledata = array();
  232. if (is_resource($handle)) {
  233. while (($file = readdir($handle)) !== false) {
  234. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file) && !preg_match('/\-/', $file)) {
  235. $tablefound++;
  236. $tabledata[] = $file;
  237. }
  238. }
  239. closedir($handle);
  240. }
  241. // Sort list of sql files on alphabetical order (load order is important)
  242. sort($tabledata);
  243. foreach ($tabledata as $file) {
  244. $name = substr($file, 0, dol_strlen($file) - 4);
  245. //print "<tr><td>Creation of table $name</td>";
  246. $buffer = '';
  247. $fp = fopen($dir.$file, "r");
  248. if ($fp) {
  249. while (!feof($fp)) {
  250. $buf = fgets($fp, 4096);
  251. // Special case of lines allowed for some version only
  252. // MySQL
  253. if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) {
  254. $versioncommande = explode('.', $reg[1]);
  255. //var_dump($versioncommande);
  256. //var_dump($versionarray);
  257. if (count($versioncommande) && count($versionarray)
  258. && versioncompare($versioncommande, $versionarray) <= 0) {
  259. // Version qualified, delete SQL comments
  260. $buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf);
  261. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  262. }
  263. }
  264. // PGSQL
  265. if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
  266. $versioncommande = explode('.', $reg[1]);
  267. //var_dump($versioncommande);
  268. //var_dump($versionarray);
  269. if (count($versioncommande) && count($versionarray)
  270. && versioncompare($versioncommande, $versionarray) <= 0) {
  271. // Version qualified, delete SQL comments
  272. $buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf);
  273. //print "Ligne $i qualifiee par version: ".$buf.'<br>';
  274. }
  275. }
  276. // Add line if no comment
  277. if (!preg_match('/^--/i', $buf)) {
  278. $buffer .= $buf;
  279. }
  280. }
  281. fclose($fp);
  282. // If several requests, we loop on each
  283. $listesql = explode(';', $buffer);
  284. foreach ($listesql as $req) {
  285. $buffer = trim($req);
  286. if ($buffer) {
  287. // Replace the prefix tables
  288. if ($dolibarr_main_db_prefix != 'llx_') {
  289. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  290. }
  291. //print "<tr><td>Creation of keys and table index $name: '$buffer'</td>";
  292. $requestnb++;
  293. dolibarr_install_syslog("step2: request: ".$buffer);
  294. $resql = $db->query($buffer, 0, 'dml');
  295. if ($resql) {
  296. //print "<td>OK request ==== $buffer</td></tr>";
  297. $db->free($resql);
  298. } else {
  299. if ($db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' ||
  300. $db->errno() == 'DB_ERROR_CANNOT_CREATE' ||
  301. $db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
  302. $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
  303. preg_match('/duplicate key name/i', $db->error())) {
  304. //print "<td>Deja existante</td></tr>";
  305. $key_exists = 1;
  306. } else {
  307. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  308. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$db->lastqueryerror();
  309. print "\n</td>";
  310. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  311. $error++;
  312. }
  313. }
  314. }
  315. }
  316. } else {
  317. print "<tr><td>".$langs->trans("CreateOtherKeysForTable", $name);
  318. print "</td>";
  319. print '<td><span class="error">'.$langs->trans("Error")." Failed to open file ".$dir.$file."</span></td></tr>";
  320. $error++;
  321. dolibarr_install_syslog("step2: failed to open file ".$dir.$file, LOG_ERR);
  322. }
  323. }
  324. if ($tablefound && $error == 0) {
  325. print '<tr><td>';
  326. print $langs->trans("OtherKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  327. $okkeys = 1;
  328. }
  329. }
  330. /***************************************************************************************
  331. *
  332. * Load the file 'functions.sql'
  333. *
  334. ***************************************************************************************/
  335. if ($ok && $createfunctions) {
  336. // For this file, we use a directory according to database type
  337. if ($choix == 1) {
  338. $dir = "mysql/functions/";
  339. } elseif ($choix == 2) {
  340. $dir = "pgsql/functions/";
  341. } elseif ($choix == 3) {
  342. $dir = "mssql/functions/";
  343. } elseif ($choix == 4) {
  344. $dir = "sqlite3/functions/";
  345. }
  346. // Creation of data
  347. $file = "functions.sql";
  348. if (file_exists($dir.$file)) {
  349. $fp = fopen($dir.$file, "r");
  350. dolibarr_install_syslog("step2: open function file ".$dir.$file." handle=".$fp);
  351. if ($fp) {
  352. $buffer = '';
  353. while (!feof($fp)) {
  354. $buf = fgets($fp, 4096);
  355. if (substr($buf, 0, 2) != '--') {
  356. $buffer .= $buf."§";
  357. }
  358. }
  359. fclose($fp);
  360. }
  361. //$buffer=preg_replace('/;\';/',";'§",$buffer);
  362. // If several requests, we loop on each of them
  363. $listesql = explode('§', $buffer);
  364. foreach ($listesql as $buffer) {
  365. $buffer = trim($buffer);
  366. if ($buffer) {
  367. // Replace the prefix in table names
  368. if ($dolibarr_main_db_prefix != 'llx_') {
  369. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  370. }
  371. dolibarr_install_syslog("step2: request: ".$buffer);
  372. print "<!-- Insert line : ".$buffer."<br>-->\n";
  373. $resql = $db->query($buffer, 0, 'dml');
  374. if ($resql) {
  375. $ok = 1;
  376. $db->free($resql);
  377. } else {
  378. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
  379. || $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
  380. //print "Insert line : ".$buffer."<br>\n";
  381. } else {
  382. $ok = 0;
  383. print "<tr><td>".$langs->trans("FunctionsCreation");
  384. print "<br>\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer;
  385. print "\n</td>";
  386. print '<td><span class="error">'.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().'</span></td></tr>';
  387. $error++;
  388. }
  389. }
  390. }
  391. }
  392. print "<tr><td>".$langs->trans("FunctionsCreation")."</td>";
  393. if ($ok) {
  394. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  395. } else {
  396. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  397. $ok = 1;
  398. }
  399. }
  400. }
  401. /***************************************************************************************
  402. *
  403. * Load files data/*.sql. Files with '-xxx' in name are excluded (they will be loaded during activation of module 'xxx').
  404. *
  405. ***************************************************************************************/
  406. if ($ok && $createdata) {
  407. // We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
  408. $dir = "mysql/data/";
  409. // Insert data
  410. $handle = opendir($dir);
  411. dolibarr_install_syslog("step2: open directory data ".$dir." handle=".$handle);
  412. $tablefound = 0;
  413. $tabledata = array();
  414. if (is_resource($handle)) {
  415. while (($file = readdir($handle)) !== false) {
  416. if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\-/', $file)) {
  417. if (preg_match('/^llx_accounting_account_/', $file)) {
  418. continue; // We discard data file of chart of account. This will be loaded when a chart is selected.
  419. }
  420. //print 'x'.$file.'-'.$createdata.'<br>';
  421. if (is_numeric($createdata) || preg_match('/'.preg_quote($createdata).'/i', $file)) {
  422. $tablefound++;
  423. $tabledata[] = $file;
  424. }
  425. }
  426. }
  427. closedir($handle);
  428. }
  429. // Sort list of data files on alphabetical order (load order is important)
  430. sort($tabledata);
  431. foreach ($tabledata as $file) {
  432. $name = substr($file, 0, dol_strlen($file) - 4);
  433. $fp = fopen($dir.$file, "r");
  434. dolibarr_install_syslog("step2: open data file ".$dir.$file." handle=".$fp);
  435. if ($fp) {
  436. $arrayofrequests = array();
  437. $linefound = 0;
  438. $linegroup = 0;
  439. $sizeofgroup = 1; // Grouping request to have 1 query for several requests does not works with mysql, so we use 1.
  440. // Load all requests
  441. while (!feof($fp)) {
  442. $buffer = fgets($fp, 4096);
  443. $buffer = trim($buffer);
  444. if ($buffer) {
  445. if (substr($buffer, 0, 2) == '--') {
  446. continue;
  447. }
  448. if ($linefound && ($linefound % $sizeofgroup) == 0) {
  449. $linegroup++;
  450. }
  451. if (empty($arrayofrequests[$linegroup])) {
  452. $arrayofrequests[$linegroup] = $buffer;
  453. } else {
  454. $arrayofrequests[$linegroup] .= " ".$buffer;
  455. }
  456. $linefound++;
  457. }
  458. }
  459. fclose($fp);
  460. dolibarr_install_syslog("step2: found ".$linefound." records, defined ".count($arrayofrequests)." group(s).");
  461. $okallfile = 1;
  462. $db->begin();
  463. // We loop on each requests of file
  464. foreach ($arrayofrequests as $buffer) {
  465. // Replace the tables prefixes
  466. if ($dolibarr_main_db_prefix != 'llx_') {
  467. $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
  468. }
  469. //dolibarr_install_syslog("step2: request: " . $buffer);
  470. $resql = $db->query($buffer, 1);
  471. if ($resql) {
  472. //$db->free($resql); // Not required as request we launch here does not return memory needs.
  473. } else {
  474. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  475. //print "<tr><td>Insertion ligne : $buffer</td><td>";
  476. } else {
  477. $ok = 0;
  478. $okallfile = 0;
  479. print '<span class="error">'.$langs->trans("ErrorSQL")." : ".$db->lasterrno()." - ".$db->lastqueryerror()." - ".$db->lasterror()."</span><br>";
  480. }
  481. }
  482. }
  483. if ($okallfile) {
  484. $db->commit();
  485. } else {
  486. $db->rollback();
  487. }
  488. }
  489. }
  490. print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>";
  491. if ($ok) {
  492. print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
  493. } else {
  494. print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
  495. $ok = 1; // Data loading are not blocking errors
  496. }
  497. }
  498. print '</table>';
  499. } else {
  500. print 'Parameter action=set not defined';
  501. }
  502. $ret = 0;
  503. if (!$ok && isset($argv[1])) {
  504. $ret = 1;
  505. }
  506. dolibarr_install_syslog("Exit ".$ret);
  507. dolibarr_install_syslog("- step2: end");
  508. // Force here a value we need after because master.inc.php is not loaded into step2.
  509. // This code must be similar with the one into main.inc.php
  510. $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); // Unique id of instance
  511. $hash_unique_id = dol_hash('dolibarr'.$conf->file->instance_unique_id, 'sha256'); // Note: if the global salt changes, this hash changes too so ping may be counted twice. We don't mind. It is for statistics purpose only.
  512. $out = '<input type="checkbox" name="dolibarrpingno" id="dolibarrpingno"'.((getDolGlobalString('MAIN_FIRST_PING_OK_ID') == 'disabled') ? '' : ' value="checked" checked="true"').'> ';
  513. $out .= '<label for="dolibarrpingno">'.$langs->trans("MakeAnonymousPing").'</label>';
  514. $out .= '<!-- Add js script to manage the uncheck of option to not send the ping -->';
  515. $out .= '<script type="text/javascript">';
  516. $out .= 'jQuery(document).ready(function(){';
  517. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  518. $out .= ' jQuery("#dolibarrpingno").click(function() {';
  519. $out .= ' if (! $(this).is(\':checked\')) {';
  520. $out .= ' console.log("We uncheck anonymous ping");';
  521. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=1; path=/"'."\n";
  522. $out .= ' } else {'."\n";
  523. $out .= ' console.log("We check anonymous ping");';
  524. $out .= ' document.cookie = "DOLINSTALLNOPING_'.$hash_unique_id.'=0; path=/"'."\n";
  525. $out .= ' }'."\n";
  526. $out .= ' });';
  527. $out .= '});';
  528. $out .= '</script>';
  529. print $out;
  530. pFooter($ok ? 0 : 1, $setuplang);
  531. if (isset($db) && is_object($db)) {
  532. $db->close();
  533. }
  534. // Return code if ran from command line
  535. if ($ret) {
  536. exit($ret);
  537. }