";
print $langs->trans("DatabaseConnection")." (".$langs->trans("User")." ".$conf->db->user.") : ";
@@ -773,7 +737,9 @@ function jsinfo()
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 ' '.$langs->trans("Database").'';
print '';
@@ -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 "| ";
print $langs->trans("ServerConnection")." : ".$conf->db->host.' |  | ';
$ok = 1;
@@ -103,10 +114,8 @@ if ($action == "set")
print "| Failed to connect to server : ".$conf->db->host.' |  | ';
}
- 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 '| '.$langs->trans("DatabaseVersion").' | ';
@@ -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 "OK requete ==== $buffer | ";
$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 "Deja existante | ";
} else {
print "| ".$langs->trans("CreateTableAndPrimaryKey", $name);
@@ -241,10 +237,8 @@ if ($action == "set")
}
}
- if ($tablefound)
- {
- if ($error == 0)
- {
+ if ($tablefound) {
+ if ($error == 0) {
print ' | | ';
print $langs->trans("TablesAndPrimaryKeysCreation").' |  | ';
$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 "| Creation de la table $name | ";
$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.' ';
}
}
- 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.' ';
@@ -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 "OK requete ==== $buffer | ";
$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 "Deja existante | ";
$key_exists = 1;
} else {
@@ -382,8 +362,7 @@ if ($action == "set")
}
}
- if ($tablefound && $error == 0)
- {
+ if ($tablefound && $error == 0) {
print '| ';
print $langs->trans("OtherKeysCreation").' |  | ';
$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 "\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." \n";
} else {
$ok = 0;
@@ -463,8 +437,7 @@ if ($action == "set")
}
print "| ".$langs->trans("FunctionsCreation")." | ";
- if ($ok)
- {
+ if ($ok) {
print ' | ';
} else {
print ' | ';
@@ -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.' ';
- 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 "| Insertion ligne : $buffer | ";
} 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 " | | ".$langs->trans("ReferenceDataLoading")." | ";
- if ($ok)
- {
+ if ($ok) {
print ' | ';
} else {
print ' | ';
@@ -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);
+}
diff --git a/htdocs/install/step4.php b/htdocs/install/step4.php
index ca188ae4d5b..7d03c7b6fd0 100644
--- a/htdocs/install/step4.php
+++ b/htdocs/install/step4.php
@@ -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 '';
- if (isset($_GET["error"]) && $_GET["error"] == 1)
- {
+ if (isset($_GET["error"]) && $_GET["error"] == 1) {
print ' ';
print ''.$langs->trans("PasswordsMismatch").' ';
$error = 0; // We show button
}
- if (isset($_GET["error"]) && $_GET["error"] == 2)
- {
+ if (isset($_GET["error"]) && $_GET["error"] == 2) {
print ' ';
print '';
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 ' ';
print ' '.$langs->trans("PleaseTypeALogin").' ';
$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);
+}
diff --git a/htdocs/install/step5.php b/htdocs/install/step5.php
index ed64de7cbb1..6ae3bffc59b 100644
--- a/htdocs/install/step5.php
+++ b/htdocs/install/step5.php
@@ -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 ' ';
// 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)." ";
$success = 1;
} else {
- if ($newuser->error == 'ErrorLoginAlreadyExists')
- {
+ if ($newuser->error == 'ErrorLoginAlreadyExists') {
dolibarr_install_syslog('step5: AdminLoginAlreadyExists', LOG_WARNING);
print ' '.$langs->trans("AdminLoginAlreadyExists", $login)." ";
$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).' ';
@@ -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")." ";
}
- }
- // 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")." ";
$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 ' '.$langs->trans("WarningRemoveInstallDir")." ";
}
@@ -383,33 +398,29 @@ if ($action == "set" && $success)
print ' '.$langs->trans("GoToUpgradePage");
print ' ';
}
-}
-// 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")." ";
$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 '
'.$langs->trans("WarningRemoveInstallDir")." ";
}
@@ -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);
+}
diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index 29b51746a14..db3ca2f4eb1 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -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 ' '.$langs->trans("DatabaseMigration").'';
@@ -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 '| ';
print $langs->trans("ServerConnection")." : ".$dolibarr_main_db_host.' | '.$langs->trans("OK").' | '."\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 '| ';
print $langs->trans("DatabaseConnection")." : ".$dolibarr_main_db_name.' | '.$langs->trans("OK")." | \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 '| '.$langs->trans("ServerVersion").' | ';
print ''.$version.' | ';
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 '| '.$langs->trans("ClientCharset").' | ';
print ''.$tmparray->charset.' | ';
@@ -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 "| ".$langs->trans("ErrorDatabaseVersionTooLow", join('.', $versionarray), join('.', $versionmindb)).' | '.$langs->trans("Error")." | \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)." \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 ''.$langs->trans("ErrorDatabaseVersionForbiddenForMigration", join('.', $versionarray), $listofforbiddenversion)." | ".$langs->trans("Error")." | \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 '| '.$langs->trans("PleaseBePatient").' | ';
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." ";
$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 '| '.$sqldrop."; | \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 '| '.$sql.' : '.$db->lasterror()." | \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 ''.$langs->trans("ErrorNoMigrationFilesFoundForParameters").' ';
} 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 '
| ';
print '| '.$langs->trans("ChoosedMigrateScript").' | '.$file.' | '."\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 '
| ';
print '| '.$langs->trans("ChoosedMigrateScript").' (external modules) | '.$modulefileshort.' | '."\n";
@@ -401,24 +386,33 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
print ' ';
- if ($db->connected) $db->close();
+ if ($db->connected) {
+ $db->close();
+ }
}
-if (empty($actiondone))
-{
+if (empty($actiondone)) {
print ''.$langs->trans("ErrorWrongParameters").' ';
}
$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);
+}
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 1dc7180bc4b..d9656231a2c 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -39,8 +39,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;
@@ -64,9 +63,11 @@ $error = 0;
// Ne fonctionne que si on est pas en safe_mode.
$err = error_reporting();
error_reporting(0);
-if (!empty($conf->global->MAIN_OVERRIDE_TIME_LIMIT))
+if (!empty($conf->global->MAIN_OVERRIDE_TIME_LIMIT)) {
@set_time_limit((int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
-else @set_time_limit(600);
+} else {
+ @set_time_limit(600);
+}
error_reporting($err);
$setuplang = GETPOST("selectlang", 'aZ09', 3) ?GETPOST("selectlang", 'aZ09', 3) : 'auto';
@@ -77,13 +78,21 @@ $enablemodules = GETPOST("enablemodules", 'alpha', 3) ?GETPOST("enablemodules",
$langs->loadLangs(array("admin", "install", "bills", "suppliers"));
-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("--- upgrade2: entering upgrade2.php page ".$versionfrom." ".$versionto." ".$enablemodules);
-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);
+}
@@ -91,16 +100,14 @@ if (!is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initiali
* View
*/
-if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto || preg_match('/version/', $versionto)))
-{
+if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto || preg_match('/version/', $versionto))) {
print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\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 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
}
exit;
@@ -109,22 +116,21 @@ if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto ||
pHeader('', 'step5', GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'upgrade', 'versionfrom='.$versionfrom.'&versionto='.$versionto);
-if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09')))
-{
+if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) {
print ' '.$langs->trans('DataMigration').'';
print '';
// 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
@@ -142,47 +148,48 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$hookmanager = new HookManager($db);
$hookmanager->initHooks(array('upgrade'));
- if (!$db->connected)
- {
+ if (!$db->connected) {
print '| '.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).' | '.$langs->trans('Error').' | ';
dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR);
$error++;
}
- if (!$error)
- {
- if ($db->database_selected)
- {
+ if (!$error) {
+ if ($db->database_selected) {
dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name);
} else {
$error++;
}
}
- 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;
// Chargement config
- if (!$error)
- {
+ if (!$error) {
$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;
}
/***************************************************************************************
- *
- * Migration of data
- *
- ***************************************************************************************/
+ *
+ * Migration of data
+ *
+ ***************************************************************************************/
$db->begin();
- if (!$error)
- {
+ if (!$error) {
// Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
// Version to install is DOL_VERSION
$dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : ''));
@@ -222,8 +229,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$afterversionarray = explode('.', '2.0.0');
$beforeversionarray = explode('.', '2.7.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
// Script pour V2 -> V2.1
migrate_paiements($db, $langs, $conf);
@@ -286,8 +292,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
$afterversionarray = explode('.', '2.7.9');
$beforeversionarray = explode('.', '2.8.9');
//print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx
migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping');
@@ -312,8 +317,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Script for 2.9
$afterversionarray = explode('.', '2.8.9');
$beforeversionarray = explode('.', '2.9.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_project_task_time($db, $langs, $conf);
migrate_customerorder_shipping($db, $langs, $conf);
@@ -326,16 +330,14 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Script for 3.0
$afterversionarray = explode('.', '2.9.9');
$beforeversionarray = explode('.', '3.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
// No particular code
}
// Script for 3.1
$afterversionarray = explode('.', '3.0.9');
$beforeversionarray = explode('.', '3.1.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss');
migrate_actioncomm_element($db, $langs, $conf);
@@ -344,8 +346,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Script for 3.2
$afterversionarray = explode('.', '3.1.9');
$beforeversionarray = explode('.', '3.2.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_price_contrat($db, $langs, $conf);
migrate_mode_reglement($db, $langs, $conf);
@@ -356,8 +357,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Script for 3.3
$afterversionarray = explode('.', '3.2.9');
$beforeversionarray = explode('.', '3.3.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_categorie_association($db, $langs, $conf);
}
@@ -367,32 +367,28 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Tasks to do always and only into last targeted version
$afterversionarray = explode('.', '3.6.9'); // target is after this
$beforeversionarray = explode('.', '3.7.9'); // target is before this
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
- migrate_event_assignement($db, $langs, $conf);
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
+ migrate_event_assignement($db, $langs, $conf);
}
// Scripts for 3.9
$afterversionarray = explode('.', '3.7.9');
$beforeversionarray = explode('.', '3.8.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
// No particular code
}
// Scripts for 4.0
$afterversionarray = explode('.', '3.9.9');
$beforeversionarray = explode('.', '4.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias');
}
// Scripts for 5.0
$afterversionarray = explode('.', '4.0.9');
$beforeversionarray = explode('.', '5.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
// Migrate to add entity value into llx_societe_remise
migrate_remise_entity($db, $langs, $conf);
@@ -403,15 +399,12 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Scripts for 6.0
$afterversionarray = explode('.', '5.0.9');
$beforeversionarray = explode('.', '6.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
- if (!empty($conf->multicompany->enabled))
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
+ if (!empty($conf->multicompany->enabled)) {
global $multicompany_transverse_mode;
// Only if the transverse mode is not used
- if (empty($multicompany_transverse_mode))
- {
+ if (empty($multicompany_transverse_mode)) {
// Migrate to add entity value into llx_user_rights
migrate_user_rights_entity($db, $langs, $conf);
@@ -424,8 +417,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Scripts for 7.0
$afterversionarray = explode('.', '6.0.9');
$beforeversionarray = explode('.', '7.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
// Migrate contact association
migrate_event_assignement_contact($db, $langs, $conf);
@@ -435,16 +427,14 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Scripts for 8.0
$afterversionarray = explode('.', '7.0.9');
$beforeversionarray = explode('.', '8.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract');
}
// Scripts for 9.0
$afterversionarray = explode('.', '8.0.9');
$beforeversionarray = explode('.', '9.0.9');
- if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0)
- {
+ if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
migrate_user_photospath();
}
@@ -460,8 +450,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
// Code executed only if migration is LAST ONE. Must always be done.
- if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3)
- {
+ if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3) {
// Reload modules (this must be always done and only into last targeted version, because code to reload module may need table structure of last version)
$listofmodule = array(
'MAIN_MODULE_ACCOUNTING'=>'newboxdefonly',
@@ -502,14 +491,12 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...'
// In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line.
- if (!$error && $enablemodules)
- {
+ if (!$error && $enablemodules) {
// Reload modules (this must be always done and only into last targeted version)
$listofmodules = array();
$enablemodules = preg_replace('/enablemodules=/', '', $enablemodules);
$tmplistofmodules = explode(',', $enablemodules);
- foreach ($tmplistofmodules as $value)
- {
+ foreach ($tmplistofmodules as $value) {
$listofmodules[$value] = 'forceactivate';
}
@@ -521,16 +508,13 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
// Can call a dedicated external upgrade process
- if (!$error)
- {
+ if (!$error) {
$parameters = array('versionfrom'=>$versionfrom, 'versionto='.$versionto);
$object = new stdClass();
$action = "upgrade";
$reshook = $hookmanager->executeHooks('doUpgrade2', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($hookmanager->resNbOfHooks > 0)
- {
- if ($reshook < 0)
- {
+ if ($hookmanager->resNbOfHooks > 0) {
+ if ($reshook < 0) {
print '| ';
print ''.$langs->trans('UpgradeExternalModule').': ';
print $hookmanager->error;
@@ -544,8 +528,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
} else {
//if (! empty($conf->modules))
- if (!empty($conf->modules_parts['hooks'])) // If there is at least one module with one hook, we show message to say nothing was done
- {
+ if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
print ' | | ';
print ''.$langs->trans('UpgradeExternalModule').': '.$langs->trans("None");
print ' | ';
@@ -587,16 +570,22 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
}
$ret = 0;
-if ($error && isset($argv[1])) $ret = 1;
+if ($error && isset($argv[1])) {
+ $ret = 1;
+}
dolibarr_install_syslog("Exit ".$ret);
dolibarr_install_syslog("--- upgrade2: end");
pFooter($error ? 2 : 0, $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);
+}
@@ -617,8 +606,7 @@ function migrate_paiements($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$sql = "SELECT p.rowid, p.fk_facture, p.amount";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql .= " WHERE p.fk_facture > 0";
@@ -626,14 +614,12 @@ function migrate_paiements($db, $langs, $conf)
$resql = $db->query($sql);
dolibarr_install_syslog("upgrade2::migrate_paiements");
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$row = array();
$num = $db->num_rows($resql);
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$row[$i][0] = $obj->rowid;
$row[$i][1] = $obj->fk_facture;
@@ -644,15 +630,12 @@ function migrate_paiements($db, $langs, $conf)
dol_print_error($db);
}
- if ($num)
- {
+ if ($num) {
print $langs->trans('MigrationPaymentsNumberToUpdate', $num)." \n";
- if ($db->begin())
- {
+ if ($db->begin()) {
$res = 0;
$num = count($row);
- for ($i = 0; $i < $num; $i++)
- {
+ for ($i = 0; $i < $num; $i++) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
$sql .= " VALUES (".$row[$i][1].",".$row[$i][0].",".$row[$i][2].")";
@@ -666,8 +649,7 @@ function migrate_paiements($db, $langs, $conf)
}
}
- if ($res == (2 * count($row)))
- {
+ if ($res == (2 * count($row))) {
$db->commit();
print $langs->trans('MigrationSuccessfullUpdate')." ";
} else {
@@ -703,8 +685,7 @@ function migrate_paiements_orphelins_1($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
// Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
$sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
$sql .= " bu2.url_id as socid";
@@ -719,16 +700,13 @@ function migrate_paiements_orphelins_1($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1");
$row = array();
- if ($resql)
- {
+ if ($resql) {
$i = $j = 0;
$num = $db->num_rows($resql);
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
- if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas
- {
+ if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
$row[$j]['paymentid'] = $obj->rowid; // paymentid
$row[$j]['pamount'] = $obj->pamount;
$row[$j]['fk_bank'] = $obj->fk_bank;
@@ -743,16 +721,16 @@ function migrate_paiements_orphelins_1($db, $langs, $conf)
dol_print_error($db);
}
- if (count($row))
- {
+ if (count($row)) {
print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)." \n";
$db->begin();
$res = 0;
$num = count($row);
- for ($i = 0; $i < $num; $i++)
- {
- if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' bamount='.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
+ for ($i = 0; $i < $num; $i++) {
+ if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
+ print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' bamount='.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
+ }
// On cherche facture sans lien paiement et du meme montant et pour meme societe.
$sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
@@ -762,12 +740,10 @@ function migrate_paiements_orphelins_1($db, $langs, $conf)
$sql .= " ORDER BY f.fk_statut";
//print $sql.' ';
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
//print 'Nb of invoice found for this amount and company :'.$num.' ';
- if ($num >= 1)
- {
+ if ($num >= 1) {
$obj = $db->fetch_object($resql);
$facid = $obj->rowid;
@@ -783,8 +759,7 @@ function migrate_paiements_orphelins_1($db, $langs, $conf)
}
}
- if ($res > 0)
- {
+ if ($res > 0) {
print $langs->trans('MigrationSuccessfullUpdate')." ";
} else {
print $langs->trans('MigrationPaymentsNothingUpdatable')." \n";
@@ -820,8 +795,7 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
// Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
$sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
$sql .= " bu2.url_id as socid";
@@ -835,16 +809,13 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2");
$row = array();
- if ($resql)
- {
+ if ($resql) {
$i = $j = 0;
$num = $db->num_rows($resql);
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
- if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas
- {
+ if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
$row[$j]['paymentid'] = $obj->rowid; // paymentid
$row[$j]['pamount'] = $obj->pamount;
$row[$j]['fk_bank'] = $obj->fk_bank;
@@ -862,15 +833,15 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
$nberr = 0;
$num = count($row);
- if ($num)
- {
+ if ($num) {
print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)." \n";
$db->begin();
$res = 0;
- for ($i = 0; $i < $num; $i++)
- {
- if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
+ for ($i = 0; $i < $num; $i++) {
+ if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
+ print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].' ';
+ }
// On cherche facture sans lien paiement et du meme montant et pour meme societe.
$sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
@@ -880,12 +851,10 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
$sql .= " ORDER BY f.fk_statut";
//print $sql.' ';
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
//print 'Nb of invoice found for this amount and company :'.$num.' ';
- if ($num >= 1)
- {
+ if ($num >= 1) {
$obj = $db->fetch_object($resql);
$facid = $obj->rowid;
@@ -901,8 +870,7 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
}
}
- if ($res > 0)
- {
+ if ($res > 0) {
print $langs->trans('MigrationSuccessfullUpdate')." ";
} else {
print $langs->trans('MigrationPaymentsNothingUpdatable')." \n";
@@ -919,8 +887,7 @@ function migrate_paiements_orphelins_2($db, $langs, $conf)
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture";
$db->query($sql);
- if (!$nberr)
- {
+ if (!$nberr) {
$db->commit();
} else {
print 'ERROR';
@@ -962,19 +929,16 @@ function migrate_contracts_det($db, $langs, $conf)
$resql = $db->query($sql);
dolibarr_install_syslog("upgrade2::migrate_contracts_det");
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$row = array();
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
print $langs->trans('MigrationContractsNumberToUpdate', $num)." \n";
$db->begin();
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet (";
@@ -993,8 +957,7 @@ function migrate_contracts_det($db, $langs, $conf)
$sql .= "null";
$sql .= ")";
- if ($db->query($sql))
- {
+ if ($db->query($sql)) {
print $langs->trans('MigrationContractsLineCreation', $obj->cref)." \n";
} else {
dol_print_error($db);
@@ -1004,8 +967,7 @@ function migrate_contracts_det($db, $langs, $conf)
$i++;
}
- if (!$nberr)
- {
+ if (!$nberr) {
// $db->rollback();
$db->commit();
print $langs->trans('MigrationSuccessfullUpdate')." ";
@@ -1050,19 +1012,16 @@ function migrate_links_transfert($db, $langs, $conf)
$resql = $db->query($sql);
dolibarr_install_syslog("upgrade2::migrate_links_transfert");
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$row = array();
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
print $langs->trans('MigrationBankTransfertsToUpdate', $num)." \n";
$db->begin();
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
@@ -1075,8 +1034,7 @@ function migrate_links_transfert($db, $langs, $conf)
print $sql.' ';
dolibarr_install_syslog("migrate_links_transfert");
- if (!$db->query($sql))
- {
+ if (!$db->query($sql)) {
dol_print_error($db);
$nberr++;
}
@@ -1084,8 +1042,7 @@ function migrate_links_transfert($db, $langs, $conf)
$i++;
}
- if (!$nberr)
- {
+ if (!$nberr) {
// $db->rollback();
$db->commit();
print $langs->trans('MigrationSuccessfullUpdate')." ";
@@ -1121,18 +1078,26 @@ function migrate_contracts_date1($db, $langs, $conf)
$sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null";
dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
- if ($db->affected_rows($resql) > 0)
- print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')." \n";
- else print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')." \n";
+ if (!$resql) {
+ dol_print_error($db);
+ }
+ if ($db->affected_rows($resql) > 0) {
+ print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')." \n";
+ } else {
+ print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')." \n";
+ }
$sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null";
dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
- if ($db->affected_rows($resql) > 0)
- print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')." \n";
- else print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')." \n";
+ if (!$resql) {
+ dol_print_error($db);
+ }
+ if ($db->affected_rows($resql) > 0) {
+ print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')." \n";
+ } else {
+ print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')." \n";
+ }
print '';
}
@@ -1162,22 +1127,18 @@ function migrate_contracts_date2($db, $langs, $conf)
$resql = $db->query($sql);
dolibarr_install_syslog("upgrade2::migrate_contracts_date2");
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$row = array();
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
$nbcontratsmodifie = 0;
$db->begin();
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
- if ($obj->date_contrat > $obj->datemin)
- {
+ if ($obj->date_contrat > $obj->datemin) {
$datemin = $db->jdate($obj->datemin);
print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)." \n";
@@ -1185,7 +1146,9 @@ function migrate_contracts_date2($db, $langs, $conf)
$sql .= " SET date_contrat='".$db->idate($datemin)."'";
$sql .= " WHERE rowid=".$obj->cref;
$resql2 = $db->query($sql);
- if (!$resql2) dol_print_error($db);
+ if (!$resql2) {
+ dol_print_error($db);
+ }
$nbcontratsmodifie++;
}
@@ -1194,9 +1157,11 @@ function migrate_contracts_date2($db, $langs, $conf)
$db->commit();
- if ($nbcontratsmodifie)
- print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)." \n";
- else print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')." \n";
+ if ($nbcontratsmodifie) {
+ print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)." \n";
+ } else {
+ print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')." \n";
+ }
}
} else {
dol_print_error($db);
@@ -1223,10 +1188,14 @@ function migrate_contracts_date3($db, $langs, $conf)
$sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat";
dolibarr_install_syslog("upgrade2::migrate_contracts_date3");
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
- if ($db->affected_rows($resql) > 0)
- print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')." \n";
- else print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')." \n";
+ if (!$resql) {
+ dol_print_error($db);
+ }
+ if ($db->affected_rows($resql) > 0) {
+ print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')." \n";
+ } else {
+ print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')." \n";
+ }
print '';
}
@@ -1250,19 +1219,19 @@ function migrate_contracts_open($db, $langs, $conf)
$sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
dolibarr_install_syslog("upgrade2::migrate_contracts_open");
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
+ if (!$resql) {
+ dol_print_error($db);
+ }
if ($db->affected_rows($resql) > 0) {
$i = 0;
$row = array();
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
$nbcontratsmodifie = 0;
$db->begin();
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
print $langs->trans('MigrationReopenThisContract', $obj->cref)." \n";
@@ -1270,7 +1239,9 @@ function migrate_contracts_open($db, $langs, $conf)
$sql .= " SET statut=1";
$sql .= " WHERE rowid=".$obj->cref;
$resql2 = $db->query($sql);
- if (!$resql2) dol_print_error($db);
+ if (!$resql2) {
+ dol_print_error($db);
+ }
$nbcontratsmodifie++;
@@ -1279,11 +1250,15 @@ function migrate_contracts_open($db, $langs, $conf)
$db->commit();
- if ($nbcontratsmodifie)
- print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)." \n";
- else print $langs->trans('MigrationReopeningContractsNothingToUpdate')." \n";
+ if ($nbcontratsmodifie) {
+ print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)." \n";
+ } else {
+ print $langs->trans('MigrationReopeningContractsNothingToUpdate')." \n";
+ }
}
- } else print $langs->trans('MigrationReopeningContractsNothingToUpdate')." \n";
+ } else {
+ print $langs->trans('MigrationReopeningContractsNothingToUpdate')." \n";
+ }
print '';
}
@@ -1307,8 +1282,7 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$error = 0;
$nb = 0;
@@ -1318,15 +1292,13 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn");
$select_resql = $db->query($select_sql);
- if ($select_resql)
- {
+ if ($select_resql) {
$select_num = $db->num_rows($select_resql);
$i = 0;
$var = true;
// Pour chaque paiement fournisseur, on insere une ligne dans paiementfourn_facturefourn
- while (($i < $select_num) && (!$error))
- {
+ while (($i < $select_num) && (!$error)) {
$var = !$var;
$select_obj = $db->fetch_object($select_resql);
@@ -1335,15 +1307,12 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf)
$check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
$check_sql .= ' WHERE fk_paiementfourn = '.$select_obj->rowid.' AND fk_facturefourn = '.$select_obj->fk_facture_fourn;
$check_resql = $db->query($check_sql);
- if ($check_resql)
- {
+ if ($check_resql) {
$check_num = $db->num_rows($check_resql);
- if ($check_num == 0)
- {
+ if ($check_num == 0) {
$db->begin();
- if ($nb == 0)
- {
+ if ($nb == 0) {
print '| '.$langs->trans('SuppliersInvoices').' | ';
print '| fk_paiementfourn | fk_facturefourn | '.$langs->trans('Amount').' | | ';
}
@@ -1357,8 +1326,7 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf)
$insert_sql .= ' amount = \''.$select_obj->amount.'\'';
$insert_resql = $db->query($insert_sql);
- if ($insert_resql)
- {
+ if ($insert_resql) {
$nb++;
print ''.$langs->trans("OK").' | ';
} else {
@@ -1376,10 +1344,8 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf)
$error++;
}
- if (!$error)
- {
- if (!$nb)
- {
+ if (!$error) {
+ if (!$nb) {
print '| '.$langs->trans("AlreadyDone").' | ';
}
$db->commit();
@@ -1427,14 +1393,11 @@ function migrate_price_facture($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_price_facture");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$rowid = $obj->rowid;
@@ -1465,15 +1428,12 @@ function migrate_price_facture($db, $langs, $conf)
/* On touche a facture mere uniquement si total_ttc = 0 */
- if (!$total_ttc_f)
- {
+ if (!$total_ttc_f) {
$facture = new Facture($db);
$facture->id = $obj->facid;
- if ($facture->fetch($facture->id) >= 0)
- {
- if ($facture->update_price() > 0)
- {
+ if ($facture->fetch($facture->id) >= 0) {
+ if ($facture->update_price() > 0) {
//print $facture->id;
} else {
print "Error id=".$facture->id;
@@ -1516,7 +1476,7 @@ function migrate_price_facture($db, $langs, $conf)
*/
function migrate_price_propal($db, $langs, $conf)
{
- $tmpmysoc = new Societe($db);
+ $tmpmysoc = new Societe($db);
$tmpmysoc->setMysoc($conf);
$db->begin();
@@ -1535,14 +1495,11 @@ function migrate_price_propal($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_price_propal");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$rowid = $obj->rowid;
@@ -1572,24 +1529,24 @@ function migrate_price_propal($db, $langs, $conf)
/* On touche pas a propal mere
- $propal = new Propal($db);
- $propal->id=$obj->rowid;
- if ( $propal->fetch($propal->id) >= 0 )
- {
- if ( $propal->update_price() > 0 )
- {
- print ". ";
- }
- else
- {
- print "Error id=".$propal->id;
- }
- }
- else
- {
- print "Error #3";
- }
- */
+ $propal = new Propal($db);
+ $propal->id=$obj->rowid;
+ if ( $propal->fetch($propal->id) >= 0 )
+ {
+ if ( $propal->update_price() > 0 )
+ {
+ print ". ";
+ }
+ else
+ {
+ print "Error id=".$propal->id;
+ }
+ }
+ else
+ {
+ print "Error #3";
+ }
+ */
$i++;
}
} else {
@@ -1622,9 +1579,11 @@ function migrate_price_contrat($db, $langs, $conf)
{
$db->begin();
- $tmpmysoc = new Societe($db);
+ $tmpmysoc = new Societe($db);
$tmpmysoc->setMysoc($conf);
- if (empty($tmpmysoc->country_id)) $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
+ if (empty($tmpmysoc->country_id)) {
+ $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
+ }
print '';
@@ -1640,14 +1599,11 @@ function migrate_price_contrat($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_price_contrat");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$rowid = $obj->rowid;
@@ -1724,14 +1680,11 @@ function migrate_price_commande($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_price_commande");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$rowid = $obj->rowid;
@@ -1760,24 +1713,24 @@ function migrate_price_commande($db, $langs, $conf)
$commandeligne->update_total();
/* On touche pas a facture mere
- $commande = new Commande($db);
- $commande->id = $obj->rowid;
- if ( $commande->fetch($commande->id) >= 0 )
- {
- if ( $commande->update_price() > 0 )
- {
- print ". ";
- }
- else
- {
- print "Error id=".$commande->id;
- }
- }
- else
- {
- print "Error #3";
- }
- */
+ $commande = new Commande($db);
+ $commande->id = $obj->rowid;
+ if ( $commande->fetch($commande->id) >= 0 )
+ {
+ if ( $commande->update_price() > 0 )
+ {
+ print ". ";
+ }
+ else
+ {
+ print "Error id=".$commande->id;
+ }
+ }
+ else
+ {
+ print "Error #3";
+ }
+ */
$i++;
}
} else {
@@ -1787,14 +1740,14 @@ function migrate_price_commande($db, $langs, $conf)
$db->free($resql);
/*
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
- $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
- $resql=$db->query($sql);
- if (! $resql)
- {
- dol_print_error($db);
- }
- */
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
+ $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
+ $resql=$db->query($sql);
+ if (! $resql)
+ {
+ dol_print_error($db);
+ }
+ */
$db->commit();
} else {
@@ -1837,14 +1790,11 @@ function migrate_price_commande_fournisseur($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$rowid = $obj->rowid;
@@ -1873,24 +1823,24 @@ function migrate_price_commande_fournisseur($db, $langs, $conf)
$commandeligne->update_total();
/* On touche pas a facture mere
- $commande = new Commande($db);
- $commande->id = $obj->rowid;
- if ( $commande->fetch($commande->id) >= 0 )
- {
- if ( $commande->update_price() > 0 )
- {
- print ". ";
- }
- else
- {
- print "Error id=".$commande->id;
- }
- }
- else
- {
- print "Error #3";
- }
- */
+ $commande = new Commande($db);
+ $commande->id = $obj->rowid;
+ if ( $commande->fetch($commande->id) >= 0 )
+ {
+ if ( $commande->update_price() > 0 )
+ {
+ print ". ";
+ }
+ else
+ {
+ print "Error id=".$commande->id;
+ }
+ }
+ else
+ {
+ print "Error #3";
+ }
+ */
$i++;
}
} else {
@@ -1900,14 +1850,14 @@ function migrate_price_commande_fournisseur($db, $langs, $conf)
$db->free($resql);
/*
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
- $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
- $resql=$db->query($sql);
- if (! $resql)
- {
- dol_print_error($db);
- }
- */
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
+ $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
+ $resql=$db->query($sql);
+ if (! $resql)
+ {
+ dol_print_error($db);
+ }
+ */
$db->commit();
} else {
@@ -1936,42 +1886,42 @@ function migrate_modeles($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_modeles");
- if (!empty($conf->facture->enabled))
- {
+ if (!empty($conf->facture->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
$modellist = ModelePDFFactures::liste_modeles($db);
- if (count($modellist) == 0)
- {
+ if (count($modellist) == 0) {
// Aucun model par defaut.
$sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')";
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
+ if (!$resql) {
+ dol_print_error($db);
+ }
}
}
- if (!empty($conf->commande->enabled))
- {
+ if (!empty($conf->commande->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
$modellist = ModelePDFCommandes::liste_modeles($db);
- if (count($modellist) == 0)
- {
+ if (count($modellist) == 0) {
// Aucun model par defaut.
$sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')";
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
+ if (!$resql) {
+ dol_print_error($db);
+ }
}
}
- if (!empty($conf->expedition->enabled))
- {
+ if (!empty($conf->expedition->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
$modellist = ModelePDFExpedition::liste_modeles($db);
- if (count($modellist) == 0)
- {
+ if (count($modellist) == 0) {
// Aucun model par defaut.
$sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')";
$resql = $db->query($sql);
- if (!$resql) dol_print_error($db);
+ if (!$resql) {
+ dol_print_error($db);
+ }
}
}
@@ -1998,31 +1948,26 @@ function migrate_commande_expedition($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$error = 0;
$db->begin();
$sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
$sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")";
$resql2 = $db->query($sql);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
@@ -2031,8 +1976,7 @@ function migrate_commande_expedition($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
print $langs->trans('FieldRenamed')." \n";
@@ -2069,8 +2013,7 @@ function migrate_commande_livraison($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$error = 0;
$db->begin();
@@ -2080,23 +2023,19 @@ function migrate_commande_livraison($db, $langs, $conf)
$sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
$sql .= " WHERE c.rowid = l.fk_commande";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)";
$sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")";
$resql2 = $db->query($sql);
- if ($resql2)
- {
+ if ($resql2) {
$delivery_date = $db->jdate($obj->delivery_date);
$sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
@@ -2104,8 +2043,7 @@ function migrate_commande_livraison($db, $langs, $conf)
$sqlu .= ", date_livraison='".$db->idate($delivery_date)."'";
$sqlu .= " WHERE rowid = ".$obj->rowid;
$resql3 = $db->query($sqlu);
- if (!$resql3)
- {
+ if (!$resql3) {
$error++;
dol_print_error($db);
}
@@ -2118,8 +2056,7 @@ function migrate_commande_livraison($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
print $langs->trans('FieldRenamed')." \n";
@@ -2158,8 +2095,7 @@ function migrate_detail_livraison($db, $langs, $conf)
// If not this means migration was already done.
$result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$error = 0;
$db->begin();
@@ -2169,15 +2105,12 @@ function migrate_detail_livraison($db, $langs, $conf)
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
$sql .= " WHERE ld.fk_commande_ligne = cd.rowid";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET";
@@ -2188,15 +2121,13 @@ function migrate_detail_livraison($db, $langs, $conf)
$sql .= " WHERE fk_commande_ligne = ".$obj->rowid;
$resql2 = $db->query($sql);
- if ($resql2)
- {
+ if ($resql2) {
$sql = "SELECT total_ht";
$sql .= " FROM ".MAIN_DB_PREFIX."livraison";
$sql .= " WHERE rowid = ".$obj->fk_livraison;
$resql3 = $db->query($sql);
- if ($resql3)
- {
+ if ($resql3) {
$obju = $db->fetch_object($resql3);
$total_ht = $obju->total_ht + $obj->total_ht;
@@ -2204,8 +2135,7 @@ function migrate_detail_livraison($db, $langs, $conf)
$sqlu .= " total_ht='".$db->escape($total_ht)."'";
$sqlu .= " WHERE rowid=".$obj->fk_livraison;
$resql4 = $db->query($sqlu);
- if (!$resql4)
- {
+ if (!$resql4) {
$error++;
dol_print_error($db);
}
@@ -2222,8 +2152,7 @@ function migrate_detail_livraison($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
print $langs->trans('FieldRenamed')." \n";
@@ -2238,8 +2167,7 @@ function migrate_detail_livraison($db, $langs, $conf)
} else {
$result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line");
$obj = $db->fetch_object($result);
- if (!$obj)
- {
+ if (!$obj) {
$sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
$db->query($sql);
}
@@ -2273,15 +2201,12 @@ function migrate_stocks($db, $langs, $conf)
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql .= " GROUP BY fk_product";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
@@ -2289,8 +2214,7 @@ function migrate_stocks($db, $langs, $conf)
$sql .= " WHERE rowid=".$obj->fk_product;
$resql2 = $db->query($sql);
- if ($resql2)
- {
+ if ($resql2) {
} else {
$error++;
dol_print_error($db);
@@ -2300,8 +2224,7 @@ function migrate_stocks($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -2334,8 +2257,7 @@ function migrate_menus($db, $langs, $conf)
$error = 0;
- if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint"))
- {
+ if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) {
$db->begin();
$sql = "SELECT m.rowid, mc.action";
@@ -2343,14 +2265,11 @@ function migrate_menus($db, $langs, $conf)
$sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
$sql .= " AND m.enabled = '1'";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
@@ -2359,8 +2278,7 @@ function migrate_menus($db, $langs, $conf)
$sql .= " AND enabled = '1'";
$resql2 = $db->query($sql);
- if ($resql2)
- {
+ if ($resql2) {
} else {
$error++;
dol_print_error($db);
@@ -2370,8 +2288,7 @@ function migrate_menus($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -2407,8 +2324,7 @@ function migrate_commande_deliveryaddress($db, $langs, $conf)
$error = 0;
- if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp"))
- {
+ if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) {
$db->begin();
$sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition";
@@ -2418,15 +2334,12 @@ function migrate_commande_deliveryaddress($db, $langs, $conf)
$sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
@@ -2434,8 +2347,7 @@ function migrate_commande_deliveryaddress($db, $langs, $conf)
$sql .= " WHERE rowid=".$obj->fk_expedition;
$resql2 = $db->query($sql);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
@@ -2446,8 +2358,7 @@ function migrate_commande_deliveryaddress($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -2476,10 +2387,8 @@ function migrate_restore_missing_links($db, $langs, $conf)
{
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
- if (($db->type == 'mysql' || $db->type == 'mysqli'))
- {
- if (versioncompare($db->getVersionArray(), array(4, 0)) < 0)
- {
+ if (($db->type == 'mysql' || $db->type == 'mysqli')) {
+ if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
return 0;
}
@@ -2506,15 +2415,12 @@ function migrate_restore_missing_links($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this. ';
@@ -2523,18 +2429,18 @@ function migrate_restore_missing_links($db, $langs, $conf)
$sql .= " WHERE rowid=".$obj->field;
$resql2 = $db->query($sql);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
//print ". ";
$i++;
}
- } else print $langs->trans('AlreadyDone')." \n";
+ } else {
+ print $langs->trans('AlreadyDone')." \n";
+ }
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -2566,15 +2472,12 @@ function migrate_restore_missing_links($db, $langs, $conf)
dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this. ';
@@ -2583,8 +2486,7 @@ function migrate_restore_missing_links($db, $langs, $conf)
$sql .= " WHERE rowid=".$obj->field;
$resql2 = $db->query($sql);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
@@ -2595,8 +2497,7 @@ function migrate_restore_missing_links($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -2628,23 +2529,19 @@ function migrate_project_user_resp($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
$error = 0;
$db->begin();
$sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
@@ -2661,11 +2558,9 @@ function migrate_project_user_resp($db, $langs, $conf)
$sql2 .= ", ".$obj->fk_user_resp;
$sql2 .= ")";
- if ($obj->fk_user_resp > 0)
- {
+ if ($obj->fk_user_resp > 0) {
$resql2 = $db->query($sql2);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
@@ -2676,11 +2571,9 @@ function migrate_project_user_resp($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp";
- if ($db->query($sqlDrop))
- {
+ if ($db->query($sqlDrop)) {
$db->commit();
} else {
$db->rollback();
@@ -2715,23 +2608,19 @@ function migrate_project_task_actors($db, $langs, $conf)
print ' ';
print ''.$langs->trans('MigrationProjectTaskActors')." \n";
- if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors"))
- {
+ if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) {
$error = 0;
$db->begin();
$sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
@@ -2750,8 +2639,7 @@ function migrate_project_task_actors($db, $langs, $conf)
$resql2 = $db->query($sql2);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
@@ -2760,11 +2648,9 @@ function migrate_project_task_actors($db, $langs, $conf)
}
}
- if ($error == 0)
- {
+ if ($error == 0) {
$sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors";
- if ($db->query($sqlDrop))
- {
+ if ($db->query($sqlDrop)) {
$db->commit();
} else {
$db->rollback();
@@ -2804,8 +2690,7 @@ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $so
$error = 0;
- if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table))
- {
+ if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table);
$db->begin();
@@ -2814,15 +2699,12 @@ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $so
$sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -2838,8 +2720,7 @@ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $so
$sqlInsert .= ")";
$result = $db->query($sqlInsert);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -2850,11 +2731,9 @@ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $so
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$table;
- if ($db->query($sqlDrop))
- {
+ if ($db->query($sqlDrop)) {
$db->commit();
} else {
$db->rollback();
@@ -2897,22 +2776,18 @@ function migrate_project_task_time($db, $langs, $conf)
$sql = "SELECT rowid, fk_task, task_duration";
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
$totaltime = array();
$oldtime = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
- if ($obj->task_duration > 0)
- {
+ if ($obj->task_duration > 0) {
// convert to second
// only for int time and float time ex: 1,75 for 1h45
list($hour, $min) = explode('.', $obj->task_duration);
@@ -2925,36 +2800,37 @@ function migrate_project_task_time($db, $langs, $conf)
$sql2 .= " WHERE rowid = ".$obj->rowid;
$resql2 = $db->query($sql2);
- if (!$resql2)
- {
+ if (!$resql2) {
$error++;
dol_print_error($db);
}
print ". ";
$oldtime++;
- if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $newtime;
- else $totaltime[$obj->fk_task] = $newtime;
+ if (!empty($totaltime[$obj->fk_task])) {
+ $totaltime[$obj->fk_task] += $newtime;
+ } else {
+ $totaltime[$obj->fk_task] = $newtime;
+ }
} else {
- if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $obj->task_duration;
- else $totaltime[$obj->fk_task] = $obj->task_duration;
+ if (!empty($totaltime[$obj->fk_task])) {
+ $totaltime[$obj->fk_task] += $obj->task_duration;
+ } else {
+ $totaltime[$obj->fk_task] = $obj->task_duration;
+ }
}
$i++;
}
- if ($error == 0)
- {
- if ($oldtime > 0)
- {
- foreach ($totaltime as $taskid => $total_duration)
- {
+ if ($error == 0) {
+ if ($oldtime > 0) {
+ foreach ($totaltime as $taskid => $total_duration) {
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
$sql .= " duration_effective = ".$total_duration;
$sql .= " WHERE rowid = ".$taskid;
$resql = $db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$error++;
dol_print_error($db);
}
@@ -2972,8 +2848,7 @@ function migrate_project_task_time($db, $langs, $conf)
dol_print_error($db);
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
$db->rollback();
@@ -3003,8 +2878,7 @@ function migrate_customerorder_shipping($db, $langs, $conf)
$result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery");
$obj1 = $db->fetch_object($result1);
$obj2 = $db->fetch_object($result2);
- if (!$obj1 && !$obj2)
- {
+ if (!$obj1 && !$obj2) {
dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping");
$db->begin();
@@ -3012,8 +2886,7 @@ function migrate_customerorder_shipping($db, $langs, $conf)
$sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
$sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
- if ($db->query($sqlAdd1) && $db->query($sqlAdd2))
- {
+ if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
$sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
$sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el";
@@ -3022,15 +2895,12 @@ function migrate_customerorder_shipping($db, $langs, $conf)
$sqlSelect .= " AND el.targettype = 'shipping'";
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
@@ -3039,8 +2909,7 @@ function migrate_customerorder_shipping($db, $langs, $conf)
$sqlUpdate .= " WHERE rowid = ".$obj->shipping_id;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3051,8 +2920,7 @@ function migrate_customerorder_shipping($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
dol_print_error($db);
@@ -3092,8 +2960,7 @@ function migrate_shipping_delivery($db, $langs, $conf)
$result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition");
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
dolibarr_install_syslog("upgrade2::migrate_shipping_delivery");
$db->begin();
@@ -3103,15 +2970,12 @@ function migrate_shipping_delivery($db, $langs, $conf)
$sqlSelect .= " WHERE fk_expedition is not null";
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -3127,14 +2991,12 @@ function migrate_shipping_delivery($db, $langs, $conf)
$sqlInsert .= ")";
$result = $db->query($sqlInsert);
- if ($result)
- {
+ if ($result) {
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL";
$sqlUpdate .= " WHERE rowid = ".$obj->rowid;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3149,8 +3011,7 @@ function migrate_shipping_delivery($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
$db->query($sqlDelete);
@@ -3209,15 +3070,12 @@ function migrate_shipping_delivery2($db, $langs, $conf)
$sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")";
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
@@ -3226,8 +3084,7 @@ function migrate_shipping_delivery2($db, $langs, $conf)
$sqlUpdate .= " WHERE rowid = ".$obj->delivery_id;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3238,8 +3095,7 @@ function migrate_shipping_delivery2($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if ($error == 0)
- {
+ if ($error == 0) {
$db->commit();
} else {
dol_print_error($db);
@@ -3277,12 +3133,10 @@ function migrate_actioncomm_element($db, $langs, $conf)
'invoice_supplier' => 'fk_supplier_invoice'
);
- foreach ($elements as $type => $field)
- {
+ foreach ($elements as $type => $field) {
$result = $db->DDLDescTable(MAIN_DB_PREFIX."actioncomm", $field);
$obj = $db->fetch_object($result);
- if ($obj)
- {
+ if ($obj) {
dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=".$field);
$db->begin();
@@ -3294,8 +3148,7 @@ function migrate_actioncomm_element($db, $langs, $conf)
$sql .= " AND elementtype IS NULL";
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$db->commit();
// DDL commands must not be inside a transaction
@@ -3338,8 +3191,7 @@ function migrate_mode_reglement($db, $langs, $conf)
);
$count = 0;
- foreach ($elements['old_id'] as $key => $old_id)
- {
+ foreach ($elements['old_id'] as $key => $old_id) {
$error = 0;
dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);
@@ -3350,11 +3202,9 @@ function migrate_mode_reglement($db, $langs, $conf)
$sqlSelect .= " AND code = '".$db->escape($elements['code'][$key])."'";
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
- if ($num)
- {
+ if ($num) {
$count++;
$db->begin();
@@ -3371,25 +3221,21 @@ function migrate_mode_reglement($db, $langs, $conf)
$sql .= " AND code = '".$db->escape($elements['code'][$key])."'";
$resql = $db->query($sql);
- if ($resqla && $resql)
- {
- foreach ($elements['tables'] as $table)
- {
+ if ($resqla && $resql) {
+ foreach ($elements['tables'] as $table) {
$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
$sql .= "fk_mode_reglement = ".$elements['new_id'][$key];
$sql .= " WHERE fk_mode_reglement = ".$old_id;
$resql = $db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
dol_print_error($db);
$error++;
}
print ". ";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
dol_print_error($db);
@@ -3403,7 +3249,9 @@ function migrate_mode_reglement($db, $langs, $conf)
}
}
- if ($count == 0) print $langs->trans('AlreadyDone')." \n";
+ if ($count == 0) {
+ print $langs->trans('AlreadyDone')." \n";
+ }
print ' | ';
@@ -3421,26 +3269,20 @@ function migrate_mode_reglement($db, $langs, $conf)
function migrate_clean_association($db, $langs, $conf)
{
$result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association");
- if ($result) // result defined for version 3.2 or -
- {
+ if ($result) { // result defined for version 3.2 or -
$obj = $db->fetch_object($result);
- if ($obj) // It table categorie_association exists
- {
+ if ($obj) { // It table categorie_association exists
$couples = array();
$filles = array();
$sql = "SELECT fk_categorie_mere, fk_categorie_fille";
$sql .= " FROM ".MAIN_DB_PREFIX."categorie_association";
dolibarr_install_syslog("upgrade: search duplicate");
$resql = $db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $db->num_rows($resql);
- while ($obj = $db->fetch_object($resql))
- {
- if (!isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent).
- {
- if ($obj->fk_categorie_mere != $obj->fk_categorie_fille)
- {
+ while ($obj = $db->fetch_object($resql)) {
+ if (!isset($filles[$obj->fk_categorie_fille])) { // Only one record as child (a child has only on parent).
+ if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
$filles[$obj->fk_categorie_fille] = 1; // Set record for this child
$couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille);
}
@@ -3450,8 +3292,7 @@ function migrate_clean_association($db, $langs, $conf)
dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
// If there is duplicates couples or child with two parents
- if (count($couples) > 0 && $num > count($couples))
- {
+ if (count($couples) > 0 && $num > count($couples)) {
$error = 0;
$db->begin();
@@ -3460,21 +3301,20 @@ function migrate_clean_association($db, $langs, $conf)
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
dolibarr_install_syslog("upgrade: delete association");
$resqld = $db->query($sql);
- if ($resqld)
- {
+ if ($resqld) {
// And we insert only each record once
- foreach ($couples as $key => $val)
- {
+ foreach ($couples as $key => $val) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
$sql .= " VALUES(".$val['mere'].", ".$val['fille'].")";
dolibarr_install_syslog("upgrade: insert association");
$resqli = $db->query($sql);
- if (!$resqli) $error++;
+ if (!$resqli) {
+ $error++;
+ }
}
}
- if (!$error)
- {
+ if (!$error) {
print '| '.$langs->trans("MigrationCategorieAssociation").' | ';
print ''.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).') | ';
$db->commit();
@@ -3510,8 +3350,7 @@ function migrate_categorie_association($db, $langs, $conf)
$error = 0;
- if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association"))
- {
+ if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association")) {
dolibarr_install_syslog("upgrade2::migrate_categorie_association");
$db->begin();
@@ -3520,15 +3359,12 @@ function migrate_categorie_association($db, $langs, $conf)
$sqlSelect .= " FROM ".MAIN_DB_PREFIX."categorie_association";
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
@@ -3536,8 +3372,7 @@ function migrate_categorie_association($db, $langs, $conf)
$sqlUpdate .= " WHERE rowid = ".$obj->fk_categorie_fille;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3548,8 +3383,7 @@ function migrate_categorie_association($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
// TODO DROP table in the next release
/*
$sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."categorie_association";
@@ -3607,23 +3441,19 @@ function migrate_event_assignement($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
$sqlUpdate .= "VALUES(".$obj->id.", 'user', ".$obj->fk_user_action.")";
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3634,8 +3464,7 @@ function migrate_event_assignement($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -3678,23 +3507,19 @@ function migrate_event_assignement_contact($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
$sqlUpdate .= "VALUES(".$obj->id.", 'socpeople', ".$obj->fk_contact.")";
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3705,8 +3530,7 @@ function migrate_event_assignement_contact($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -3752,34 +3576,28 @@ function migrate_reset_blocked_log($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
print 'Process entity '.$obj->entity;
$sqlSearch = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."blockedlog WHERE action = 'MODULE_SET' and entity = ".$obj->entity;
$resqlSearch = $db->query($sqlSearch);
- if ($resqlSearch)
- {
+ if ($resqlSearch) {
$objSearch = $db->fetch_object($resqlSearch);
//var_dump($objSearch);
- if ($objSearch && $objSearch->nb == 0)
- {
+ if ($objSearch && $objSearch->nb == 0) {
print ' - Record for entity must be reset...';
$sqlUpdate = "DELETE FROM ".MAIN_DB_PREFIX."blockedlog";
$sqlUpdate .= " WHERE entity = ".$obj->entity;
$resqlUpdate = $db->query($sqlUpdate);
- if (!$resqlUpdate)
- {
+ if (!$resqlUpdate) {
$error++;
dol_print_error($db);
} else {
@@ -3812,8 +3630,7 @@ function migrate_reset_blocked_log($db, $langs, $conf)
print $langs->trans('NothingToDo')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -3855,15 +3672,12 @@ function migrate_remise_entity($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
@@ -3871,8 +3685,7 @@ function migrate_remise_entity($db, $langs, $conf)
$sqlUpdate .= " WHERE rowid = ".$obj->rowid;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3884,8 +3697,7 @@ function migrate_remise_entity($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -3924,26 +3736,21 @@ function migrate_remise_except_entity($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
- if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture))
- {
+ if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
$fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
$sqlSelect2 = "SELECT f.entity";
$sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sqlSelect2 .= " WHERE f.rowid = ".$fk_facture;
- } elseif (!empty($obj->fk_facture_line))
- {
+ } elseif (!empty($obj->fk_facture_line)) {
$sqlSelect2 = "SELECT f.entity";
$sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
$sqlSelect2 .= " WHERE fd.rowid = ".$obj->fk_facture_line;
@@ -3955,10 +3762,8 @@ function migrate_remise_except_entity($db, $langs, $conf)
}
$resql2 = $db->query($sqlSelect2);
- if ($resql2)
- {
- if ($db->num_rows($resql2) > 0)
- {
+ if ($resql2) {
+ if ($db->num_rows($resql2) > 0) {
$obj2 = $db->fetch_object($resql2);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
@@ -3966,8 +3771,7 @@ function migrate_remise_except_entity($db, $langs, $conf)
$sqlUpdate .= " WHERE rowid = ".$obj->rowid;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -3984,8 +3788,7 @@ function migrate_remise_except_entity($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -4025,15 +3828,12 @@ function migrate_user_rights_entity($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
@@ -4041,8 +3841,7 @@ function migrate_user_rights_entity($db, $langs, $conf)
$sqlUpdate .= " WHERE fk_user = ".$obj->rowid;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -4054,8 +3853,7 @@ function migrate_user_rights_entity($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -4095,15 +3893,12 @@ function migrate_usergroup_rights_entity($db, $langs, $conf)
//print $sqlSelect;
$resql = $db->query($sqlSelect);
- if ($resql)
- {
+ if ($resql) {
$i = 0;
$num = $db->num_rows($resql);
- if ($num)
- {
- while ($i < $num)
- {
+ if ($num) {
+ while ($i < $num) {
$obj = $db->fetch_object($resql);
$sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
@@ -4111,8 +3906,7 @@ function migrate_usergroup_rights_entity($db, $langs, $conf)
$sqlUpdate .= " WHERE fk_usergroup = ".$obj->rowid;
$result = $db->query($sqlUpdate);
- if (!$result)
- {
+ if (!$result) {
$error++;
dol_print_error($db);
}
@@ -4124,8 +3918,7 @@ function migrate_usergroup_rights_entity($db, $langs, $conf)
print $langs->trans('AlreadyDone')." \n";
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
} else {
$db->rollback();
@@ -4153,8 +3946,7 @@ function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
{
dolibarr_install_syslog("upgrade2::migrate_rename_directories");
- if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname))
- {
+ if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname);
@rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
}
@@ -4296,12 +4088,16 @@ function migrate_delete_old_dir($db, $langs, $conf)
*/
function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $force = 0)
{
- if (count($listofmodule) == 0) return;
+ if (count($listofmodule) == 0) {
+ return;
+ }
dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".join(',', array_keys($listofmodule)));
foreach ($listofmodule as $moduletoreload => $reloadmode) { // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
- if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) continue; // Discard reload if module not enabled
+ if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
+ continue; // Discard reload if module not enabled
+ }
$mod = null;
@@ -4485,10 +4281,8 @@ function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $fo
} else { // Other generic cases/modules
$reg = array();
$tmp = preg_match('/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
- if (!empty($reg[1]))
- {
- if (strtoupper($moduletoreload) == $moduletoreload) // If key is un uppercase
- {
+ if (!empty($reg[1])) {
+ if (strtoupper($moduletoreload) == $moduletoreload) { // If key is un uppercase
$moduletoreloadshort = ucfirst(strtolower($reg[1]));
} else // If key is a mix of up and low case
{
@@ -4525,8 +4319,7 @@ function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $fo
}
}
- if (!empty($mod) && is_object($mod))
- {
+ if (!empty($mod) && is_object($mod)) {
print '| ';
print ''.$langs->trans('Upgrade').': ';
print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
@@ -4557,13 +4350,11 @@ function migrate_reload_menu($db, $langs, $conf)
// Define list of menu handlers to initialize
$listofmenuhandler = array();
if ($conf->global->MAIN_MENU_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE == 'auguria_menu'
- || $conf->global->MAIN_MENUFRONT_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE == 'auguria_menu')
- {
+ || $conf->global->MAIN_MENUFRONT_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE == 'auguria_menu') {
$listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers
}
- foreach ($listofmenuhandler as $key => $val)
- {
+ foreach ($listofmenuhandler as $key => $val) {
print ' | ';
//print "x".$key;
@@ -4573,8 +4364,7 @@ function migrate_reload_menu($db, $langs, $conf)
// Load sql ini_menu_handler.sql file
$dir = DOL_DOCUMENT_ROOT."/core/menus/";
$file = 'init_menu_'.$key.'.sql';
- if (file_exists($dir.$file))
- {
+ if (file_exists($dir.$file)) {
$result = run_sql($dir.$file, 1, '', 1, $key);
}
@@ -4598,14 +4388,14 @@ function migrate_user_photospath()
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$fuser = new User($db);
- if (!is_object($user)) $user = $fuser; // To avoid error during migration
+ if (!is_object($user)) {
+ $user = $fuser; // To avoid error during migration
+ }
$sql = "SELECT rowid as uid from ".MAIN_DB_PREFIX."user"; // Get list of all users
$resql = $db->query($sql);
- if ($resql)
- {
- while ($obj = $db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $db->fetch_object($resql)) {
$fuser->fetch($obj->uid);
//echo ' '.$fuser->id.' -> '.$fuser->entity;
$entity = (empty($fuser->entity) ? 1 : $fuser->entity);
@@ -4615,8 +4405,7 @@ function migrate_user_photospath()
$dir = $conf->user->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
}
- if ($dir)
- {
+ if ($dir) {
//print "Process user id ".$fuser->id." \n";
$origin = $dir.'/'.get_exdir($fuser->id, 2, 0, 1, $fuser, 'user'); // Use old behaviour to get x/y path
$destin = $dir.'/'.$fuser->id;
@@ -4626,26 +4415,23 @@ function migrate_user_photospath()
dol_mkdir($destin);
//echo ' '.$origin.' -> '.$destin;
- if (dol_is_dir($origin))
- {
+ if (dol_is_dir($origin)) {
$handle = opendir($origin_osencoded);
- if (is_resource($handle))
- {
- while (($file = readdir($handle)) !== false)
- {
- if ($file == '.' || $file == '..') continue;
+ if (is_resource($handle)) {
+ while (($file = readdir($handle)) !== false) {
+ if ($file == '.' || $file == '..') {
+ continue;
+ }
- if (dol_is_dir($origin.'/'.$file)) // it is a dir (like 'thumbs')
- {
+ if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
$thumbs = opendir($origin_osencoded.'/'.$file);
- if (is_resource($thumbs))
- {
- dol_mkdir($destin.'/'.$file);
- while (($thumb = readdir($thumbs)) !== false)
- {
- if (!dol_is_file($destin.'/'.$file.'/'.$thumb))
- {
- if ($thumb == '.' || $thumb == '..') continue;
+ if (is_resource($thumbs)) {
+ dol_mkdir($destin.'/'.$file);
+ while (($thumb = readdir($thumbs)) !== false) {
+ if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
+ if ($thumb == '.' || $thumb == '..') {
+ continue;
+ }
//print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.' '."\n";
print '.';
@@ -4657,8 +4443,7 @@ function migrate_user_photospath()
}
} else // it is a file
{
- if (!dol_is_file($destin.'/'.$file))
- {
+ if (!dol_is_file($destin.'/'.$file)) {
//print $origin.'/'.$file.' -> '.$destin.'/'.$file.' '."\n";
print '.';
dol_copy($origin.'/'.$file, $destin.'/'.$file, 0, 0);
| |