40define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
41include_once
'inc.php';
42if (!file_exists($conffile)) {
43 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").';
45require_once $conffile;
46require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
57$err = error_reporting();
63$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
64$langs->setDefaultLang($setuplang);
65$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
66$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
67$dirmodule = ((
GETPOST(
"dirmodule",
'alpha', 3) &&
GETPOST(
"dirmodule",
'alpha', 3) !=
'ignoredbversion')) ?
GETPOST(
"dirmodule",
'alpha', 3) : ((empty($argv[3]) || $argv[3] ==
'ignoredbversion') ?
'' : $argv[3]);
68$ignoredbversion = (
GETPOST(
'ignoredbversion',
'alpha', 3) ==
'ignoredbversion') ?
GETPOST(
'ignoredbversion',
'alpha', 3) : ((empty($argv[3]) || $argv[3] !=
'ignoredbversion') ?
'' : $argv[3]);
70$langs->loadLangs(array(
"admin",
"install",
"other",
"errors"));
72if ($dolibarr_main_db_type ==
"mysqli") {
75if ($dolibarr_main_db_type ==
"pgsql") {
78if ($dolibarr_main_db_type ==
"mssql") {
84if (!is_object($conf)) {
93if (!$versionfrom && !$versionto) {
94 print
'Error: Parameter versionfrom or versionto missing.'.
"\n";
95 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
97 $sapi_type = php_sapi_name();
98 $script_file = basename(__FILE__);
100 if (substr($sapi_type, 0, 3) ==
'cli') {
101 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c\n";
107pHeader(
'',
"upgrade2",
GETPOST(
'action',
'aZ09'),
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
112if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
115 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
116 print
'<span class="inline-block">'.$langs->trans(
"DatabaseMigration").
'</span></h3>';
118 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
122 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
123 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
124 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
125 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
126 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
127 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
129 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
134 $conf->db->type = $dolibarr_main_db_type;
135 $conf->db->host = $dolibarr_main_db_host;
136 $conf->db->port = $dolibarr_main_db_port;
137 $conf->db->name = $dolibarr_main_db_name;
138 $conf->db->user = $dolibarr_main_db_user;
139 $conf->db->pass = $dolibarr_main_db_pass;
142 if (empty($dolibarr_main_db_encryption)) {
143 $dolibarr_main_db_encryption = 0;
145 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
146 if (empty($dolibarr_main_db_cryptkey)) {
147 $dolibarr_main_db_cryptkey =
'';
149 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
151 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
154 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
157 if ($db->connected) {
158 print
'<tr><td class="nowrap">';
159 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
'</span></td></tr>'.
"\n";
160 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ServerConnection").
": $dolibarr_main_db_host ".$langs->transnoentities(
"OK"));
163 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="error">'.$langs->transnoentities(
"Error").
"</span></td></tr>\n";
164 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
169 if ($db->database_selected) {
170 print
'<tr><td class="nowrap">';
171 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
"</span></td></tr>\n";
175 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="ok">'.$langs->trans(
"Error").
"</span></td></tr>\n";
176 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
183 $version = $db->getVersion();
184 $versionarray = $db->getVersionArray();
185 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
186 print
'<td class="right">'.$version.
'</td></tr>';
188 if ($db->type ==
'mysqli' && function_exists(
'mysqli_get_charset')) {
189 $tmparray = $db->db->get_charset();
190 print
'<tr><td>'.$langs->trans(
"ClientCharset").
'</td>';
191 print
'<td class="right">'.$tmparray->charset.
'</td></tr>';
193 print
'<tr><td>'.$langs->trans(
"ClientSortingCharset").
'</td>';
194 print
'<td class="right">'.$tmparray->collation.
'</td></tr>';
199 $versionmindb = explode(
'.', $db::VERSIONMIN);
201 if (count($versionmindb) && count($versionarray)
204 print
"<tr><td>".$langs->trans(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)).
'</td><td class="right"><span class="error">'.$langs->trans(
"Error").
"</span></td></tr>\n";
205 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)));
210 if (empty($ignoredbversion)) {
211 $dbversion_disallowed = array(
212 array(
'type'=>
'mysql',
'version'=>array(5, 5, 40)),
213 array(
'type'=>
'mysqli',
'version'=>array(5, 5, 40))
217 $listofforbiddenversion =
'';
218 foreach ($dbversion_disallowed as $dbversion_totest) {
219 if ($dbversion_totest[
'type'] == $db->type) {
220 $listofforbiddenversion .= ($listofforbiddenversion ?
', ' :
'').implode(
'.', $dbversion_totest[
'version']);
223 foreach ($dbversion_disallowed as $dbversion_totest) {
225 if ($dbversion_totest[
'type'] == $db->type
226 && (
versioncompare($dbversion_totest[
'version'], $versionarray) == 0 ||
versioncompare($dbversion_totest[
'version'], $versionarray) <= -4 ||
versioncompare($dbversion_totest[
'version'], $versionarray) >= 4)
229 print
'<tr><td><div class="warning">'.$langs->trans(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion).
"</div></td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>\n";
230 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion));
240 print
'<tr><td colspan="2"><span class="opacitymedium messagebepatient">'.$langs->trans(
"PleaseBePatient").
'</span></td></tr>';
245 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
252 if ($ok && preg_match(
'/mysql/', $db->type)) {
253 $versioncommande = array(4, 0, 0);
254 if (count($versioncommande) && count($versionarray)
261 MAIN_DB_PREFIX.
'adherent_options',
262 MAIN_DB_PREFIX.
'bank_class',
263 MAIN_DB_PREFIX.
'c_ecotaxe',
264 MAIN_DB_PREFIX.
'c_methode_commande_fournisseur',
265 MAIN_DB_PREFIX.
'c_input_method'
268 $listtables = $db->DDLListTables($conf->db->name,
'');
270 foreach ($listtables as $val) {
272 if (preg_match(
'/^'.MAIN_DB_PREFIX.
'/', $val)) {
274 $sql =
"SHOW CREATE TABLE ".$val;
275 $resql = $db->query($sql);
277 $values = $db->fetch_array($resql);
278 if (is_array($values)) {
280 $createsql = $values[1];
282 while (preg_match(
'/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
283 $sqldrop =
"ALTER TABLE ".$val.
" DROP FOREIGN KEY ".$reg[1];
284 $resqldrop = $db->query($sqldrop);
286 print
'<tr><td colspan="2">'.$sqldrop.
";</td></tr>\n";
288 $createsql = preg_replace(
'/CONSTRAINT `'.$reg[1].
'`/i',
'XXX', $createsql);
294 if ($db->lasterrno() !=
'DB_ERROR_NOSUCHTABLE') {
295 print
'<tr><td colspan="2"><span class="error">'.dol_escape_htmltag($sql).
' : '.
dol_escape_htmltag($db->lasterror()).
"</span></td></tr>\n";
307 $dir =
"mysql/migration/";
308 if (!empty($dirmodule)) {
314 $newversionfrom = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionfrom);
315 $newversionto = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionto);
320 $from =
'^'.preg_quote($newversionfrom,
'/');
321 $to = preg_quote($newversionto.
'.sql',
'/').
'$';
324 $filesindir = array();
325 $handle = opendir($dir);
326 if (is_resource($handle)) {
327 while (($file = readdir($handle)) !==
false) {
328 if (preg_match(
'/\.sql$/i', $file)) {
329 $filesindir[] = $file;
334 print
'<div class="error">'.$langs->trans(
"ErrorCanNotReadDir", $dir).
'</div>';
338 foreach ($filesindir as $file) {
339 if (preg_match(
'/'.$from.
'\-/i', $file)) {
341 } elseif (preg_match(
'/\-'.$to.
'/i', $file)) {
346 if (count($filelist) == 0) {
347 print
'<div class="error">'.$langs->trans(
"ErrorNoMigrationFilesFoundForParameters").
'</div>';
349 $listoffileprocessed = array();
352 foreach ($filelist as $file) {
353 if (in_array($dir.$file, $listoffileprocessed)) {
357 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
358 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
'</td><td class="right">'.$file.
'</td></tr>'.
"\n";
361 $ok =
run_sql($dir.$file, 0,
'', 1,
'',
'default', 32768, 0, 0, 2, 0, $db->database_name);
362 $listoffileprocessed[$dir.$file] = $dir.$file;
367 $modulesfile = array();
368 foreach ($conf->file->dol_document_root as $type => $dirroot) {
369 $handlemodule = @opendir($dirroot);
370 if (is_resource($handlemodule)) {
371 while (($filemodule = readdir($handlemodule)) !==
false) {
372 if (!preg_match(
'/\./', $filemodule) && is_dir($dirroot.
'/'.$filemodule.
'/sql')) {
374 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file)) {
375 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file] =
'/'.$filemodule.
'/sql/dolibarr_'.$file;
377 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql')) {
378 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql'] =
'/'.$filemodule.
'/sql/dolibarr_allversions.sql';
382 closedir($handlemodule);
386 if (count($modulesfile)) {
387 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
389 foreach ($modulesfile as $modulefilelong => $modulefileshort) {
390 if (in_array($modulefilelong, $listoffileprocessed)) {
394 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules)</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
397 $okmodule =
run_sql($modulefilelong, 0,
'', 1);
398 $listoffileprocessed[$modulefilelong] = $modulefilelong;
407 if ($db->connected) {
413if (empty($actiondone)) {
414 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
418if (!$ok && isset($argv[1])) {
425$nonext = (!$ok && !
GETPOST(
"ignoreerrors")) ? 2 : 0;
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).
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).
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.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.