41define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
42include_once
'inc.php';
49 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").';
69@phan-var-force string $dolibarr_main_db_type
71require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
80$err = error_reporting();
86$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
87$langs->setDefaultLang($setuplang);
88$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
89$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
90$dirmodule = ((
GETPOST(
"dirmodule",
'alpha', 3) &&
GETPOST(
"dirmodule",
'alpha', 3) !=
'ignoredbversion')) ?
GETPOST(
"dirmodule",
'alpha', 3) : ((empty($argv[3]) || $argv[3] ==
'ignoredbversion') ?
'' : $argv[3]);
91$ignoredbversion = (
GETPOST(
'ignoredbversion',
'alpha', 3) ==
'ignoredbversion') ?
GETPOST(
'ignoredbversion',
'alpha', 3) : ((empty($argv[3]) || $argv[3] !=
'ignoredbversion') ?
'' : $argv[3]);
93$langs->loadLangs(array(
"admin",
"install",
"other",
"errors"));
97if (!is_object(
$conf)) {
106if (!$versionfrom && !$versionto) {
107 print
'Error: Parameter versionfrom or versionto missing.'.
"\n";
108 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
110 $sapi_type = php_sapi_name();
111 $script_file = basename(__FILE__);
113 if (substr($sapi_type, 0, 3) ==
'cli') {
114 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c\n";
120pHeader(
'',
"upgrade2",
GETPOST(
'action',
'aZ09'),
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
126if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
129 print
'<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> ';
130 print
'<span class="inline-block valignmiddle">'.$langs->trans(
"DatabaseMigration").
'</span></h3>';
132 print
'<table cellspacing="0" cellpadding="1" class="centpercent">';
135 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/(crypted|dolcrypt):/i', (
string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
136 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
137 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', (
string) $dolibarr_main_db_pass)) {
138 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', (
string) $dolibarr_main_db_pass);
139 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
140 $dolibarr_main_db_pass =
dol_decode((
string) $dolibarr_main_db_pass);
141 } elseif (preg_match(
'/dolcrypt:/i', (
string) $dolibarr_main_db_pass)) {
142 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
143 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
145 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
158 if (empty($dolibarr_main_db_encryption)) {
159 $dolibarr_main_db_encryption = 0;
161 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
162 if (empty($dolibarr_main_db_cryptkey)) {
163 $dolibarr_main_db_cryptkey =
'';
165 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
171 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
174 if (
$db->connected) {
175 print
'<tr><td class="nowrap">';
176 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"Success").
'</span></td></tr>'.
"\n";
177 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ServerConnection").
": $dolibarr_main_db_host ".$langs->transnoentities(
"Success"));
180 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="error">'.$langs->transnoentities(
"Error").
"</span></td></tr>\n";
181 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
186 if (
$db->database_selected) {
187 print
'<tr><td class="nowrap">';
188 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"Success").
"</span></td></tr>\n";
192 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="neutral">'.$langs->trans(
"Error").
"</span></td></tr>\n";
193 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
199 $versionarray = array();
201 $version =
$db->getVersion();
202 $versionarray =
$db->getVersionArray();
203 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
204 print
'<td class="right">'.$version.
'</td></tr>';
206 if (
$db->type ==
'mysqli' && function_exists(
'mysqli_get_charset')) {
207 $tmparray =
$db->db->get_charset();
208 print
'<tr><td>'.$langs->trans(
"ClientCharset").
'</td>';
209 print
'<td class="right">'.$tmparray->charset.
'</td></tr>';
211 print
'<tr><td>'.$langs->trans(
"ClientSortingCharset").
'</td>';
212 print
'<td class="right">'.$tmparray->collation.
'</td></tr>';
217 $versionmindb = explode(
'.', $db::VERSIONMIN);
219 if (count($versionmindb) && count($versionarray)
222 print
"<tr><td>".$langs->trans(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)).
'</td><td class="right"><span class="error">'.$langs->trans(
"Error").
"</span></td></tr>\n";
223 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)));
228 if (empty($ignoredbversion)) {
229 $dbversion_disallowed = array(
230 array(
'type' =>
'mysql',
'version' => array(5, 5, 40)),
231 array(
'type' =>
'mysqli',
'version' => array(5, 5, 40))
235 $listofforbiddenversion =
'';
236 foreach ($dbversion_disallowed as $dbversion_totest) {
237 if ($dbversion_totest[
'type'] ==
$db->type) {
238 $listofforbiddenversion .= ($listofforbiddenversion ?
', ' :
'').implode(
'.', $dbversion_totest[
'version']);
241 foreach ($dbversion_disallowed as $dbversion_totest) {
243 if ($dbversion_totest[
'type'] ==
$db->type
244 && (
versioncompare($dbversion_totest[
'version'], $versionarray) == 0 ||
versioncompare($dbversion_totest[
'version'], $versionarray) <= -4 ||
versioncompare($dbversion_totest[
'version'], $versionarray) >= 4)
247 print
'<tr><td><div class="warning">'.$langs->trans(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion).
"</div></td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>\n";
248 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion));
258 print
'<tr><td colspan="2"><span class="opacitymedium messagebepatient">'.$langs->trans(
"PleaseBePatient").
'</span></td></tr>';
263 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
270 if ($ok && preg_match(
'/mysql/',
$db->type)) {
271 $versioncommande = array(4, 0, 0);
272 if (count($versioncommande) && count($versionarray)
279 MAIN_DB_PREFIX.
'adherent_options',
280 MAIN_DB_PREFIX.
'category_bankline',
281 MAIN_DB_PREFIX.
'c_ecotaxe',
282 MAIN_DB_PREFIX.
'c_methode_commande_fournisseur',
283 MAIN_DB_PREFIX.
'c_input_method'
286 $listtables =
$db->DDLListTables(
$conf->db->name,
'');
288 foreach ($listtables as $val) {
290 if (preg_match(
'/^'.MAIN_DB_PREFIX.
'/', $val)) {
292 $sql =
"SHOW CREATE TABLE ".$db->sanitize($val);
293 $resql =
$db->query($sql);
295 $values =
$db->fetch_array($resql);
296 if (is_array($values)) {
298 $createsql = $values[1];
300 while (preg_match(
'/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
301 $sqldrop =
"ALTER TABLE ".$val.
" DROP FOREIGN KEY ".$reg[1];
302 $resqldrop =
$db->query($sqldrop);
304 print
'<tr><td colspan="2">'.$sqldrop.
";</td></tr>\n";
306 $createsql = preg_replace(
'/CONSTRAINT `'.$reg[1].
'`/i',
'XXX', $createsql);
312 if (
$db->lasterrno() !=
'DB_ERROR_NOSUCHTABLE') {
313 print
'<tr><td colspan="2"><span class="error">'.dol_escape_htmltag($sql).
' : '.
dol_escape_htmltag(
$db->lasterror()).
"</span></td></tr>\n";
325 $dir =
"mysql/migration/";
326 if (!empty($dirmodule)) {
332 $newversionfrom = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionfrom);
333 $newversionto = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionto);
338 $from =
'^'.preg_quote($newversionfrom,
'/');
339 $to = preg_quote($newversionto.
'.sql',
'/').
'$';
342 $filesindir = array();
343 $handle = opendir($dir);
344 if (is_resource($handle)) {
345 while (($file = readdir($handle)) !==
false) {
346 if (preg_match(
'/\.sql$/i', $file)) {
347 $filesindir[] = $file;
352 print
'<div class="error">'.$langs->trans(
"ErrorCanNotReadDir", $dir).
'</div>';
356 foreach ($filesindir as $file) {
357 if (preg_match(
'/'.$from.
'\-/i', $file)) {
359 } elseif (preg_match(
'/\-'.$to.
'/i', $file)) {
364 if (count($filelist) == 0) {
365 print
'<div class="error">'.$langs->trans(
"ErrorNoMigrationFilesFoundForParameters").
'</div>';
367 $listoffileprocessed = array();
370 foreach ($filelist as $file) {
371 if (in_array($dir.$file, $listoffileprocessed)) {
375 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
376 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
'</td><td class="right">'.$file.
'</td></tr>'.
"\n";
379 $ok =
run_sql($dir.$file, 0, 0, 1,
'',
'default', 32768, 0, 0, 2, 0,
$db->database_name);
380 $listoffileprocessed[$dir.$file] = $dir.$file;
385 $modulesfile = array();
386 foreach (
$conf->file->dol_document_root as $type => $dirroot) {
387 $handlemodule = @opendir($dirroot);
388 if (is_resource($handlemodule)) {
389 while (($filemodule = readdir($handlemodule)) !==
false) {
390 if (!preg_match(
'/\./', $filemodule) && is_dir($dirroot.
'/'.$filemodule.
'/sql')) {
392 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file)) {
393 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file] =
'/'.$filemodule.
'/sql/dolibarr_'.$file;
395 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql')) {
396 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql'] =
'/'.$filemodule.
'/sql/dolibarr_allversions.sql';
400 closedir($handlemodule);
404 if (count($modulesfile)) {
405 $conf->setValues($db);
407 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
409 foreach ($modulesfile as $modulefilelong => $modulefileshort) {
410 if (in_array($modulefilelong, $listoffileprocessed)) {
413 $dirofmodule = preg_replace(
'/\//',
'', preg_replace(
'/\/sql\/[a-z0-8_]+\.sql$/',
'', $modulefileshort));
415 if (!is_null($dirofmodule) &&
isModEnabled($dirofmodule)) {
416 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules '.$dirofmodule.
')</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
419 $okmodule =
run_sql($modulefilelong, 0, 0, 1);
420 $listoffileprocessed[$modulefilelong] = $modulefilelong;
422 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules '.$dirofmodule.
')</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
423 print
'<tr><td class="nowrap">'.$langs->trans(
"ProcessMigrateScript").
'</td><td class="right"><span class="opacitymedium">Ignored (module not enabled)</span></td></tr>'.
"\n";
433 if (
$db->connected) {
439if (empty($actiondone)) {
440 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
444if (!$ok && isset($argv[1])) {
451$nonext = (!$ok && !
GETPOST(
"ignoreerrors")) ? 2 : 0;
457if ($db !==
null &&
$db->connected) {
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
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.
isModEnabled($module)
Is Dolibarr module enabled.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.