code syntax

This commit is contained in:
Frédéric FRANCE 2021-02-22 15:18:01 +01:00
parent 93aa12a573
commit 858a65a173
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
9 changed files with 1143 additions and 1390 deletions

View File

@ -43,7 +43,9 @@ $langs->load("install");
// Now we load forced/pre-set values from install.forced.php file.
$useforcedwizard = false;
$forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") {
$forcedfile = "/etc/dolibarr/install.forced.php";
}
if (@file_exists($forcedfile)) {
$useforcedwizard = true;
include_once $forcedfile;
@ -66,36 +68,36 @@ print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg
// Check browser
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (!empty($useragent))
{
if (!empty($useragent)) {
$tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
$browserversion = $tmp['browserversion'];
$browsername = $tmp['browsername'];
if ($browsername == 'ie' && $browserversion < 7) print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
if ($browsername == 'ie' && $browserversion < 7) {
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
}
}
// Check PHP version
$arrayphpminversionerror = array(5, 5, 0);
$arrayphpminversionwarning = array(5, 6, 0);
if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) // Minimum to use (error if lower)
{
if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
$checksok = 0; // 0=error, 1=warning
} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) // Minimum supported (warning if lower)
{
} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
$checksok = 0; // 0=error, 1=warning
} else {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
}
if (empty($force_install_nophpinfo)) print ' (<a href="phpinfo.php" target="_blank">'.$langs->trans("MoreInformation").'</a>)';
if (empty($force_install_nophpinfo)) {
print ' (<a href="phpinfo.php" target="_blank">'.$langs->trans("MoreInformation").'</a>)';
}
print "<br>\n";
// Check PHP support for $_GET and $_POST
if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) // We must keep $_GET and $_POST here
{
if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
print '<img src="../theme/eldy/img/warning.png" alt="Warning"> '.$langs->trans("PHPSupportPOSTGETKo");
print ' (<a href="'.$_SERVER["PHP_SELF"].'?testget=ok">'.$langs->trans("Recheck").'</a>)';
print "<br>\n";
@ -106,8 +108,7 @@ if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) // We must keep $_GE
// Check if session_id is enabled
if (!function_exists("session_id"))
{
if (!function_exists("session_id")) {
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
$checksok = 0;
} else {
@ -116,8 +117,7 @@ if (!function_exists("session_id"))
// Check if GD is supported (we need GD for image conversion)
if (!function_exists("imagecreate"))
{
if (!function_exists("imagecreate")) {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportGD")."<br>\n";
// $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
@ -127,8 +127,7 @@ if (!function_exists("imagecreate"))
// Check if Curl is supported
if (!function_exists("curl_init"))
{
if (!function_exists("curl_init")) {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCurl")."<br>\n";
// $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
@ -137,8 +136,7 @@ if (!function_exists("curl_init"))
}
// Check if PHP calendar extension is available
if (!function_exists("easter_date"))
{
if (!function_exists("easter_date")) {
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCalendar")."<br>\n";
} else {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
@ -146,8 +144,7 @@ if (!function_exists("easter_date"))
// Check if UTF8 is supported
if (!function_exists("utf8_encode"))
{
if (!function_exists("utf8_encode")) {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportUTF8")."<br>\n";
// $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
@ -157,10 +154,8 @@ if (!function_exists("utf8_encode"))
// Check if intl methods are supported
if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost')
{
if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region"))
{
if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportIntl")."<br>\n";
// $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
@ -169,8 +164,7 @@ if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@loc
}
}
if (!class_exists('ZipArchive'))
{
if (!class_exists('ZipArchive')) {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
// $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
@ -183,17 +177,20 @@ $memrequiredorig = '64M';
$memrequired = 64 * 1024 * 1024;
$memmaxorig = @ini_get("memory_limit");
$memmax = @ini_get("memory_limit");
if ($memmaxorig != '')
{
if ($memmaxorig != '') {
preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
if ($reg[2])
{
if (strtoupper($reg[2]) == 'G') $memmax = $reg[1] * 1024 * 1024 * 1024;
if (strtoupper($reg[2]) == 'M') $memmax = $reg[1] * 1024 * 1024;
if (strtoupper($reg[2]) == 'K') $memmax = $reg[1] * 1024;
if ($reg[2]) {
if (strtoupper($reg[2]) == 'G') {
$memmax = $reg[1] * 1024 * 1024 * 1024;
}
if (strtoupper($reg[2]) == 'M') {
$memmax = $reg[1] * 1024 * 1024;
}
if (strtoupper($reg[2]) == 'K') {
$memmax = $reg[1] * 1024;
}
}
if ($memmax >= $memrequired || $memmax == -1)
{
if ($memmax >= $memrequired || $memmax == -1) {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
} else {
print '<img src="../theme/eldy/img/warning.png" alt="Warning"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
@ -203,15 +200,13 @@ if ($memmaxorig != '')
// If that config file is present and filled
clearstatcache();
if (is_readable($conffile) && filesize($conffile) > 8)
{
if (is_readable($conffile) && filesize($conffile) > 8) {
dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
$confexists = 1;
include_once $conffile;
$databaseok = 1;
if ($databaseok)
{
if ($databaseok) {
// Already installed for all parts (config and database). We can propose upgrade.
$allowupgrade = true;
} else {
@ -223,8 +218,7 @@ if (is_readable($conffile) && filesize($conffile) > 8)
$confexists = 0;
// First we try by copying example
if (@copy($conffile.".example", $conffile))
{
if (@copy($conffile.".example", $conffile)) {
// Success
dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
} else {
@ -232,12 +226,13 @@ if (is_readable($conffile) && filesize($conffile) > 8)
dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
$fp = @fopen($conffile, "w");
if ($fp)
{
if ($fp) {
@fwrite($fp, '<?php');
@fputs($fp, "\n");
fclose($fp);
} else dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
} else {
dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
}
}
// First install: no upgrade necessary/required
@ -247,8 +242,7 @@ if (is_readable($conffile) && filesize($conffile) > 8)
// File is missing and cannot be created
if (!file_exists($conffile))
{
if (!file_exists($conffile)) {
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
print "<br><br>";
print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
@ -257,17 +251,13 @@ if (!file_exists($conffile))
print $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok');
$err++;
} else {
if (dol_is_dir($conffile))
{
if (dol_is_dir($conffile)) {
print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
$allowinstall = 0;
}
// File exists but cannot be modified
elseif (!is_writable($conffile))
{
if ($confexists)
{
} elseif (!is_writable($conffile)) {
// File exists but cannot be modified
if ($confexists) {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
} else {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
@ -277,11 +267,9 @@ if (!file_exists($conffile))
print "<br>\n";
$allowinstall = 0;
}
// File exists and can be modified
else {
if ($confexists)
{
} else {
// File exists and can be modified
if ($confexists) {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
} else {
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
@ -295,32 +283,28 @@ if (!file_exists($conffile))
print "<br>\n";
// Requirements met/all ok: display the next step button
if ($checksok)
{
if ($checksok) {
$ok = 0;
// Try to create db connection
if (file_exists($conffile))
{
if (file_exists($conffile)) {
include_once $conffile;
if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root))
{
if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php"))
{
if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
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";
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);
} else {
require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
// If password is encoded, we decode it
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
if (preg_match('/crypted:/i', $dolibarr_main_db_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
$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 crypted
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
} else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
} else {
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
}
}
// $conf already created in inc.php
@ -331,8 +315,7 @@ if (!file_exists($conffile))
$conf->db->user = $dolibarr_main_db_user;
$conf->db->pass = $dolibarr_main_db_pass;
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
if ($db->connected && $db->database_selected)
{
if ($db->connected && $db->database_selected) {
$ok = true;
}
}
@ -340,16 +323,21 @@ if (!file_exists($conffile))
}
// If database access is available, we set more variables
if ($ok)
{
if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0;
if ($ok) {
if (empty($dolibarr_main_db_encryption)) {
$dolibarr_main_db_encryption = 0;
}
$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = '';
if (empty($dolibarr_main_db_cryptkey)) {
$dolibarr_main_db_cryptkey = '';
}
$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
$conf->setValues($db);
// Reset forced setup after the setValues
if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
if (defined('SYSLOG_FILE')) {
$conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
}
$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
// Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
@ -359,14 +347,15 @@ if (!file_exists($conffile))
}
// Show title
if (!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || !empty($conf->global->MAIN_VERSION_LAST_INSTALL))
{
if (!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || !empty($conf->global->MAIN_VERSION_LAST_INSTALL)) {
print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.(empty($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE).'</span></b> - ';
print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
//print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
print '<br>';
print '<br>';
} else print "<br>\n";
} else {
print "<br>\n";
}
//print $langs->trans("InstallEasy")." ";
print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
@ -376,8 +365,7 @@ if (!file_exists($conffile))
$available_choices = array();
$notavailable_choices = array();
if (empty($dolibarr_main_db_host)) // This means install process was not run
{
if (empty($dolibarr_main_db_host)) { // This means install process was not run
$foundrecommandedchoice = 1; // To show only once
}
@ -387,8 +375,7 @@ if (!file_exists($conffile))
$choice .= '</td>';
$choice .= '<td class="listofchoicesdesc">';
$choice .= $langs->trans("FreshInstallDesc");
if (empty($dolibarr_main_db_host)) // This means install process was not run
{
if (empty($dolibarr_main_db_host)) { // This means install process was not run
$choice .= '<br>';
//print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
$choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
@ -397,8 +384,7 @@ if (!file_exists($conffile))
$choice .= '</td>';
$choice .= '<td class="center">';
if ($allowinstall)
{
if ($allowinstall) {
$choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
} else {
$choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
@ -415,12 +401,15 @@ if (!file_exists($conffile))
// Show upgrade lines
$allowupgrade = true;
if (empty($dolibarr_main_db_host)) // This means install process was not run
{
if (empty($dolibarr_main_db_host)) { // This means install process was not run
$allowupgrade = false;
}
if (defined("MAIN_NOT_INSTALLED")) $allowupgrade = false;
if (GETPOST('allowupgrade')) $allowupgrade = true;
if (defined("MAIN_NOT_INSTALLED")) {
$allowupgrade = false;
}
if (GETPOST('allowupgrade')) {
$allowupgrade = true;
}
$migrationscript = array(array('from'=>'3.0.0', 'to'=>'3.1.0'),
array('from'=>'3.1.0', 'to'=>'3.2.0'),
array('from'=>'3.2.0', 'to'=>'3.3.0'),
@ -444,8 +433,7 @@ if (!file_exists($conffile))
);
$count = 0;
foreach ($migrationscript as $migarray)
{
foreach ($migrationscript as $migarray) {
$choice = '';
$count++;
@ -460,20 +448,16 @@ if (!file_exists($conffile))
$newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
$newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
$newversionfrombis = '';
if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) // From x.y.z -> x.y.z+1
{
if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
$newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
}
if ($ok)
{
if (count($dolibarrlastupgradeversionarray) >= 2) // If database access is available and last upgrade version is known
{
// Now we check if this is the first qualified choice
if ($ok) {
if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
// Now we check if this is the first qualified choice
if ($allowupgrade && empty($foundrecommandedchoice) &&
(versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
)
{
) {
$foundrecommandedchoice = 1; // To show only once
$recommended_choice = true;
}
@ -489,14 +473,12 @@ if (!file_exists($conffile))
$choice .= '<td class="listofchoicesdesc">';
$choice .= $langs->trans("UpgradeDesc");
if ($recommended_choice)
{
if ($recommended_choice) {
$choice .= '<br>';
//print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
$choice .= '<div class="center">';
$choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
if ($count < count($migarray)) // There are other choices after
{
if ($count < count($migarray)) { // There are other choices after
print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
}
$choice .= '</div>';
@ -504,19 +486,15 @@ if (!file_exists($conffile))
$choice .= '</td>';
$choice .= '<td class="center">';
if ($allowupgrade)
{
if ($allowupgrade) {
$disabled = false;
if ($foundrecommandedchoice == 2)
{
if ($foundrecommandedchoice == 2) {
$disabled = true;
}
if ($foundrecommandedchoice == 1)
{
if ($foundrecommandedchoice == 1) {
$foundrecommandedchoice = 2;
}
if ($disabled)
{
if ($disabled) {
$choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
} else {
$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>';
@ -535,8 +513,7 @@ if (!file_exists($conffile))
}
// If there is no choice at all, we show all of them.
if (empty($available_choices))
{
if (empty($available_choices)) {
$available_choices = $notavailable_choices;
$notavailable_choices = array();
}

View File

@ -32,8 +32,7 @@ global $langs;
$err = 0;
// If the config file exists and is filled, we're not on first install so we skip the language selection page
if (file_exists($conffile) && isset($dolibarr_main_url_root))
{
if (file_exists($conffile) && isset($dolibarr_main_url_root)) {
header("Location: check.php?testget=ok");
exit;
}
@ -65,4 +64,6 @@ print '</table></div>';
print '<br><br><span class="opacitymedium">'.$langs->trans("SomeTranslationAreUncomplete").'</span>';
// If there's no error, we display the next step button
if ($err == 0) pFooter(0);
if ($err == 0) {
pFooter(0);
}

View File

@ -35,12 +35,16 @@ function checkElementExist($id, $table)
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$table;
$sql .= ' WHERE rowid = '.$id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0) return true;
else return false;
} else return true; // for security
if ($num > 0) {
return true;
} else {
return false;
}
} else {
return true; // for security
}
}
/**
@ -60,28 +64,37 @@ function checkLinkedElements($sourcetype, $targettype)
$sourcetable = $sourcetype;
$targettable = $targettype;
if ($sourcetype == 'shipping') $sourcetable = 'expedition';
elseif ($targettype == 'shipping') $targettable = 'expedition';
if ($sourcetype == 'delivery') $sourcetable = 'livraison';
elseif ($targettype == 'delivery') $targettable = 'livraison';
if ($sourcetype == 'order_supplier') $sourcetable = 'commande_fournisseur';
elseif ($targettype == 'order_supplier') $targettable = 'commande_fournisseur';
if ($sourcetype == 'invoice_supplier') $sourcetable = 'facture_fourn';
elseif ($targettype == 'invoice_supplier') $targettable = 'facture_fourn';
if ($sourcetype == 'shipping') {
$sourcetable = 'expedition';
} elseif ($targettype == 'shipping') {
$targettable = 'expedition';
}
if ($sourcetype == 'delivery') {
$sourcetable = 'livraison';
} elseif ($targettype == 'delivery') {
$targettable = 'livraison';
}
if ($sourcetype == 'order_supplier') {
$sourcetable = 'commande_fournisseur';
} elseif ($targettype == 'order_supplier') {
$targettable = 'commande_fournisseur';
}
if ($sourcetype == 'invoice_supplier') {
$sourcetable = 'facture_fourn';
} elseif ($targettype == 'invoice_supplier') {
$targettable = 'facture_fourn';
}
$out = $langs->trans('SourceType').': '.$sourcetype.' => '.$langs->trans('TargetType').': '.$targettype.' ';
$sql = 'SELECT rowid, fk_source, fk_target FROM '.MAIN_DB_PREFIX.'element_element';
$sql .= ' WHERE sourcetype="'.$sourcetype.'" AND targettype="'.$targettype.'"';
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
$elements[$obj->rowid] = array($sourcetype => $obj->fk_source, $targettype => $obj->fk_target);
$i++;
@ -89,12 +102,9 @@ function checkLinkedElements($sourcetype, $targettype)
}
}
if (!empty($elements))
{
foreach ($elements as $key => $element)
{
if (!checkElementExist($element[$sourcetype], $sourcetable) || !checkElementExist($element[$targettype], $targettable))
{
if (!empty($elements)) {
foreach ($elements as $key => $element) {
if (!checkElementExist($element[$sourcetype], $sourcetable) || !checkElementExist($element[$targettype], $targettable)) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'element_element';
$sql .= ' WHERE rowid = '.$key;
$resql = $db->query($sql);
@ -103,8 +113,11 @@ function checkLinkedElements($sourcetype, $targettype)
}
}
if ($deleted) $out .= '('.$langs->trans('LinkedElementsInvalidDeleted', $deleted).')<br>';
else $out .= '('.$langs->trans('NothingToDelete').')<br>';
if ($deleted) {
$out .= '('.$langs->trans('LinkedElementsInvalidDeleted', $deleted).')<br>';
} else {
$out .= '('.$langs->trans('NothingToDelete').')<br>';
}
return $out;
}
@ -121,22 +134,23 @@ function clean_data_ecm_directories()
// Clean data from ecm_directories
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."ecm_directories";
$resql = $db->query($sql);
if ($resql)
{
while ($obj = $db->fetch_object($resql))
{
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$id = $obj->rowid;
$label = $obj->label;
$newlabel = dol_sanitizeFileName($label);
if ($label != $newlabel)
{
if ($label != $newlabel) {
$sqlupdate = "UPDATE ".MAIN_DB_PREFIX."ecm_directories set label='".$db->escape($newlabel)."' WHERE rowid=".$id;
print '<tr><td>'.$sqlupdate."</td></tr>\n";
$resqlupdate = $db->query($sqlupdate);
if (!$resqlupdate) dol_print_error($db, 'Failed to update');
if (!$resqlupdate) {
dol_print_error($db, 'Failed to update');
}
}
}
} else dol_print_error($db, 'Failed to run request');
} else {
dol_print_error($db, 'Failed to run request');
}
return;
}

View File

@ -75,14 +75,18 @@ $_SESSION['dol_save_pass'] = $db_pass;
// Now we load forced values from install.forced.php file.
$useforcedwizard = false;
$forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") {
$forcedfile = "/etc/dolibarr/install.forced.php";
}
if (@file_exists($forcedfile)) {
$useforcedwizard = true;
include_once $forcedfile;
// If forced install is enabled, replace the post values. These are empty because form fields are disabled.
if ($force_install_noedit) {
$main_dir = detect_dolibarr_main_document_root();
if (!empty($argv[1])) $main_dir = $argv[1]; // override when executing the script in command line
if (!empty($argv[1])) {
$main_dir = $argv[1]; // override when executing the script in command line
}
if (!empty($force_install_main_data_root)) {
$main_data_dir = $force_install_main_data_root;
} else {
@ -148,8 +152,7 @@ dolibarr_install_syslog("--- step1: entering step1.php page");
pHeader($langs->trans("ConfigurationFile"), "step2");
// Test if we can run a first install process
if (!is_writable($conffile))
{
if (!is_writable($conffile)) {
print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
pFooter(1, $setuplang, 'jscheckparam');
exit;
@ -158,57 +161,48 @@ if (!is_writable($conffile))
// Check parameters
$is_sqlite = false;
if (empty($db_type))
{
if (empty($db_type)) {
print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseType")).'</div>';
$error++;
} else {
$is_sqlite = ($db_type === 'sqlite' || $db_type === 'sqlite3');
}
if (empty($db_host) && !$is_sqlite)
{
if (empty($db_host) && !$is_sqlite) {
print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Server")).'</div>';
$error++;
}
if (empty($db_name))
{
if (empty($db_name)) {
print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("DatabaseName")).'</div>';
$error++;
}
if (empty($db_user) && !$is_sqlite)
{
if (empty($db_user) && !$is_sqlite) {
print '<div class="error">'.$langs->trans("ErrorFieldRequired", $langs->transnoentities("Login")).'</div>';
$error++;
}
if (!empty($db_port) && !is_numeric($db_port))
{
if (!empty($db_port) && !is_numeric($db_port)) {
print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_port, $langs->transnoentities("Port")).'</div>';
$error++;
}
if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix))
{
if (!empty($db_prefix) && !preg_match('/^[a-z0-9]+_$/i', $db_prefix)) {
print '<div class="error">'.$langs->trans("ErrorBadValueForParameter", $db_prefix, $langs->transnoentities("DatabasePrefix")).'</div>';
$error++;
}
// Remove last / into dans main_dir
if (substr($main_dir, dol_strlen($main_dir) - 1) == "/")
{
if (substr($main_dir, dol_strlen($main_dir) - 1) == "/") {
$main_dir = substr($main_dir, 0, dol_strlen($main_dir) - 1);
}
// Remove last / into dans main_url
if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/")
{
if (!empty($main_url) && substr($main_url, dol_strlen($main_url) - 1) == "/") {
$main_url = substr($main_url, 0, dol_strlen($main_url) - 1);
}
// Test database connection
if (!$error) {
$result = @include_once $main_dir."/core/db/".$db_type.'.class.php';
if ($result)
{
if ($result) {
// If we require database or user creation we need to connect as root, so we need root login credentials
if (!empty($db_create_database) && !$userroot) {
print '<div class="error">'.$langs->trans("YouAskDatabaseCreationSoDolibarrNeedToConnect", $db_name).'</div>';
@ -229,11 +223,9 @@ if (!$error) {
if (!$error && (!empty($db_create_database) || !empty($db_create_user))) {
$databasefortest = $db_name;
if (!empty($db_create_database)) {
if ($db_type == 'mysql' || $db_type == 'mysqli')
{
if ($db_type == 'mysql' || $db_type == 'mysqli') {
$databasefortest = 'mysql';
} elseif ($db_type == 'pgsql')
{
} elseif ($db_type == 'pgsql') {
$databasefortest = 'postgres';
} else {
$databasefortest = 'master';
@ -249,14 +241,21 @@ if (!$error) {
if (empty($db_create_database) && $db->connected && !$db->database_selected) {
print '<div class="error">'.$langs->trans("ErrorConnectedButDatabaseNotFound", $db_name).'</div>';
print '<br>';
if (!$db->connected) print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
if (!$db->connected) {
print $langs->trans("IfDatabaseNotExistsGoBackAndUncheckCreate").'<br><br>';
}
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
} elseif ($db->error && !(!empty($db_create_database) && $db->connected)) {
// Note: you may experience error here with message "No such file or directory" when mysql was installed for the first time but not yet launched.
if ($db->error == "No such file or directory") print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
else print '<div class="error">'.$db->error.'</div>';
if (!$db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
if ($db->error == "No such file or directory") {
print '<div class="error">'.$langs->trans("ErrorToConnectToMysqlCheckInstance").'</div>';
} else {
print '<div class="error">'.$db->error.'</div>';
}
if (!$db->connected) {
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
}
//print '<a href="#" onClick="javascript: history.back();">';
print $langs->trans("ErrorGoBackAndCorrectParameters");
//print '</a>';
@ -267,10 +266,11 @@ if (!$error) {
if (!$error && (empty($db_create_database) && empty($db_create_user))) {
$db = getDoliDBInstance($db_type, $db_host, $db_user, $db_pass, $db_name, $db_port);
if ($db->error)
{
if ($db->error) {
print '<div class="error">'.$db->error.'</div>';
if (!$db->connected) print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
if (!$db->connected) {
print $langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
}
//print '<a href="#" onClick="javascript: history.back();">';
print $langs->trans("ErrorGoBackAndCorrectParameters");
//print '</a>';
@ -286,18 +286,20 @@ if (!$error) {
$error++;
}
} else {
if (isset($db)) print $db->lasterror();
if (isset($db) && !$db->connected) print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
if (isset($db)) {
print $db->lasterror();
}
if (isset($db) && !$db->connected) {
print '<br>'.$langs->trans("BecauseConnectionFailedParametersMayBeWrong").'<br><br>';
}
print $langs->trans("ErrorGoBackAndCorrectParameters");
$error++;
}
if (!$error && $db->connected)
{
if (!$error && $db->connected) {
if (!empty($db_create_database)) {
$result = $db->select_db($db_name);
if ($result)
{
if ($result) {
print '<div class="error">'.$langs->trans("ErrorDatabaseAlreadyExists", $db_name).'</div>';
print $langs->trans("IfDatabaseExistsGoBackAndCheckCreate").'<br><br>';
print $langs->trans("ErrorGoBackAndCorrectParameters");
@ -307,11 +309,9 @@ if (!$error && $db->connected)
}
// Define $defaultCharacterSet and $defaultDBSortingCollation
if (!$error && $db->connected)
{
if (!empty($db_create_database)) // If we create database, we force default value
{
// Default values come from the database handler
if (!$error && $db->connected) {
if (!empty($db_create_database)) { // If we create database, we force default value
// Default values come from the database handler
$defaultCharacterSet = $db->forcecharset;
$defaultDBSortingCollation = $db->forcecollate;
@ -323,8 +323,7 @@ if (!$error && $db->connected)
// Force to avoid utf8mb4 because index on field char 255 reach limit of 767 char for indexes (example with mysql 5.6.34 = mariadb 10.0.29)
// TODO Remove this when utf8mb4 is supported
if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci')
{
if ($defaultCharacterSet == 'utf8mb4' || $defaultDBSortingCollation == 'utf8mb4_unicode_ci') {
$defaultCharacterSet = 'utf8';
$defaultDBSortingCollation = 'utf8_unicode_ci';
}
@ -338,13 +337,10 @@ if (!$error && $db->connected)
// Create config file
if (!$error && $db->connected && $action == "set")
{
if (!$error && $db->connected && $action == "set") {
umask(0);
if (is_array($_POST))
{
foreach ($_POST as $key => $value)
{
if (is_array($_POST)) {
foreach ($_POST as $key => $value) {
if (!preg_match('/^db_pass/i', $key)) {
dolibarr_install_syslog("step1: choice for ".$key." = ".$value);
}
@ -356,10 +352,8 @@ if (!$error && $db->connected && $action == "set")
print '<table cellspacing="0" width="100%" cellpadding="1" border="0">';
// Check parameter main_dir
if (!$error)
{
if (!is_dir($main_dir))
{
if (!$error) {
if (!is_dir($main_dir)) {
dolibarr_install_syslog("step1: directory '".$main_dir."' is unavailable or can't be accessed");
print "<tr><td>";
@ -373,23 +367,19 @@ if (!$error && $db->connected && $action == "set")
}
}
if (!$error)
{
if (!$error) {
dolibarr_install_syslog("step1: directory '".$main_dir."' exists");
}
// Create subdirectory main_data_dir
if (!$error)
{
if (!$error) {
// Create directory for documents
if (!is_dir($main_data_dir))
{
if (!is_dir($main_data_dir)) {
dol_mkdir($main_data_dir);
}
if (!is_dir($main_data_dir))
{
if (!is_dir($main_data_dir)) {
print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
print '</td><td>';
@ -400,12 +390,10 @@ if (!$error && $db->connected && $action == "set")
} else {
// Create .htaccess file in document directory
$pathhtaccess = $main_data_dir.'/.htaccess';
if (!file_exists($pathhtaccess))
{
if (!file_exists($pathhtaccess)) {
dolibarr_install_syslog("step1: .htaccess file did not exist, we created it in '".$main_data_dir."'");
$handlehtaccess = @fopen($pathhtaccess, 'w');
if ($handlehtaccess)
{
if ($handlehtaccess) {
fwrite($handlehtaccess, 'Order allow,deny'."\n");
fwrite($handlehtaccess, 'Deny from all'."\n");
@ -427,14 +415,11 @@ if (!$error && $db->connected && $action == "set")
// Loop on each directory of dir [] to create them if they do not exist
$num = count($dir);
for ($i = 0; $i < $num; $i++)
{
if (is_dir($dir[$i]))
{
for ($i = 0; $i < $num; $i++) {
if (is_dir($dir[$i])) {
dolibarr_install_syslog("step1: directory '".$dir[$i]."' exists");
} else {
if (dol_mkdir($dir[$i]) < 0)
{
if (dol_mkdir($dir[$i]) < 0) {
print "<tr><td>";
print "Failed to create directory: ".$dir[$i];
print '</td><td>';
@ -454,8 +439,7 @@ if (!$error && $db->connected && $action == "set")
$destroot = $main_data_dir.'/medias';
dolCopyDir($srcroot, $destroot, 0, 0);
if ($error)
{
if ($error) {
print "<tr><td>".$langs->trans("ErrorDirDoesNotExists", $main_data_dir);
print ' '.$langs->trans("YouMustCreateItAndAllowServerToWrite");
print '</td><td>';
@ -480,16 +464,14 @@ if (!$error && $db->connected && $action == "set")
'usergroups' => 'usergroups',
'users' => 'user',
);
foreach ($docs as $cursordir => $cursorfile)
{
foreach ($docs as $cursordir => $cursorfile) {
$src = $srcroot.'/'.$cursordir.'/template_'.$cursorfile.'.odt';
$dirodt = $destroot.'/'.$cursordir;
$dest = $dirodt.'/template_'.$cursorfile.'.odt';
dol_mkdir($dirodt);
$result = dol_copy($src, $dest, 0, 0);
if ($result < 0)
{
if ($result < 0) {
print '<tr><td colspan="2"><br>'.$langs->trans('ErrorFailToCopyFile', $src, $dest).'</td></tr>';
}
}
@ -501,11 +483,9 @@ if (!$error && $db->connected && $action == "set")
$main_db_prefix = (!empty($db_prefix) ? $db_prefix : 'llx_');
// Write conf file on disk
if (!$error)
{
if (!$error) {
// Save old conf file on disk
if (file_exists("$conffile"))
{
if (file_exists("$conffile")) {
// We must ignore errors as an existing old file may already exist and not be replaceable or
// the installer (like for ubuntu) may not have permission to create another file than conf.php.
// Also no other process must be able to read file or we expose the new file, so content with password.
@ -516,8 +496,7 @@ if (!$error && $db->connected && $action == "set")
}
// Create database and admin user database
if (!$error)
{
if (!$error) {
// We reload configuration file
conf($dolibarr_main_document_root);
@ -532,14 +511,11 @@ if (!$error && $db->connected && $action == "set")
//print $conf->db->host." , ".$conf->db->name." , ".$conf->db->user." , ".$conf->db->port;
$databasefortest = $conf->db->name;
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli')
{
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') {
$databasefortest = 'mysql';
} elseif ($conf->db->type == 'pgsql')
{
} elseif ($conf->db->type == 'pgsql') {
$databasefortest = 'postgres';
} elseif ($conf->db->type == 'mssql')
{
} elseif ($conf->db->type == 'mssql') {
$databasefortest = 'master';
}
@ -547,32 +523,26 @@ if (!$error && $db->connected && $action == "set")
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, $databasefortest, $conf->db->port);
if ($db->error)
{
if ($db->error) {
print '<div class="error">'.$db->error.'</div>';
$error++;
}
if (!$error)
{
if ($db->connected)
{
if (!$error) {
if ($db->connected) {
$resultbis = 1;
// Create user
$result = $db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
// Create user bis
if ($databasefortest == 'mysql')
{
if (!in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local')))
{
if ($databasefortest == 'mysql') {
if (!in_array($dolibarr_main_db_host, array('127.0.0.1', '::1', 'localhost', 'localhost.local'))) {
$resultbis = $db->DDLCreateUser('%', $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
}
}
if ($result > 0 && $resultbis > 0)
{
if ($result > 0 && $resultbis > 0) {
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
@ -581,8 +551,7 @@ if (!$error && $db->connected && $action == "set")
} else {
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
|| $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'
|| $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS')
{
|| $db->errno() == 'DB_ERROR_USER_ALREADY_EXISTS') {
dolibarr_install_syslog("step1: user already exists");
print '<tr><td>';
print $langs->trans("UserCreation").' : ';
@ -628,12 +597,10 @@ if (!$error && $db->connected && $action == "set")
$newdb = getDoliDBInstance($conf->db->type, $conf->db->host, $userroot, $passroot, '', $conf->db->port);
//print 'eee'.$conf->db->type." ".$conf->db->host." ".$userroot." ".$passroot." ".$conf->db->port." ".$newdb->connected." ".$newdb->forcecharset;exit;
if ($newdb->connected)
{
if ($newdb->connected) {
$result = $newdb->DDLCreateDb($dolibarr_main_db_name, $dolibarr_main_db_character_set, $dolibarr_main_db_collation, $dolibarr_main_db_user);
if ($result)
{
if ($result) {
print '<tr><td>';
print $langs->trans("DatabaseCreation")." (".$langs->trans("User")." ".$userroot.") : ";
print $dolibarr_main_db_name;
@ -683,15 +650,13 @@ if (!$error && $db->connected && $action == "set")
// We test access with dolibarr database user (not admin)
if (!$error)
{
if (!$error) {
dolibarr_install_syslog("step1: connection type=".$conf->db->type." on host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name);
//print "connexion de type=".$conf->db->type." sur host=".$conf->db->host." port=".$conf->db->port." user=".$conf->db->user." name=".$conf->db->name;
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
if ($db->connected)
{
if ($db->connected) {
dolibarr_install_syslog("step1: connection to server by user ".$conf->db->user." ok");
print "<tr><td>";
print $langs->trans("ServerConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
@ -701,8 +666,7 @@ if (!$error && $db->connected && $action == "set")
print "</td></tr>";
// server access ok, basic access ok
if ($db->database_selected)
{
if ($db->database_selected) {
dolibarr_install_syslog("step1: connection to database ".$conf->db->name." by user ".$conf->db->user." ok");
print "<tr><td>";
print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
@ -773,7 +737,9 @@ function jsinfo()
<?php
$ret = 0;
if ($error && isset($argv[1])) $ret = 1;
if ($error && isset($argv[1])) {
$ret = 1;
}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("--- step1: end");
@ -781,7 +747,9 @@ dolibarr_install_syslog("--- step1: end");
pFooter($error ? 1 : 0, $setuplang, 'jsinfo', 1);
// Return code if ran from command line
if ($ret) exit($ret);
if ($ret) {
exit($ret);
}
/**
@ -794,8 +762,7 @@ if ($ret) exit($ret);
function write_main_file($mainfile, $main_dir)
{
$fp = @fopen("$mainfile", "w");
if ($fp)
{
if ($fp) {
clearstatcache();
fputs($fp, '<?php'."\n");
fputs($fp, "// Wrapper to include main into htdocs\n");
@ -815,8 +782,7 @@ function write_main_file($mainfile, $main_dir)
function write_master_file($masterfile, $main_dir)
{
$fp = @fopen("$masterfile", "w");
if ($fp)
{
if ($fp) {
clearstatcache();
fputs($fp, '<?php'."\n");
fputs($fp, "// Wrapper to include master into htdocs\n");
@ -854,8 +820,7 @@ function write_conf_file($conffile)
$key = md5(uniqid(mt_rand(), true)); // Generate random hash
$fp = fopen("$conffile", "w");
if ($fp)
{
if ($fp) {
clearstatcache();
fputs($fp, '<?php'."\n");
@ -940,49 +905,77 @@ function write_conf_file($conffile)
// Write params to overwrites default lib path
fputs($fp, "\n");
if (empty($force_dolibarr_lib_FPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH = ''; }
if (empty($force_dolibarr_lib_FPDF_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_FPDF_PATH = '';
}
fputs($fp, '$dolibarr_lib_FPDF_PATH=\''.$force_dolibarr_lib_FPDF_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_TCPDF_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH = ''; }
if (empty($force_dolibarr_lib_TCPDF_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_TCPDF_PATH = '';
}
fputs($fp, '$dolibarr_lib_TCPDF_PATH=\''.$force_dolibarr_lib_TCPDF_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_FPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH = ''; }
if (empty($force_dolibarr_lib_FPDI_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_FPDI_PATH = '';
}
fputs($fp, '$dolibarr_lib_FPDI_PATH=\''.$force_dolibarr_lib_FPDI_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_TCPDI_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH = ''; }
if (empty($force_dolibarr_lib_TCPDI_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_TCPDI_PATH = '';
}
fputs($fp, '$dolibarr_lib_TCPDI_PATH=\''.$force_dolibarr_lib_TCPDI_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_ADODB_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH = ''; }
if (empty($force_dolibarr_lib_ADODB_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_ADODB_PATH = '';
}
fputs($fp, '$dolibarr_lib_ADODB_PATH=\''.$force_dolibarr_lib_ADODB_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_GEOIP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH = ''; }
if (empty($force_dolibarr_lib_GEOIP_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_GEOIP_PATH = '';
}
fputs($fp, '$dolibarr_lib_GEOIP_PATH=\''.$force_dolibarr_lib_GEOIP_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_NUSOAP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH = ''; }
if (empty($force_dolibarr_lib_NUSOAP_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_NUSOAP_PATH = '';
}
fputs($fp, '$dolibarr_lib_NUSOAP_PATH=\''.$force_dolibarr_lib_NUSOAP_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_ODTPHP_PATH)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH = ''; }
if (empty($force_dolibarr_lib_ODTPHP_PATH)) {
fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATH = '';
}
fputs($fp, '$dolibarr_lib_ODTPHP_PATH=\''.$force_dolibarr_lib_ODTPHP_PATH.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) { fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = ''; }
if (empty($force_dolibarr_lib_ODTPHP_PATHTOPCLZIP)) {
fputs($fp, '//'); $force_dolibarr_lib_ODTPHP_PATHTOPCLZIP = '';
}
fputs($fp, '$dolibarr_lib_ODTPHP_PATHTOPCLZIP=\''.$force_dolibarr_lib_ODTPHP_PATHTOPCLZIP.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_js_CKEDITOR)) { fputs($fp, '//'); $force_dolibarr_js_CKEDITOR = ''; }
if (empty($force_dolibarr_js_CKEDITOR)) {
fputs($fp, '//'); $force_dolibarr_js_CKEDITOR = '';
}
fputs($fp, '$dolibarr_js_CKEDITOR=\''.$force_dolibarr_js_CKEDITOR.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_js_JQUERY)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY = ''; }
if (empty($force_dolibarr_js_JQUERY)) {
fputs($fp, '//'); $force_dolibarr_js_JQUERY = '';
}
fputs($fp, '$dolibarr_js_JQUERY=\''.$force_dolibarr_js_JQUERY.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_js_JQUERY_UI)) { fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI = ''; }
if (empty($force_dolibarr_js_JQUERY_UI)) {
fputs($fp, '//'); $force_dolibarr_js_JQUERY_UI = '';
}
fputs($fp, '$dolibarr_js_JQUERY_UI=\''.$force_dolibarr_js_JQUERY_UI.'\';');
fputs($fp, "\n");
// Write params to overwrites default font path
fputs($fp, "\n");
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF = ''; }
fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF)) {
fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF = '';
}
fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF=\''.$force_dolibarr_font_DOL_DEFAULT_TTF.'\';');
fputs($fp, "\n");
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) { fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = ''; }
if (empty($force_dolibarr_font_DOL_DEFAULT_TTF_BOLD)) {
fputs($fp, '//'); $force_dolibarr_font_DOL_DEFAULT_TTF_BOLD = '';
}
fputs($fp, '$dolibarr_font_DOL_DEFAULT_TTF_BOLD=\''.$force_dolibarr_font_DOL_DEFAULT_TTF_BOLD.'\';');
fputs($fp, "\n");
@ -992,8 +985,7 @@ function write_conf_file($conffile)
fclose($fp);
if (file_exists("$conffile"))
{
if (file_exists("$conffile")) {
include $conffile; // force config reload, do not put include_once
conf($dolibarr_main_document_root);

View File

@ -49,23 +49,37 @@ $langs->setDefaultLang($setuplang);
$langs->loadLangs(array("admin", "install"));
$choix = 0;
if ($dolibarr_main_db_type == "mysqli") $choix = 1;
if ($dolibarr_main_db_type == "pgsql") $choix = 2;
if ($dolibarr_main_db_type == "mssql") $choix = 3;
if ($dolibarr_main_db_type == "sqlite") $choix = 4;
if ($dolibarr_main_db_type == "sqlite3") $choix = 5;
if ($dolibarr_main_db_type == "mysqli") {
$choix = 1;
}
if ($dolibarr_main_db_type == "pgsql") {
$choix = 2;
}
if ($dolibarr_main_db_type == "mssql") {
$choix = 3;
}
if ($dolibarr_main_db_type == "sqlite") {
$choix = 4;
}
if ($dolibarr_main_db_type == "sqlite3") {
$choix = 5;
}
//if (empty($choix)) dol_print_error('','Database type '.$dolibarr_main_db_type.' not supported into step2.php page');
// Now we load forced values from install.forced.php file.
$useforcedwizard = false;
$forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") {
$forcedfile = "/etc/dolibarr/install.forced.php";
}
if (@file_exists($forcedfile)) {
$useforcedwizard = true;
include_once $forcedfile;
// test for travis
if (!empty($argv[1]) && $argv[1] == "set") $action = "set";
if (!empty($argv[1]) && $argv[1] == "set") {
$action = "set";
}
}
dolibarr_install_syslog("- step2: entering step2.php page");
@ -78,15 +92,13 @@ dolibarr_install_syslog("- step2: entering step2.php page");
pHeader($langs->trans("CreateDatabaseObjects"), "step4");
// Test if we can run a first install process
if (!is_writable($conffile))
{
if (!is_writable($conffile)) {
print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
pFooter(1, $setuplang, 'jscheckparam');
exit;
}
if ($action == "set")
{
if ($action == "set") {
print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans("Database").'</h3>';
print '<table cellspacing="0" style="padding: 4px 4px 4px 0" border="0" width="100%">';
@ -94,8 +106,7 @@ if ($action == "set")
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
if ($db->connected)
{
if ($db->connected) {
print "<tr><td>";
print $langs->trans("ServerConnection")." : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
$ok = 1;
@ -103,10 +114,8 @@ if ($action == "set")
print "<tr><td>Failed to connect to server : ".$conf->db->host.'</td><td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
}
if ($ok)
{
if ($db->database_selected)
{
if ($ok) {
if ($db->database_selected) {
dolibarr_install_syslog("step2: successful connection to database: ".$conf->db->name);
} else {
dolibarr_install_syslog("step2: failed connection to database :".$conf->db->name, LOG_ERR);
@ -117,8 +126,7 @@ if ($action == "set")
// Affiche version
if ($ok)
{
if ($ok) {
$version = $db->getVersion();
$versionarray = $db->getVersionArray();
print '<tr><td>'.$langs->trans("DatabaseVersion").'</td>';
@ -145,13 +153,12 @@ if ($action == "set")
/**************************************************************************************
*
* Chargement fichiers tables/*.sql (non *.key.sql)
* A faire avant les fichiers *.key.sql
*
***************************************************************************************/
if ($ok && $createtables)
{
*
* Chargement fichiers tables/*.sql (non *.key.sql)
* A faire avant les fichiers *.key.sql
*
***************************************************************************************/
if ($ok && $createtables) {
// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
$dir = "mysql/tables/";
@ -160,12 +167,9 @@ if ($action == "set")
dolibarr_install_syslog("step2: open tables directory ".$dir." handle=".$handle);
$tablefound = 0;
$tabledata = array();
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && !preg_match('/\.key\.sql$/i', $file)) {
$tablefound++;
$tabledata[] = $file;
}
@ -175,18 +179,14 @@ if ($action == "set")
// Sort list of sql files on alphabetical order (load order is important)
sort($tabledata);
foreach ($tabledata as $file)
{
foreach ($tabledata as $file) {
$name = substr($file, 0, dol_strlen($file) - 4);
$buffer = '';
$fp = fopen($dir.$file, "r");
if ($fp)
{
while (!feof($fp))
{
if ($fp) {
while (!feof($fp)) {
$buf = fgets($fp, 4096);
if (substr($buf, 0, 2) <> '--')
{
if (substr($buf, 0, 2) <> '--') {
$buf = preg_replace('/--(.+)*/', '', $buf);
$buffer .= $buf;
}
@ -194,8 +194,7 @@ if ($action == "set")
fclose($fp);
$buffer = trim($buffer);
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb
{
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') { // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb
$buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer);
} else {
// Keyword ENGINE is MySQL-specific, so scrub it for
@ -205,8 +204,7 @@ if ($action == "set")
}
// Replace the prefix tables
if ($dolibarr_main_db_prefix != 'llx_')
{
if ($dolibarr_main_db_prefix != 'llx_') {
$buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
}
@ -215,14 +213,12 @@ if ($action == "set")
dolibarr_install_syslog("step2: request: ".$buffer);
$resql = $db->query($buffer, 0, 'dml');
if ($resql)
{
if ($resql) {
// print "<td>OK requete ==== $buffer</td></tr>";
$db->free($resql);
} else {
if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' ||
$db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS')
{
$db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') {
//print "<td>Deja existante</td></tr>";
} else {
print "<tr><td>".$langs->trans("CreateTableAndPrimaryKey", $name);
@ -241,10 +237,8 @@ if ($action == "set")
}
}
if ($tablefound)
{
if ($error == 0)
{
if ($tablefound) {
if ($error == 0) {
print '<tr><td>';
print $langs->trans("TablesAndPrimaryKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
$ok = 1;
@ -257,13 +251,12 @@ if ($action == "set")
/***************************************************************************************
*
* Chargement fichiers tables/*.key.sql
* A faire apres les fichiers *.sql
*
***************************************************************************************/
if ($ok && $createkeys)
{
*
* Chargement fichiers tables/*.key.sql
* A faire apres les fichiers *.sql
*
***************************************************************************************/
if ($ok && $createkeys) {
// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
$dir = "mysql/tables/";
@ -272,12 +265,9 @@ if ($action == "set")
dolibarr_install_syslog("step2: open keys directory ".$dir." handle=".$handle);
$tablefound = 0;
$tabledata = array();
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file)) {
$tablefound++;
$tabledata[] = $file;
}
@ -287,40 +277,33 @@ if ($action == "set")
// Sort list of sql files on alphabetical order (load order is important)
sort($tabledata);
foreach ($tabledata as $file)
{
foreach ($tabledata as $file) {
$name = substr($file, 0, dol_strlen($file) - 4);
//print "<tr><td>Creation de la table $name</td>";
$buffer = '';
$fp = fopen($dir.$file, "r");
if ($fp)
{
while (!feof($fp))
{
if ($fp) {
while (!feof($fp)) {
$buf = fgets($fp, 4096);
// Special case of lines allowed for some version only
if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg))
{
if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) {
$versioncommande = explode('.', $reg[1]);
//print var_dump($versioncommande);
//print var_dump($versionarray);
if (count($versioncommande) && count($versionarray)
&& versioncompare($versioncommande, $versionarray) <= 0)
{
&& versioncompare($versioncommande, $versionarray) <= 0) {
// Version qualified, delete SQL comments
$buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf);
//print "Ligne $i qualifiee par version: ".$buf.'<br>';
}
}
if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg))
{
if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) {
$versioncommande = explode('.', $reg[1]);
//print var_dump($versioncommande);
//print var_dump($versionarray);
if (count($versioncommande) && count($versionarray)
&& versioncompare($versioncommande, $versionarray) <= 0)
{
&& versioncompare($versioncommande, $versionarray) <= 0) {
// Version qualified, delete SQL comments
$buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf);
//print "Ligne $i qualifiee par version: ".$buf.'<br>';
@ -328,20 +311,19 @@ if ($action == "set")
}
// Ajout ligne si non commentaire
if (!preg_match('/^--/i', $buf)) $buffer .= $buf;
if (!preg_match('/^--/i', $buf)) {
$buffer .= $buf;
}
}
fclose($fp);
// Si plusieurs requetes, on boucle sur chaque
$listesql = explode(';', $buffer);
foreach ($listesql as $req)
{
foreach ($listesql as $req) {
$buffer = trim($req);
if ($buffer)
{
if ($buffer) {
// Replace the prefix tables
if ($dolibarr_main_db_prefix != 'llx_')
{
if ($dolibarr_main_db_prefix != 'llx_') {
$buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
}
@ -350,8 +332,7 @@ if ($action == "set")
dolibarr_install_syslog("step2: request: ".$buffer);
$resql = $db->query($buffer, 0, 'dml');
if ($resql)
{
if ($resql) {
//print "<td>OK requete ==== $buffer</td></tr>";
$db->free($resql);
} else {
@ -359,8 +340,7 @@ if ($action == "set")
$db->errno() == 'DB_ERROR_CANNOT_CREATE' ||
$db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ||
$db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' ||
preg_match('/duplicate key name/i', $db->error()))
{
preg_match('/duplicate key name/i', $db->error())) {
//print "<td>Deja existante</td></tr>";
$key_exists = 1;
} else {
@ -382,8 +362,7 @@ if ($action == "set")
}
}
if ($tablefound && $error == 0)
{
if ($tablefound && $error == 0) {
print '<tr><td>';
print $langs->trans("OtherKeysCreation").'</td><td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
$okkeys = 1;
@ -392,32 +371,32 @@ if ($action == "set")
/***************************************************************************************
*
* Chargement fichier functions.sql
*
***************************************************************************************/
if ($ok && $createfunctions)
{
*
* Chargement fichier functions.sql
*
***************************************************************************************/
if ($ok && $createfunctions) {
// For this file, we use a directory according to database type
if ($choix == 1) $dir = "mysql/functions/";
elseif ($choix == 2) $dir = "pgsql/functions/";
elseif ($choix == 3) $dir = "mssql/functions/";
elseif ($choix == 4) { $dir = "sqlite3/functions/"; }
if ($choix == 1) {
$dir = "mysql/functions/";
} elseif ($choix == 2) {
$dir = "pgsql/functions/";
} elseif ($choix == 3) {
$dir = "mssql/functions/";
} elseif ($choix == 4) {
$dir = "sqlite3/functions/";
}
// Creation donnees
$file = "functions.sql";
if (file_exists($dir.$file))
{
if (file_exists($dir.$file)) {
$fp = fopen($dir.$file, "r");
dolibarr_install_syslog("step2: open function file ".$dir.$file." handle=".$fp);
if ($fp)
{
if ($fp) {
$buffer = '';
while (!feof($fp))
{
while (!feof($fp)) {
$buf = fgets($fp, 4096);
if (substr($buf, 0, 2) <> '--')
{
if (substr($buf, 0, 2) <> '--') {
$buffer .= $buf."§";
}
}
@ -427,27 +406,22 @@ if ($action == "set")
// If several requests, we loop on each of them
$listesql = explode('§', $buffer);
foreach ($listesql as $buffer)
{
foreach ($listesql as $buffer) {
$buffer = trim($buffer);
if ($buffer)
{
if ($buffer) {
// Replace the prefix in table names
if ($dolibarr_main_db_prefix != 'llx_')
{
if ($dolibarr_main_db_prefix != 'llx_') {
$buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
}
dolibarr_install_syslog("step2: request: ".$buffer);
print "<!-- Insert line : ".$buffer."<br>-->\n";
$resql = $db->query($buffer, 0, 'dml');
if ($resql)
{
if ($resql) {
$ok = 1;
$db->free($resql);
} else {
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS'
|| $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS')
{
|| $db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS') {
//print "Insert line : ".$buffer."<br>\n";
} else {
$ok = 0;
@ -463,8 +437,7 @@ if ($action == "set")
}
print "<tr><td>".$langs->trans("FunctionsCreation")."</td>";
if ($ok)
{
if ($ok) {
print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
} else {
print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
@ -475,12 +448,11 @@ if ($action == "set")
/***************************************************************************************
*
* Load files data/*.sql
*
***************************************************************************************/
if ($ok && $createdata)
{
*
* Load files data/*.sql
*
***************************************************************************************/
if ($ok && $createdata) {
// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax)
$dir = "mysql/data/";
@ -489,17 +461,15 @@ if ($action == "set")
dolibarr_install_syslog("step2: open directory data ".$dir." handle=".$handle);
$tablefound = 0;
$tabledata = array();
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file))
{
if (preg_match('/^llx_accounting_account_/', $file)) continue; // We discard data file of chart of account. Will be loaded when a chart is selected.
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file)) {
if (preg_match('/^llx_accounting_account_/', $file)) {
continue; // We discard data file of chart of account. Will be loaded when a chart is selected.
}
//print 'x'.$file.'-'.$createdata.'<br>';
if (is_numeric($createdata) || preg_match('/'.preg_quote($createdata).'/i', $file))
{
if (is_numeric($createdata) || preg_match('/'.preg_quote($createdata).'/i', $file)) {
$tablefound++;
$tabledata[] = $file;
}
@ -510,33 +480,33 @@ if ($action == "set")
// Sort list of data files on alphabetical order (load order is important)
sort($tabledata);
foreach ($tabledata as $file)
{
foreach ($tabledata as $file) {
$name = substr($file, 0, dol_strlen($file) - 4);
$fp = fopen($dir.$file, "r");
dolibarr_install_syslog("step2: open data file ".$dir.$file." handle=".$fp);
if ($fp)
{
if ($fp) {
$arrayofrequests = array();
$linefound = 0;
$linegroup = 0;
$sizeofgroup = 1; // Grouping request to have 1 query for several requests does not works with mysql, so we use 1.
// Load all requests
while (!feof($fp))
{
while (!feof($fp)) {
$buffer = fgets($fp, 4096);
$buffer = trim($buffer);
if ($buffer)
{
if (substr($buffer, 0, 2) == '--') continue;
if ($buffer) {
if (substr($buffer, 0, 2) == '--') {
continue;
}
if ($linefound && ($linefound % $sizeofgroup) == 0)
{
if ($linefound && ($linefound % $sizeofgroup) == 0) {
$linegroup++;
}
if (empty($arrayofrequests[$linegroup])) $arrayofrequests[$linegroup] = $buffer;
else $arrayofrequests[$linegroup] .= " ".$buffer;
if (empty($arrayofrequests[$linegroup])) {
$arrayofrequests[$linegroup] = $buffer;
} else {
$arrayofrequests[$linegroup] .= " ".$buffer;
}
$linefound++;
}
@ -549,22 +519,18 @@ if ($action == "set")
$db->begin();
// We loop on each requests of file
foreach ($arrayofrequests as $buffer)
{
foreach ($arrayofrequests as $buffer) {
// Replace the prefix tables
if ($dolibarr_main_db_prefix != 'llx_')
{
if ($dolibarr_main_db_prefix != 'llx_') {
$buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer);
}
//dolibarr_install_syslog("step2: request: " . $buffer);
$resql = $db->query($buffer, 1);
if ($resql)
{
if ($resql) {
//$db->free($resql); // Not required as request we launch here does not return memory needs.
} else {
if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
//print "<tr><td>Insertion ligne : $buffer</td><td>";
} else {
$ok = 0;
@ -574,14 +540,16 @@ if ($action == "set")
}
}
if ($okallfile) $db->commit();
else $db->rollback();
if ($okallfile) {
$db->commit();
} else {
$db->rollback();
}
}
}
print "<tr><td>".$langs->trans("ReferenceDataLoading")."</td>";
if ($ok)
{
if ($ok) {
print '<td><img src="../theme/eldy/img/tick.png" alt="Ok"></td></tr>';
} else {
print '<td><img src="../theme/eldy/img/error.png" alt="Error"></td></tr>';
@ -595,7 +563,9 @@ if ($action == "set")
$ret = 0;
if (!$ok && isset($argv[1])) $ret = 1;
if (!$ok && isset($argv[1])) {
$ret = 1;
}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("- step2: end");
@ -621,7 +591,11 @@ print $out;
pFooter($ok ? 0 : 1, $setuplang);
if (isset($db) && is_object($db)) $db->close();
if (isset($db) && is_object($db)) {
$db->close();
}
// Return code if ran from command line
if ($ret) exit($ret);
if ($ret) {
exit($ret);
}

View File

@ -40,7 +40,9 @@ $langs->loadLangs(array("admin", "install"));
// Now we load forced value from install.forced.php file.
$useforcedwizard = false;
$forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") {
$forcedfile = "/etc/dolibarr/install.forced.php";
}
if (@file_exists($forcedfile)) {
$useforcedwizard = true;
include_once $forcedfile;
@ -60,8 +62,7 @@ $ok = 0;
pHeader($langs->trans("AdminAccountCreation"), "step5");
// Test if we can run a first install process
if (!is_writable($conffile))
{
if (!is_writable($conffile)) {
print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
pFooter(1, $setuplang, 'jscheckparam');
exit;
@ -77,8 +78,7 @@ print '<table cellspacing="0" cellpadding="2">';
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
if ($db->ok)
{
if ($db->ok) {
print '<tr><td><label for="login">'.$langs->trans("Login").' :</label></td><td>';
print '<input id="login" name="login" type="text" value="'.(!empty($_GET["login"]) ? GETPOST("login", 'alpha') : (isset($force_install_dolibarrlogin) ? $force_install_dolibarrlogin : '')).'"'.(@$force_install_noedit == 2 && $force_install_dolibarrlogin !== null ? ' disabled' : '').'></td></tr>';
print '<tr><td><label for="pass">'.$langs->trans("Password").' :</label></td><td>';
@ -87,15 +87,13 @@ if ($db->ok)
print '<input type="password" id="pass_verif" name="pass_verif" autocomplete="new-password"></td></tr>';
print '</table>';
if (isset($_GET["error"]) && $_GET["error"] == 1)
{
if (isset($_GET["error"]) && $_GET["error"] == 1) {
print '<br>';
print '<div class="error">'.$langs->trans("PasswordsMismatch").'</div>';
$error = 0; // We show button
}
if (isset($_GET["error"]) && $_GET["error"] == 2)
{
if (isset($_GET["error"]) && $_GET["error"] == 2) {
print '<br>';
print '<div class="error">';
print $langs->trans("PleaseTypePassword");
@ -103,8 +101,7 @@ if ($db->ok)
$error = 0; // We show button
}
if (isset($_GET["error"]) && $_GET["error"] == 3)
{
if (isset($_GET["error"]) && $_GET["error"] == 3) {
print '<br>';
print '<div class="error">'.$langs->trans("PleaseTypeALogin").'</div>';
$error = 0; // We show button
@ -112,7 +109,9 @@ if ($db->ok)
}
$ret = 0;
if ($error && isset($argv[1])) $ret = 1;
if ($error && isset($argv[1])) {
$ret = 1;
}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("- step4: end");
@ -122,4 +121,6 @@ pFooter($error, $setuplang);
$db->close();
// Return code if ran from command line
if ($ret) exit($ret);
if ($ret) {
exit($ret);
}

View File

@ -27,7 +27,9 @@
*/
include_once 'inc.php';
if (file_exists($conffile)) include_once $conffile;
if (file_exists($conffile)) {
include_once $conffile;
}
require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash
@ -42,13 +44,15 @@ $action = GETPOST('action', 'alpha') ?GETPOST('action', 'alpha') : (empty($argv[
// Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
// or MAIN_VERSION_LAST_UPGRADE for upgrade.
$targetversion = DOL_VERSION; // If it's latest upgrade
if (!empty($action) && preg_match('/upgrade/i', $action)) // If it's an old upgrade
{
if (!empty($action) && preg_match('/upgrade/i', $action)) {
// If it's an old upgrade
$tmp = explode('_', $action, 2);
if ($tmp[0] == 'upgrade')
{
if (!empty($tmp[1])) $targetversion = $tmp[1]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
else $targetversion = DOL_VERSION; // if $action = 'upgrade', we use DOL_VERSION
if ($tmp[0] == 'upgrade') {
if (!empty($tmp[1])) {
$targetversion = $tmp[1]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
} else {
$targetversion = DOL_VERSION; // if $action = 'upgrade', we use DOL_VERSION
}
}
}
@ -63,7 +67,9 @@ $success = 0;
$useforcedwizard = false;
$forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") {
$forcedfile = "/etc/dolibarr/install.forced.php";
}
if (@file_exists($forcedfile)) {
$useforcedwizard = true;
include_once $forcedfile;
@ -110,27 +116,25 @@ pHeader($langs->trans("SetupEnd"), "step5");
print '<br>';
// Test if we can run a first install process
if (empty($versionfrom) && empty($versionto) && !is_writable($conffile))
{
if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
pFooter(1, $setuplang, 'jscheckparam');
exit;
}
if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
{
if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
$error = 0;
// If password is encoded, we decode it
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
if (preg_match('/crypted:/i', $dolibarr_main_db_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
$dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
$dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
} else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
} else {
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
}
}
$conf->db->type = $dolibarr_main_db_type;
@ -151,8 +155,7 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
$ok = 0;
// If first install
if ($action == "set")
{
if ($action == "set") {
// Active module user
$modName = 'modUser';
$file = $modName.".class.php";
@ -160,13 +163,16 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
include_once DOL_DOCUMENT_ROOT."/core/modules/".$file;
$objMod = new $modName($db);
$result = $objMod->init();
if (!$result) print 'ERROR in activating module file='.$file;
if (!$result) {
print 'ERROR in activating module file='.$file;
}
if ($db->connected)
{
if ($db->connected) {
$conf->setValues($db);
// Reset forced setup after the setValues
if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
if (defined('SYSLOG_FILE')) {
$conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
}
$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
// Create admin user
@ -176,17 +182,17 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
$sql = "SELECT u.rowid, u.pass, u.pass_crypted";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows == 0)
{
if ($numrows == 0) {
// Define default setup for password encryption
dolibarr_set_const($db, "DATABASE_PWD_ENCRYPTED", "1", 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_SECURITY_SALT", dol_print_date(dol_now(), 'dayhourlog'), 'chaine', 0, '', 0); // All entities
if (function_exists('password_hash'))
if (function_exists('password_hash')) {
dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'password_hash', 'chaine', 0, '', 0); // All entities
else dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'sha1md5', 'chaine', 0, '', 0); // All entities
} else {
dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'sha1md5', 'chaine', 0, '', 0); // All entities
}
}
dolibarr_install_syslog('step5: DATABASE_PWD_ENCRYPTED = '.$conf->global->DATABASE_PWD_ENCRYPTED.' MAIN_SECURITY_HASH_ALGO = '.$conf->global->MAIN_SECURITY_HASH_ALGO, LOG_INFO);
@ -208,13 +214,11 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
$conf->global->USER_MAIL_REQUIRED = 0; // Force global option to be sure to create a new user with no email
$result = $newuser->create($createuser, 1);
if ($result > 0)
{
if ($result > 0) {
print $langs->trans("AdminLoginCreatedSuccessfuly", $login)."<br>";
$success = 1;
} else {
if ($newuser->error == 'ErrorLoginAlreadyExists')
{
if ($newuser->error == 'ErrorLoginAlreadyExists') {
dolibarr_install_syslog('step5: AdminLoginAlreadyExists', LOG_WARNING);
print '<br><div class="warning">'.$langs->trans("AdminLoginAlreadyExists", $login)."</div><br>";
$success = 1;
@ -224,14 +228,12 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
}
}
if ($success)
{
if ($success) {
// Insert MAIN_VERSION_FIRST_INSTALL in a dedicated transaction. So if it fails (when first install was already done), we can do other following requests.
$db->begin();
dolibarr_install_syslog('step5: set MAIN_VERSION_FIRST_INSTALL const to '.$targetversion, LOG_DEBUG);
$resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_FIRST_INSTALL', 1).",".$db->encrypt($targetversion, 1).",'chaine',0,'Dolibarr version when first install',0)");
if ($resql)
{
if ($resql) {
$conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
$db->commit();
} else {
@ -243,29 +245,36 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG);
$resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_INSTALL'");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL', 1).",".$db->encrypt($targetversion, 1).",'chaine',0,'Dolibarr version when last install',0)");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
if ($useforcedwizard)
{
if ($useforcedwizard) {
dolibarr_install_syslog('step5: set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG);
$resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')."='MAIN_REMOVE_INSTALL_WARNING'");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING', 1).",".$db->encrypt(1, 1).",'chaine',1,'Disable install warnings',0)");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$conf->global->MAIN_REMOVE_INSTALL_WARNING = 1;
}
// If we ask to force some modules to be enabled
if (!empty($force_install_module))
{
if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
if (!empty($force_install_module)) {
if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
}
$tmparray = explode(',', $force_install_module);
foreach ($tmparray as $modtoactivate)
{
foreach ($tmparray as $modtoactivate) {
$modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate);
print $langs->trans("ActivateModule", $modtoactivatenew).'<br>';
@ -274,46 +283,55 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
$res = dol_include_once("/core/modules/".$file);
$res = activateModule($modtoactivatenew, 1);
if (!empty($res['errors'])) print 'ERROR in activating module file='.$file;
if (!empty($res['errors'])) {
print 'ERROR in activating module file='.$file;
}
}
}
dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const');
$resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')."='MAIN_NOT_INSTALLED'");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$db->commit();
}
} else {
print $langs->trans("ErrorFailedToConnect")."<br>";
}
}
// If upgrade
elseif (empty($action) || preg_match('/upgrade/i', $action))
{
if ($db->connected)
{
} elseif (empty($action) || preg_match('/upgrade/i', $action)) {
// If upgrade
if ($db->connected) {
$conf->setValues($db);
// Reset forced setup after the setValues
if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
if (defined('SYSLOG_FILE')) {
$conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
}
$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
// Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
$tagdatabase = false;
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) $tagdatabase = true; // We don't know what it was before, so now we consider we are version choosed.
else {
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) {
$tagdatabase = true; // We don't know what it was before, so now we consider we are version choosed.
} else {
$mainversionlastupgradearray = preg_split('/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
$targetversionarray = preg_split('/[.-]/', $targetversion);
if (versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) $tagdatabase = true;
if (versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
$tagdatabase = true;
}
}
if ($tagdatabase)
{
if ($tagdatabase) {
dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion);
$resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_UPGRADE'");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) VALUES (".$db->encrypt('MAIN_VERSION_LAST_UPGRADE', 1).",".$db->encrypt($targetversion, 1).",'chaine',0,'Dolibarr version for last upgrade',0)");
if (!$resql) dol_print_error($db, 'Error in setup program');
if (!$resql) {
dol_print_error($db, 'Error in setup program');
}
$conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
} else {
dolibarr_install_syslog('step5: we run an upgrade to version '.$targetversion.' but database was already upgraded to '.$conf->global->MAIN_VERSION_LAST_UPGRADE.'. We keep MAIN_VERSION_LAST_UPGRADE as it is.');
@ -337,31 +355,28 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action))
// Create lock file
// If first install
if ($action == "set" && $success)
{
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION))
{
if ($action == "set" && $success) {
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
// Install is finished
print $langs->trans("SystemIsInstalled")."<br>";
$createlock = 0;
if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE))
{
if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
// Install is finished, we create the lock file
$lockfile = DOL_DATA_ROOT.'/install.lock';
$fp = @fopen($lockfile, "w");
if ($fp)
{
if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) $force_install_lockinstall = 444; // For backward compatibility
if ($fp) {
if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
$force_install_lockinstall = 444; // For backward compatibility
}
fwrite($fp, "This is a lock file to prevent use of install pages (set with permission ".$force_install_lockinstall.")");
fclose($fp);
@chmod($lockfile, octdec($force_install_lockinstall));
$createlock = 1;
}
}
if (empty($createlock))
{
if (empty($createlock)) {
print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
}
@ -383,33 +398,29 @@ if ($action == "set" && $success)
print '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
print '</a></div>';
}
}
// If upgrade
elseif (empty($action) || preg_match('/upgrade/i', $action))
{
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION))
{
} elseif (empty($action) || preg_match('/upgrade/i', $action)) {
// If upgrade
if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
// Upgrade is finished
print $langs->trans("SystemIsUpgraded")."<br>";
$createlock = 0;
if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE))
{
if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
// Upgrade is finished, we create the lock file
$lockfile = DOL_DATA_ROOT.'/install.lock';
$fp = @fopen($lockfile, "w");
if ($fp)
{
if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) $force_install_lockinstall = 444; // For backward compatibility
if ($fp) {
if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
$force_install_lockinstall = 444; // For backward compatibility
}
fwrite($fp, "This is a lock file to prevent use of install pages (set with permission ".$force_install_lockinstall.")");
fclose($fp);
@chmod($lockfile, octdec($force_install_lockinstall));
$createlock = 1;
}
}
if (empty($createlock))
{
if (empty($createlock)) {
print '<br><div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
}
@ -437,7 +448,9 @@ elseif (empty($action) || preg_match('/upgrade/i', $action))
clearstatcache();
$ret = 0;
if ($error && isset($argv[1])) $ret = 1;
if ($error && isset($argv[1])) {
$ret = 1;
}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("- step5: Dolibarr setup finished");
@ -445,4 +458,6 @@ dolibarr_install_syslog("- step5: Dolibarr setup finished");
pFooter(1, $setuplang);
// Return code if ran from command line
if ($ret) exit($ret);
if ($ret) {
exit($ret);
}

View File

@ -37,8 +37,7 @@
*/
include_once 'inc.php';
if (!file_exists($conffile))
{
if (!file_exists($conffile)) {
print 'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
}
require_once $conffile;
@ -68,29 +67,35 @@ $ignoredbversion = (GETPOST('ignoredbversion', 'alpha', 3) == 'ignoredbversion')
$langs->loadLangs(array("admin", "install", "other", "errors"));
if ($dolibarr_main_db_type == "mysqli") $choix = 1;
if ($dolibarr_main_db_type == "pgsql") $choix = 2;
if ($dolibarr_main_db_type == "mssql") $choix = 3;
if ($dolibarr_main_db_type == "mysqli") {
$choix = 1;
}
if ($dolibarr_main_db_type == "pgsql") {
$choix = 2;
}
if ($dolibarr_main_db_type == "mssql") {
$choix = 3;
}
dolibarr_install_syslog("--- upgrade: Entering upgrade.php page");
if (!is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
if (!is_object($conf)) {
dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
}
/*
* View
*/
if (!$versionfrom && !$versionto)
{
if (!$versionfrom && !$versionto) {
print 'Error: Parameter versionfrom or versionto missing.'."\n";
print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
// Test if batch mode
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path = __DIR__.'/';
if (substr($sapi_type, 0, 3) == 'cli')
{
if (substr($sapi_type, 0, 3) == 'cli') {
print 'Syntax from command line: '.$script_file." x.y.z a.b.c\n";
}
exit;
@ -102,8 +107,7 @@ pHeader('', "upgrade2", GETPOST('action', 'aZ09'), 'versionfrom='.$versionfrom.'
$actiondone = 0;
// Action to launch the migrate script
if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09')))
{
if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) {
$actiondone = 1;
print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> '.$langs->trans("DatabaseMigration").'</h3>';
@ -112,15 +116,15 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$error = 0;
// If password is encoded, we decode it
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
if (preg_match('/crypted:/i', $dolibarr_main_db_pass))
{
if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
$dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
$dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
} else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
} else {
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
}
}
// $conf is already instancied inside inc.php
@ -132,9 +136,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$conf->db->pass = $dolibarr_main_db_pass;
// Load type and crypt key
if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0;
if (empty($dolibarr_main_db_encryption)) {
$dolibarr_main_db_encryption = 0;
}
$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = '';
if (empty($dolibarr_main_db_cryptkey)) {
$dolibarr_main_db_cryptkey = '';
}
$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
$db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
@ -143,8 +151,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager = new HookManager($db);
if ($db->connected)
{
if ($db->connected) {
print '<tr><td class="nowrap">';
print $langs->trans("ServerConnection")." : ".$dolibarr_main_db_host.'</td><td class="right"><span class="neutral">'.$langs->trans("OK").'</span></td></tr>'."\n";
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerConnection").": $dolibarr_main_db_host ".$langs->transnoentities("OK"));
@ -155,10 +162,8 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$ok = 0;
}
if ($ok)
{
if ($db->database_selected)
{
if ($ok) {
if ($db->database_selected) {
print '<tr><td class="nowrap">';
print $langs->trans("DatabaseConnection")." : ".$dolibarr_main_db_name.'</td><td class="right"><span class="neutral">'.$langs->trans("OK")."</span></td></tr>\n";
dolibarr_install_syslog("upgrade: Database connection successful: ".$dolibarr_main_db_name);
@ -171,15 +176,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
// Affiche version
if ($ok)
{
if ($ok) {
$version = $db->getVersion();
$versionarray = $db->getVersionArray();
print '<tr><td>'.$langs->trans("ServerVersion").'</td>';
print '<td class="right">'.$version.'</td></tr>';
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ServerVersion").": ".$version);
if ($db->type == 'mysqli' && function_exists('mysqli_get_charset'))
{
if ($db->type == 'mysqli' && function_exists('mysqli_get_charset')) {
$tmparray = $db->db->get_charset();
print '<tr><td>'.$langs->trans("ClientCharset").'</td>';
print '<td class="right">'.$tmparray->charset.'</td></tr>';
@ -193,8 +196,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$versionmindb = explode('.', $db::VERSIONMIN);
//print join('.',$versionarray).' - '.join('.',$versionmindb);
if (count($versionmindb) && count($versionarray)
&& versioncompare($versionarray, $versionmindb) < 0)
{
&& versioncompare($versionarray, $versionmindb) < 0) {
// Warning: database version too low.
print "<tr><td>".$langs->trans("ErrorDatabaseVersionTooLow", join('.', $versionarray), join('.', $versionmindb)).'</td><td class="right"><span class="error">'.$langs->trans("Error")."</span></td></tr>\n";
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionTooLow", join('.', $versionarray), join('.', $versionmindb)));
@ -202,8 +204,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
// Test database version is not forbidden for migration
if (empty($ignoredbversion))
{
if (empty($ignoredbversion)) {
$dbversion_disallowed = array(
array('type'=>'mysql', 'version'=>array(5, 5, 40)),
array('type'=>'mysqli', 'version'=>array(5, 5, 40)) //,
@ -211,17 +212,16 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
//array('type'=>'mysqli','version'=>array(5,5,41))
);
$listofforbiddenversion = '';
foreach ($dbversion_disallowed as $dbversion_totest)
{
if ($dbversion_totest['type'] == $db->type) $listofforbiddenversion .= ($listofforbiddenversion ? ', ' : '').join('.', $dbversion_totest['version']);
foreach ($dbversion_disallowed as $dbversion_totest) {
if ($dbversion_totest['type'] == $db->type) {
$listofforbiddenversion .= ($listofforbiddenversion ? ', ' : '').join('.', $dbversion_totest['version']);
}
}
foreach ($dbversion_disallowed as $dbversion_totest)
{
foreach ($dbversion_disallowed as $dbversion_totest) {
//print $db->type.' - '.join('.',$versionarray).' - '.versioncompare($dbversion_totest['version'],$versionarray)."<br>\n";
if ($dbversion_totest['type'] == $db->type
&& (versioncompare($dbversion_totest['version'], $versionarray) == 0 || versioncompare($dbversion_totest['version'], $versionarray) <= -4 || versioncompare($dbversion_totest['version'], $versionarray) >= 4)
)
{
) {
// Warning: database version too low.
print '<tr><td><div class="warning">'.$langs->trans("ErrorDatabaseVersionForbiddenForMigration", join('.', $versionarray), $listofforbiddenversion)."</div></td><td class=\"right\">".$langs->trans("Error")."</td></tr>\n";
dolibarr_install_syslog("upgrade: ".$langs->transnoentities("ErrorDatabaseVersionForbiddenForMigration", join('.', $versionarray), $listofforbiddenversion));
@ -233,8 +233,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
// Force l'affichage de la progression
if ($ok)
{
if ($ok) {
print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>';
flush();
}
@ -243,12 +242,10 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
/*
* Remove deprecated indexes and constraints for Mysql
*/
if ($ok && preg_match('/mysql/', $db->type))
{
if ($ok && preg_match('/mysql/', $db->type)) {
$versioncommande = array(4, 0, 0);
if (count($versioncommande) && count($versionarray)
&& versioncompare($versioncommande, $versionarray) <= 0) // Si mysql >= 4.0
{
&& versioncompare($versioncommande, $versionarray) <= 0) { // Si mysql >= 4.0
dolibarr_install_syslog("Clean database from bad named constraints");
// Suppression vieilles contraintes sans noms et en doubles
@ -262,25 +259,20 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
);
$listtables = $db->DDLListTables($conf->db->name, '');
foreach ($listtables as $val)
{
foreach ($listtables as $val) {
// Database prefix filter
if (preg_match('/^'.MAIN_DB_PREFIX.'/', $val))
{
if (preg_match('/^'.MAIN_DB_PREFIX.'/', $val)) {
//print "x".$val."<br>";
$sql = "SHOW CREATE TABLE ".$val;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$values = $db->fetch_array($resql);
$i = 0;
$createsql = $values[1];
while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100)
{
while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
$sqldrop = "ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1];
$resqldrop = $db->query($sqldrop);
if ($resqldrop)
{
if ($resqldrop) {
print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n";
}
$createsql = preg_replace('/CONSTRAINT `'.$reg[1].'`/i', 'XXX', $createsql);
@ -288,8 +280,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
$db->free($resql);
} else {
if ($db->lasterrno() != 'DB_ERROR_NOSUCHTABLE')
{
if ($db->lasterrno() != 'DB_ERROR_NOSUCHTABLE') {
print '<tr><td colspan="2"><span class="error">'.$sql.' : '.$db->lasterror()."</font></td></tr>\n";
}
}
@ -299,12 +290,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
/*
* Load sql files
*/
if ($ok)
{
* Load sql files
*/
if ($ok) {
$dir = "mysql/migration/"; // We use mysql migration scripts whatever is database driver
if (!empty($dirmodule)) $dir = dol_buildpath('/'.$dirmodule.'/sql/', 0);
if (!empty($dirmodule)) {
$dir = dol_buildpath('/'.$dirmodule.'/sql/', 0);
}
dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
// Clean last part to exclude minor version x.y.z -> x.y
@ -320,11 +312,11 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Get files list
$filesindir = array();
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/\.sql$/i', $file)) $filesindir[] = $file;
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/\.sql$/i', $file)) {
$filesindir[] = $file;
}
}
sort($filesindir);
} else {
@ -332,27 +324,24 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
// Define which file to run
foreach ($filesindir as $file)
{
if (preg_match('/'.$from.'/i', $file))
{
foreach ($filesindir as $file) {
if (preg_match('/'.$from.'/i', $file)) {
$filelist[] = $file;
} elseif (preg_match('/'.$to.'/i', $file)) // First test may be false if we migrate from x.y.* to x.y.*
{
} elseif (preg_match('/'.$to.'/i', $file)) { // First test may be false if we migrate from x.y.* to x.y.*
$filelist[] = $file;
}
}
if (count($filelist) == 0)
{
if (count($filelist) == 0) {
print '<div class="error">'.$langs->trans("ErrorNoMigrationFilesFoundForParameters").'</div>';
} else {
$listoffileprocessed = array(); // Protection to avoid to process twice the same file
// Loop on each migrate files
foreach ($filelist as $file)
{
if (in_array($dir.$file, $listoffileprocessed)) continue;
foreach ($filelist as $file) {
if (in_array($dir.$file, $listoffileprocessed)) {
continue;
}
print '<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
print '<tr><td class="nowrap">'.$langs->trans("ChoosedMigrateScript").'</td><td class="right">'.$file.'</td></tr>'."\n";
@ -364,18 +353,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Scan if there is migration scripts that depends of Dolibarr version
// for modules htdocs/module/sql or htdocs/custom/module/sql (files called "dolibarr_x.y.z-a.b.c.sql")
$modulesfile = array();
foreach ($conf->file->dol_document_root as $type => $dirroot)
{
foreach ($conf->file->dol_document_root as $type => $dirroot) {
$handlemodule = @opendir($dirroot); // $dirroot may be '..'
if (is_resource($handlemodule))
{
while (($filemodule = readdir($handlemodule)) !== false)
{
if (!preg_match('/\./', $filemodule) && is_dir($dirroot.'/'.$filemodule.'/sql')) // We exclude filemodule that contains . (are not directories) and are not directories.
{
//print "Scan for ".$dirroot . '/' . $filemodule . '/sql/'.$file;
if (is_file($dirroot.'/'.$filemodule.'/sql/dolibarr_'.$file))
{
if (is_resource($handlemodule)) {
while (($filemodule = readdir($handlemodule)) !== false) {
if (!preg_match('/\./', $filemodule) && is_dir($dirroot.'/'.$filemodule.'/sql')) { // We exclude filemodule that contains . (are not directories) and are not directories.
//print "Scan for ".$dirroot . '/' . $filemodule . '/sql/'.$file;
if (is_file($dirroot.'/'.$filemodule.'/sql/dolibarr_'.$file)) {
$modulesfile[$dirroot.'/'.$filemodule.'/sql/dolibarr_'.$file] = '/'.$filemodule.'/sql/dolibarr_'.$file;
}
}
@ -384,9 +368,10 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
}
foreach ($modulesfile as $modulefilelong => $modulefileshort)
{
if (in_array($modulefilelong, $listoffileprocessed)) continue;
foreach ($modulesfile as $modulefilelong => $modulefileshort) {
if (in_array($modulefilelong, $listoffileprocessed)) {
continue;
}
print '<tr><td colspan="2"><hr></td></tr>';
print '<tr><td class="nowrap">'.$langs->trans("ChoosedMigrateScript").' (external modules)</td><td class="right">'.$modulefileshort.'</td></tr>'."\n";
@ -401,24 +386,33 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
print '</table>';
if ($db->connected) $db->close();
if ($db->connected) {
$db->close();
}
}
if (empty($actiondone))
{
if (empty($actiondone)) {
print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>';
}
$ret = 0;
if (!$ok && isset($argv[1])) $ret = 1;
if (!$ok && isset($argv[1])) {
$ret = 1;
}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("--- upgrade: end ".((!$ok && empty($_GET["ignoreerrors"])) || $dirmodule));
$nonext = (!$ok && empty($_GET["ignoreerrors"])) ? 2 : 0;
if ($dirmodule) $nonext = 1;
if ($dirmodule) {
$nonext = 1;
}
pFooter($nonext, $setuplang);
if ($db->connected) $db->close();
if ($db->connected) {
$db->close();
}
// Return code if ran from command line
if ($ret) exit($ret);
if ($ret) {
exit($ret);
}

File diff suppressed because it is too large Load Diff