dolibarr 21.0.0-alpha
check.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
32include_once 'inc.php';
33
34global $langs;
35
36$err = 0;
37$allowinstall = 0;
38$allowupgrade = false;
39$checksok = 1;
40
41$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
42$langs->setDefaultLang($setuplang);
43
44$langs->load("install");
45
46// Now we load forced/pre-set values from install.forced.php file.
47$useforcedwizard = false;
48$forcedfile = "./install.forced.php";
49if ($conffile == "/etc/dolibarr/conf.php") {
50 $forcedfile = "/etc/dolibarr/install.forced.php";
51}
52if (@file_exists($forcedfile)) {
53 $useforcedwizard = true;
54 include_once $forcedfile;
55}
56
57dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
58
59
60/*
61 * View
62 */
63
64pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
65
66
67//print "<br>\n";
68//print $langs->trans("InstallEasy")."<br><br>\n";
69
70print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
71print '<span class="inline-block">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
72
73// Check browser
74$useragent = $_SERVER['HTTP_USER_AGENT'];
75if (!empty($useragent)) {
76 $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
77 $browserversion = $tmp['browserversion'];
78 $browsername = $tmp['browsername'];
79 if ($browsername == 'ie' && $browserversion < 7) {
80 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
81 }
82}
83
84
85// Check PHP version min
86$arrayphpminversionerror = array(7, 0, 0);
87$arrayphpminversionwarning = array(7, 1, 0);
88if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
89 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
90 $checksok = 0; // 0=error, 1=warning
91} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
92 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
93 $checksok = 1; // 0=error, 1=warning
94} else {
95 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
96}
97if (empty($force_install_nophpinfo)) {
98 print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
99}
100print "<br>\n";
101
102// Check PHP version max
103$arrayphpmaxversionwarning = array(8, 2, 0);
104if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
105 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
106 $checksok = 1; // 0=error, 1=warning
107 print "<br>\n";
108}
109
110
111// Check PHP support for $_GET and $_POST
112if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
113 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETKo");
114 print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
115 print "<br>\n";
116 $checksok = 0;
117} else {
118 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETOk")."<br>\n";
119}
120
121
122// Check if session_id is enabled
123if (!function_exists("session_id")) {
124 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
125 $checksok = 0;
126} else {
127 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportSessions")."<br>\n";
128}
129
130
131// Check for mbstring extension
132if (!extension_loaded("mbstring")) {
133 $langs->load("errors");
134 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "MBString")."<br>\n";
135 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
136} else {
137 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "MBString")."<br>\n";
138}
139
140// Check for json extension
141if (!extension_loaded("json")) {
142 $langs->load("errors");
143 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "JSON")."<br>\n";
144 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
145} else {
146 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "JSON")."<br>\n";
147}
148
149// Check if GD is supported (we need GD for image conversion)
150if (!function_exists("imagecreate")) {
151 $langs->load("errors");
152 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "GD")."<br>\n";
153 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
154} else {
155 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "GD")."<br>\n";
156}
157
158// Check if Curl is supported
159if (!function_exists("curl_init")) {
160 $langs->load("errors");
161 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<br>\n";
162 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
163} else {
164 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Curl")."<br>\n";
165}
166
167// Check if PHP calendar extension is available
168if (!function_exists("easter_date")) {
169 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
170} else {
171 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
172}
173
174// Check if Xml is supported
175if (!function_exists("simplexml_load_string")) {
176 $langs->load("errors");
177 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
178 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
179} else {
180 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
181}
182
183// Check if UTF8 is supported
184if (!function_exists("utf8_encode")) {
185 $langs->load("errors");
186 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
187 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
188} else {
189 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
190}
191
192// Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
193if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
194 if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
195 $langs->load("errors");
196 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
197 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
198 } else {
199 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
200 }
201}
202
203// Check if Imap is supported
204if (PHP_VERSION_ID <= 80300) {
205 if (!function_exists("imap_open")) {
206 $langs->load("errors");
207 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
208 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
209 } else {
210 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
211 }
212}
213
214// Check if Zip is supported
215if (!class_exists('ZipArchive')) {
216 $langs->load("errors");
217 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
218 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
219} else {
220 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
221}
222
223// Check memory
224$memrequiredorig = '64M';
225$memrequired = 64 * 1024 * 1024;
226$memmaxorig = @ini_get("memory_limit");
227$memmax = @ini_get("memory_limit");
228if ($memmaxorig != '') {
229 preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
230 if ($reg[2]) {
231 if (strtoupper($reg[2]) == 'G') {
232 $memmax = (int) $reg[1] * 1024 * 1024 * 1024;
233 }
234 if (strtoupper($reg[2]) == 'M') {
235 $memmax = (int) $reg[1] * 1024 * 1024;
236 }
237 if (strtoupper($reg[2]) == 'K') {
238 $memmax = (int) $reg[1] * 1024;
239 }
240 }
241 if ($memmax >= $memrequired || $memmax == -1) {
242 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
243 } else {
244 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
245 }
246}
247
248
249// If that config file is present and filled
250clearstatcache();
251if (is_readable($conffile) && filesize($conffile) > 8) {
252 dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
253 $confexists = 1;
254 include_once $conffile;
255
256 $databaseok = 1;
257 if ($databaseok) {
258 // Already installed for all parts (config and database). We can propose upgrade.
259 $allowupgrade = true;
260 } else {
261 $allowupgrade = false;
262 }
263} else {
264 // If not, we create it
265 dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
266 $confexists = 0;
267
268 // First we try by copying example
269 if (@copy($conffile.".example", $conffile)) {
270 // Success
271 dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
272 } else {
273 // If failed, we try to create an empty file
274 dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
275
276 $fp = @fopen($conffile, "w");
277 if ($fp) {
278 @fwrite($fp, '<?php');
279 @fwrite($fp, "\n");
280 fclose($fp);
281 } else {
282 dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
283 }
284 }
285
286 // First install: no upgrade necessary/required
287 $allowupgrade = false;
288}
289
290
291
292// File is missing and cannot be created
293if (!file_exists($conffile)) {
294 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
295 print '<br><br><div class="error">';
296 print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
297 print '</div><br><br>'."\n";
298
299 print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
300 $err++;
301} else {
302 if (dol_is_dir($conffile)) {
303 print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
304
305 $allowinstall = 0;
306 } elseif (!is_writable($conffile)) {
307 // File exists but cannot be modified
308 if ($confexists) {
309 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
310 } else {
311 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
312 }
313 print "<br>";
314 print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
315 print "<br>\n";
316
317 $allowinstall = 0;
318 } else {
319 // File exists and can be modified
320 if ($confexists) {
321 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
322 } else {
323 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
324 }
325 print "<br>";
326 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
327 print "<br>\n";
328
329 $allowinstall = 1;
330 }
331 print "<br>\n";
332
333 // Requirements met/all ok: display the next step button
334 if ($checksok) {
335 $ok = 0;
336
337 // Try to create db connection
338 if (file_exists($conffile)) {
339 include_once $conffile;
340 if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
341 if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
342 print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n";
343 dol_syslog("A '".$conffiletoshow."' file exists with a dolibarr_main_document_root to ".$dolibarr_main_document_root." that seems wrong. Try to fix or remove the '".$conffiletoshow."' file.", LOG_WARNING);
344 } else {
345 require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
346
347 // If password is encoded, we decode it
348 if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
349 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
350 if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
351 $dolibarr_main_db_encrypted_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); // We need to set this as it is used to know the password was initially encrypted
352 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
353 } else {
354 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
355 }
356 }
357
358 // $conf already created in inc.php
359 $conf->db->type = $dolibarr_main_db_type;
360 $conf->db->host = $dolibarr_main_db_host;
361 $conf->db->port = $dolibarr_main_db_port;
362 $conf->db->name = $dolibarr_main_db_name;
363 $conf->db->user = $dolibarr_main_db_user;
364 $conf->db->pass = $dolibarr_main_db_pass;
365 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
366 if ($db->connected && $db->database_selected) {
367 $ok = true;
368 }
369 }
370 }
371 }
372
373 // If database access is available, we set more variables
374 if ($ok) {
375 if (empty($dolibarr_main_db_encryption)) {
376 $dolibarr_main_db_encryption = 0;
377 }
378 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
379 if (empty($dolibarr_main_db_cryptkey)) {
380 $dolibarr_main_db_cryptkey = '';
381 }
382 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
383
384 $conf->setValues($db);
385 // Reset forced setup after the setValues
386 if (defined('SYSLOG_FILE')) {
387 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
388 }
389 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
390
391 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
392 // Version to install is DOL_VERSION
393 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : ''));
394 $dolibarrversiontoinstallarray = versiondolibarrarray();
395 }
396
397 // Show title
398 if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) {
399 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.(!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE).'</span></b> - ';
400 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
401 //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
402 print '<br>';
403 print '<br>';
404 } else {
405 print "<br>\n";
406 }
407
408 //print $langs->trans("InstallEasy")." ";
409 print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
410
411 $foundrecommandedchoice = 0;
412
413 $available_choices = array();
414 $notavailable_choices = array();
415
416 if (empty($dolibarr_main_db_host)) { // This means install process was not run
417 $foundrecommandedchoice = 1; // To show only once
418 }
419
420 // Show line of first install choice
421 $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
422 $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
423 $choice .= '</td>';
424 $choice .= '<td class="listofchoicesdesc">';
425 $choice .= $langs->trans("FreshInstallDesc");
426 if (empty($dolibarr_main_db_host)) { // This means install process was not run
427 $choice .= '<br>';
428 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
429 $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
430 // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ';
431 }
432
433 $choice .= '</td>';
434 $choice .= '<td class="center">';
435 if ($allowinstall) {
436 $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
437 } else {
438 $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
439 }
440 $choice .= '</td>'."\n";
441 $choice .= '</tr>'."\n";
442
443 $positionkey = ($foundrecommandedchoice ? 999 : 0);
444 if ($allowinstall) {
445 $available_choices[$positionkey] = $choice;
446 } else {
447 $notavailable_choices[$positionkey] = $choice;
448 }
449
450 // Show upgrade lines
451 $allowupgrade = true;
452 if (empty($dolibarr_main_db_host)) { // This means install process was not run
453 $allowupgrade = false;
454 }
455 if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
456 $allowupgrade = false;
457 }
458 if (GETPOST('allowupgrade')) {
459 $allowupgrade = true;
460 }
461
462 $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
463 dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
464
465 // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
466 $migrationscript = array();
467 $handle = opendir($dir);
468 if (is_resource($handle)) {
469 $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
470 while (($file = readdir($handle)) !== false) {
471 $reg = array();
472 if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
473 //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
474 if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
475 $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
476 }
477 }
478 }
479 $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
480 } else {
481 print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
482 }
483
484 $count = 0;
485 foreach ($migrationscript as $migarray) {
486 $choice = '';
487
488 $count++;
489 $recommended_choice = false;
490 $version = DOL_VERSION;
491 $versionfrom = $migarray['from'];
492 $versionto = $migarray['to'];
493 $versionarray = preg_split('/[\.-]/', $version);
494 $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
495 $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
496 // Define string newversionxxx that are used for text to show
497 $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
498 $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
499 $newversionfrombis = '';
500 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
501 $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
502 }
503
504 if ($ok) {
505 if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
506 // Now we check if this is the first qualified choice
507 if ($allowupgrade && empty($foundrecommandedchoice) &&
508 (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
509 ) {
510 $foundrecommandedchoice = 1; // To show only once
511 $recommended_choice = true;
512 }
513 } else {
514 // We cannot recommend a choice.
515 // A version of install may be known, but we need last upgrade.
516 }
517 }
518
519 $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
520 $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
521 $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
522 $choice .= '<td class="listofchoicesdesc">';
523 $choice .= $langs->trans("UpgradeDesc");
524
525 if ($recommended_choice) {
526 $choice .= '<br>';
527 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
528 $choice .= '<div class="center">';
529 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
530 if ($count < count($migarray)) { // There are other choices after
531 print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
532 }
533 $choice .= '</div>';
534 }
535
536 $choice .= '</td>';
537 $choice .= '<td class="center">';
538 if ($allowupgrade) {
539 $disabled = false;
540 if ($foundrecommandedchoice == 2) {
541 $disabled = true;
542 }
543 if ($foundrecommandedchoice == 1) {
544 $foundrecommandedchoice = 2;
545 }
546 if ($disabled) {
547 $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
548 } else {
549 $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
550 }
551 } else {
552 $choice .= $langs->trans("NotAvailable");
553 }
554 $choice .= '</td>';
555 $choice .= '</tr>'."\n";
556
557 if ($allowupgrade) {
558 $available_choices[$count] = $choice;
559 } else {
560 $notavailable_choices[$count] = $choice;
561 }
562 }
563
564 // If there is no choice at all, we show all of them.
565 if (empty($available_choices)) {
566 $available_choices = $notavailable_choices;
567 $notavailable_choices = array();
568 }
569
570 // Array of install choices
571 krsort($available_choices, SORT_NATURAL);
572 print"\n";
573 print '<table width="100%" class="listofchoices">';
574 foreach ($available_choices as $choice) {
575 print $choice;
576 }
577
578 print '</table>'."\n";
579
580 if (count($notavailable_choices)) {
581 print '<br><div id="AShowChoices" style="opacity: 0.5">';
582 print '> '.$langs->trans('ShowNotAvailableOptions').'...';
583 print '</div>';
584
585 print '<div id="navail_choices" style="display:none">';
586 print "<br>\n";
587 print '<table width="100%" class="listofchoices">';
588 foreach ($notavailable_choices as $choice) {
589 print $choice;
590 }
591
592 print '</table>'."\n";
593 print '</div>';
594 }
595 }
596}
597
598print '<script type="text/javascript">
599
600$("div#AShowChoices").click(function() {
601
602 $("div#navail_choices").toggle();
603
604 if ($("div#navail_choices").css("display") == "none") {
605 $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
606 } else {
607 $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
608 }
609
610});
611
612/*
613$(".runupgrade").click(function() {
614 return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
615});
616*/
617
618</script>';
619
620dolibarr_install_syslog("- check: end");
621pFooter(1); // Never display next button
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition admin.lib.php:39
versiondolibarrarray()
Return version Dolibarr.
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:69
dol_is_dir($folder)
Test if filename is a directory.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getBrowserInfo($user_agent)
Return information about user browser.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition inc.php:535
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:628
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:692
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.