39 include_once
'inc.php';
40 if (!file_exists($conffile)) {
41 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").';
43 require_once $conffile;
44 require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
55 $err = error_reporting();
58 error_reporting($err);
61 $setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
62 $langs->setDefaultLang($setuplang);
63 $versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
64 $versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
65 $dirmodule = ((
GETPOST(
"dirmodule",
'alpha', 3) &&
GETPOST(
"dirmodule",
'alpha', 3) !=
'ignoredbversion')) ?
GETPOST(
"dirmodule",
'alpha', 3) : ((empty($argv[3]) || $argv[3] ==
'ignoredbversion') ?
'' : $argv[3]);
66 $ignoredbversion = (
GETPOST(
'ignoredbversion',
'alpha', 3) ==
'ignoredbversion') ?
GETPOST(
'ignoredbversion',
'alpha', 3) : ((empty($argv[3]) || $argv[3] !=
'ignoredbversion') ?
'' : $argv[3]);
68 $langs->loadLangs(array(
"admin",
"install",
"other",
"errors"));
70 if ($dolibarr_main_db_type ==
"mysqli") {
73 if ($dolibarr_main_db_type ==
"pgsql") {
76 if ($dolibarr_main_db_type ==
"mssql") {
82 if (!is_object($conf)) {
91 if (!$versionfrom && !$versionto) {
92 print
'Error: Parameter versionfrom or versionto missing.'.
"\n";
93 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
95 $sapi_type = php_sapi_name();
96 $script_file = basename(__FILE__);
98 if (substr($sapi_type, 0, 3) ==
'cli') {
99 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c\n";
105 pHeader(
'',
"upgrade2",
GETPOST(
'action',
'aZ09'),
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
110 if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
113 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
114 print
'<span class="inline-block">'.$langs->trans(
"DatabaseMigration").
'</span></h3>';
116 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
120 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
121 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
122 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
123 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
124 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
125 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
127 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
132 $conf->db->type = $dolibarr_main_db_type;
133 $conf->db->host = $dolibarr_main_db_host;
134 $conf->db->port = $dolibarr_main_db_port;
135 $conf->db->name = $dolibarr_main_db_name;
136 $conf->db->user = $dolibarr_main_db_user;
137 $conf->db->pass = $dolibarr_main_db_pass;
140 if (empty($dolibarr_main_db_encryption)) {
141 $dolibarr_main_db_encryption = 0;
143 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
144 if (empty($dolibarr_main_db_cryptkey)) {
145 $dolibarr_main_db_cryptkey =
'';
147 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
149 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
152 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
155 if ($db->connected) {
156 print
'<tr><td class="nowrap">';
157 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
'</span></td></tr>'.
"\n";
158 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ServerConnection").
": $dolibarr_main_db_host ".$langs->transnoentities(
"OK"));
161 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="error">'.$langs->transnoentities(
"Error").
"</span></td></tr>\n";
162 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
167 if ($db->database_selected) {
168 print
'<tr><td class="nowrap">';
169 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
"</span></td></tr>\n";
173 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="ok">'.$langs->trans(
"Error").
"</span></td></tr>\n";
174 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
181 $version = $db->getVersion();
182 $versionarray = $db->getVersionArray();
183 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
184 print
'<td class="right">'.$version.
'</td></tr>';
186 if ($db->type ==
'mysqli' && function_exists(
'mysqli_get_charset')) {
187 $tmparray = $db->db->get_charset();
188 print
'<tr><td>'.$langs->trans(
"ClientCharset").
'</td>';
189 print
'<td class="right">'.$tmparray->charset.
'</td></tr>';
191 print
'<tr><td>'.$langs->trans(
"ClientSortingCharset").
'</td>';
192 print
'<td class="right">'.$tmparray->collation.
'</td></tr>';
197 $versionmindb = explode(
'.', $db::VERSIONMIN);
199 if (count($versionmindb) && count($versionarray)
202 print
"<tr><td>".$langs->trans(
"ErrorDatabaseVersionTooLow", join(
'.', $versionarray), join(
'.', $versionmindb)).
'</td><td class="right"><span class="error">'.$langs->trans(
"Error").
"</span></td></tr>\n";
203 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionTooLow", join(
'.', $versionarray), join(
'.', $versionmindb)));
208 if (empty($ignoredbversion)) {
209 $dbversion_disallowed = array(
210 array(
'type'=>
'mysql',
'version'=>array(5, 5, 40)),
211 array(
'type'=>
'mysqli',
'version'=>array(5, 5, 40))
215 $listofforbiddenversion =
'';
216 foreach ($dbversion_disallowed as $dbversion_totest) {
217 if ($dbversion_totest[
'type'] == $db->type) {
218 $listofforbiddenversion .= ($listofforbiddenversion ?
', ' :
'').join(
'.', $dbversion_totest[
'version']);
221 foreach ($dbversion_disallowed as $dbversion_totest) {
223 if ($dbversion_totest[
'type'] == $db->type
224 && (
versioncompare($dbversion_totest[
'version'], $versionarray) == 0 ||
versioncompare($dbversion_totest[
'version'], $versionarray) <= -4 ||
versioncompare($dbversion_totest[
'version'], $versionarray) >= 4)
227 print
'<tr><td><div class="warning">'.$langs->trans(
"ErrorDatabaseVersionForbiddenForMigration", join(
'.', $versionarray), $listofforbiddenversion).
"</div></td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>\n";
228 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionForbiddenForMigration", join(
'.', $versionarray), $listofforbiddenversion));
238 print
'<tr><td colspan="2"><span class="opacitymedium messagebepatient">'.$langs->trans(
"PleaseBePatient").
'</span></td></tr>';
243 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
250 if ($ok && preg_match(
'/mysql/', $db->type)) {
251 $versioncommande = array(4, 0, 0);
252 if (count($versioncommande) && count($versionarray)
259 MAIN_DB_PREFIX.
'adherent_options',
260 MAIN_DB_PREFIX.
'bank_class',
261 MAIN_DB_PREFIX.
'c_ecotaxe',
262 MAIN_DB_PREFIX.
'c_methode_commande_fournisseur',
263 MAIN_DB_PREFIX.
'c_input_method'
266 $listtables = $db->DDLListTables($conf->db->name,
'');
268 foreach ($listtables as $val) {
270 if (preg_match(
'/^'.MAIN_DB_PREFIX.
'/', $val)) {
272 $sql =
"SHOW CREATE TABLE ".$val;
273 $resql = $db->query($sql);
275 $values = $db->fetch_array(
$resql);
277 $createsql = $values[1];
279 while (preg_match(
'/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
280 $sqldrop =
"ALTER TABLE ".$val.
" DROP FOREIGN KEY ".$reg[1];
281 $resqldrop = $db->query($sqldrop);
283 print
'<tr><td colspan="2">'.$sqldrop.
";</td></tr>\n";
285 $createsql = preg_replace(
'/CONSTRAINT `'.$reg[1].
'`/i',
'XXX', $createsql);
290 if ($db->lasterrno() !=
'DB_ERROR_NOSUCHTABLE') {
291 print
'<tr><td colspan="2"><span class="error">'.dol_escape_htmltag($sql).
' : '.
dol_escape_htmltag($db->lasterror()).
"</span></td></tr>\n";
303 $dir =
"mysql/migration/";
304 if (!empty($dirmodule)) {
310 $newversionfrom = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionfrom);
311 $newversionto = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionto);
316 $from =
'^'.preg_quote($newversionfrom,
'/');
317 $to = preg_quote($newversionto.
'.sql',
'/').
'$';
320 $filesindir = array();
321 $handle = opendir($dir);
322 if (is_resource($handle)) {
323 while (($file = readdir($handle)) !==
false) {
324 if (preg_match(
'/\.sql$/i', $file)) {
325 $filesindir[] = $file;
330 print
'<div class="error">'.$langs->trans(
"ErrorCanNotReadDir", $dir).
'</div>';
334 foreach ($filesindir as $file) {
335 if (preg_match(
'/'.$from.
'\-/i', $file)) {
337 } elseif (preg_match(
'/\-'.$to.
'/i', $file)) {
342 if (count($filelist) == 0) {
343 print
'<div class="error">'.$langs->trans(
"ErrorNoMigrationFilesFoundForParameters").
'</div>';
345 $listoffileprocessed = array();
348 foreach ($filelist as $file) {
349 if (in_array($dir.$file, $listoffileprocessed)) {
353 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
354 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
'</td><td class="right">'.$file.
'</td></tr>'.
"\n";
357 $ok =
run_sql($dir.$file, 0,
'', 1,
'',
'default', 32768, 0, 0, 2);
358 $listoffileprocessed[$dir.$file] = $dir.$file;
363 $modulesfile = array();
364 foreach ($conf->file->dol_document_root as $type => $dirroot) {
365 $handlemodule = @opendir($dirroot);
366 if (is_resource($handlemodule)) {
367 while (($filemodule = readdir($handlemodule)) !==
false) {
368 if (!preg_match(
'/\./', $filemodule) && is_dir($dirroot.
'/'.$filemodule.
'/sql')) {
370 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file)) {
371 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file] =
'/'.$filemodule.
'/sql/dolibarr_'.$file;
373 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql')) {
374 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql'] =
'/'.$filemodule.
'/sql/dolibarr_allversions.sql';
378 closedir($handlemodule);
382 if (count($modulesfile)) {
383 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
385 foreach ($modulesfile as $modulefilelong => $modulefileshort) {
386 if (in_array($modulefilelong, $listoffileprocessed)) {
390 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules)</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
393 $okmodule =
run_sql($modulefilelong, 0,
'', 1);
394 $listoffileprocessed[$modulefilelong] = $modulefilelong;
403 if ($db->connected) {
409 if (empty($actiondone)) {
410 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
414 if (!$ok && isset($argv[1])) {
420 $nonext = (!$ok && empty($_GET[
"ignoreerrors"])) ? 2 : 0;
426 if ($db->connected) {
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0)
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.