39define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
40include_once
'inc.php';
41if (!file_exists($conffile)) {
42 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").';
44require_once $conffile;
45require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
56$err = error_reporting();
62$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
63$langs->setDefaultLang($setuplang);
64$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
65$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
66$dirmodule = ((
GETPOST(
"dirmodule",
'alpha', 3) &&
GETPOST(
"dirmodule",
'alpha', 3) !=
'ignoredbversion')) ?
GETPOST(
"dirmodule",
'alpha', 3) : ((empty($argv[3]) || $argv[3] ==
'ignoredbversion') ?
'' : $argv[3]);
67$ignoredbversion = (
GETPOST(
'ignoredbversion',
'alpha', 3) ==
'ignoredbversion') ?
GETPOST(
'ignoredbversion',
'alpha', 3) : ((empty($argv[3]) || $argv[3] !=
'ignoredbversion') ?
'' : $argv[3]);
69$langs->loadLangs(array(
"admin",
"install",
"other",
"errors"));
71if ($dolibarr_main_db_type ==
"mysqli") {
74if ($dolibarr_main_db_type ==
"pgsql") {
77if ($dolibarr_main_db_type ==
"mssql") {
83if (!is_object($conf)) {
92if (!$versionfrom && !$versionto) {
93 print
'Error: Parameter versionfrom or versionto missing.'.
"\n";
94 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
96 $sapi_type = php_sapi_name();
97 $script_file = basename(__FILE__);
99 if (substr($sapi_type, 0, 3) ==
'cli') {
100 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c\n";
106pHeader(
'',
"upgrade2",
GETPOST(
'action',
'aZ09'),
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
111if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
114 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
115 print
'<span class="inline-block">'.$langs->trans(
"DatabaseMigration").
'</span></h3>';
117 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
121 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
122 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
123 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
124 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
125 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
126 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
128 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
133 $conf->db->type = $dolibarr_main_db_type;
134 $conf->db->host = $dolibarr_main_db_host;
135 $conf->db->port = $dolibarr_main_db_port;
136 $conf->db->name = $dolibarr_main_db_name;
137 $conf->db->user = $dolibarr_main_db_user;
138 $conf->db->pass = $dolibarr_main_db_pass;
141 if (empty($dolibarr_main_db_encryption)) {
142 $dolibarr_main_db_encryption = 0;
144 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
145 if (empty($dolibarr_main_db_cryptkey)) {
146 $dolibarr_main_db_cryptkey =
'';
148 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
150 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
153 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
156 if ($db->connected) {
157 print
'<tr><td class="nowrap">';
158 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
'</span></td></tr>'.
"\n";
159 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ServerConnection").
": $dolibarr_main_db_host ".$langs->transnoentities(
"OK"));
162 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="error">'.$langs->transnoentities(
"Error").
"</span></td></tr>\n";
163 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
168 if ($db->database_selected) {
169 print
'<tr><td class="nowrap">';
170 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
"</span></td></tr>\n";
174 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="ok">'.$langs->trans(
"Error").
"</span></td></tr>\n";
175 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
182 $version = $db->getVersion();
183 $versionarray = $db->getVersionArray();
184 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
185 print
'<td class="right">'.$version.
'</td></tr>';
187 if ($db->type ==
'mysqli' && function_exists(
'mysqli_get_charset')) {
188 $tmparray = $db->db->get_charset();
189 print
'<tr><td>'.$langs->trans(
"ClientCharset").
'</td>';
190 print
'<td class="right">'.$tmparray->charset.
'</td></tr>';
192 print
'<tr><td>'.$langs->trans(
"ClientSortingCharset").
'</td>';
193 print
'<td class="right">'.$tmparray->collation.
'</td></tr>';
198 $versionmindb = explode(
'.', $db::VERSIONMIN);
200 if (count($versionmindb) && count($versionarray)
203 print
"<tr><td>".$langs->trans(
"ErrorDatabaseVersionTooLow", join(
'.', $versionarray), join(
'.', $versionmindb)).
'</td><td class="right"><span class="error">'.$langs->trans(
"Error").
"</span></td></tr>\n";
204 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionTooLow", join(
'.', $versionarray), join(
'.', $versionmindb)));
209 if (empty($ignoredbversion)) {
210 $dbversion_disallowed = array(
211 array(
'type'=>
'mysql',
'version'=>array(5, 5, 40)),
212 array(
'type'=>
'mysqli',
'version'=>array(5, 5, 40))
216 $listofforbiddenversion =
'';
217 foreach ($dbversion_disallowed as $dbversion_totest) {
218 if ($dbversion_totest[
'type'] == $db->type) {
219 $listofforbiddenversion .= ($listofforbiddenversion ?
', ' :
'').join(
'.', $dbversion_totest[
'version']);
222 foreach ($dbversion_disallowed as $dbversion_totest) {
224 if ($dbversion_totest[
'type'] == $db->type
225 && (
versioncompare($dbversion_totest[
'version'], $versionarray) == 0 ||
versioncompare($dbversion_totest[
'version'], $versionarray) <= -4 ||
versioncompare($dbversion_totest[
'version'], $versionarray) >= 4)
228 print
'<tr><td><div class="warning">'.$langs->trans(
"ErrorDatabaseVersionForbiddenForMigration", join(
'.', $versionarray), $listofforbiddenversion).
"</div></td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>\n";
229 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionForbiddenForMigration", join(
'.', $versionarray), $listofforbiddenversion));
239 print
'<tr><td colspan="2"><span class="opacitymedium messagebepatient">'.$langs->trans(
"PleaseBePatient").
'</span></td></tr>';
244 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
251 if ($ok && preg_match(
'/mysql/', $db->type)) {
252 $versioncommande = array(4, 0, 0);
253 if (count($versioncommande) && count($versionarray)
260 MAIN_DB_PREFIX.
'adherent_options',
261 MAIN_DB_PREFIX.
'bank_class',
262 MAIN_DB_PREFIX.
'c_ecotaxe',
263 MAIN_DB_PREFIX.
'c_methode_commande_fournisseur',
264 MAIN_DB_PREFIX.
'c_input_method'
267 $listtables = $db->DDLListTables($conf->db->name,
'');
269 foreach ($listtables as $val) {
271 if (preg_match(
'/^'.MAIN_DB_PREFIX.
'/', $val)) {
273 $sql =
"SHOW CREATE TABLE ".$val;
274 $resql = $db->query($sql);
276 $values = $db->fetch_array($resql);
278 $createsql = $values[1];
280 while (preg_match(
'/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
281 $sqldrop =
"ALTER TABLE ".$val.
" DROP FOREIGN KEY ".$reg[1];
282 $resqldrop = $db->query($sqldrop);
284 print
'<tr><td colspan="2">'.$sqldrop.
";</td></tr>\n";
286 $createsql = preg_replace(
'/CONSTRAINT `'.$reg[1].
'`/i',
'XXX', $createsql);
291 if ($db->lasterrno() !=
'DB_ERROR_NOSUCHTABLE') {
292 print
'<tr><td colspan="2"><span class="error">'.dol_escape_htmltag($sql).
' : '.
dol_escape_htmltag($db->lasterror()).
"</span></td></tr>\n";
304 $dir =
"mysql/migration/";
305 if (!empty($dirmodule)) {
311 $newversionfrom = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionfrom);
312 $newversionto = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionto);
317 $from =
'^'.preg_quote($newversionfrom,
'/');
318 $to = preg_quote($newversionto.
'.sql',
'/').
'$';
321 $filesindir = array();
322 $handle = opendir($dir);
323 if (is_resource($handle)) {
324 while (($file = readdir($handle)) !==
false) {
325 if (preg_match(
'/\.sql$/i', $file)) {
326 $filesindir[] = $file;
331 print
'<div class="error">'.$langs->trans(
"ErrorCanNotReadDir", $dir).
'</div>';
335 foreach ($filesindir as $file) {
336 if (preg_match(
'/'.$from.
'\-/i', $file)) {
338 } elseif (preg_match(
'/\-'.$to.
'/i', $file)) {
343 if (count($filelist) == 0) {
344 print
'<div class="error">'.$langs->trans(
"ErrorNoMigrationFilesFoundForParameters").
'</div>';
346 $listoffileprocessed = array();
349 foreach ($filelist as $file) {
350 if (in_array($dir.$file, $listoffileprocessed)) {
354 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
355 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
'</td><td class="right">'.$file.
'</td></tr>'.
"\n";
358 $ok =
run_sql($dir.$file, 0,
'', 1,
'',
'default', 32768, 0, 0, 2, 0, $db->database_name);
359 $listoffileprocessed[$dir.$file] = $dir.$file;
364 $modulesfile = array();
365 foreach ($conf->file->dol_document_root as $type => $dirroot) {
366 $handlemodule = @opendir($dirroot);
367 if (is_resource($handlemodule)) {
368 while (($filemodule = readdir($handlemodule)) !==
false) {
369 if (!preg_match(
'/\./', $filemodule) && is_dir($dirroot.
'/'.$filemodule.
'/sql')) {
371 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file)) {
372 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file] =
'/'.$filemodule.
'/sql/dolibarr_'.$file;
374 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql')) {
375 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql'] =
'/'.$filemodule.
'/sql/dolibarr_allversions.sql';
379 closedir($handlemodule);
383 if (count($modulesfile)) {
384 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
386 foreach ($modulesfile as $modulefilelong => $modulefileshort) {
387 if (in_array($modulefilelong, $listoffileprocessed)) {
391 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules)</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
394 $okmodule =
run_sql($modulefilelong, 0,
'', 1);
395 $listoffileprocessed[$modulefilelong] = $modulefilelong;
404 if ($db->connected) {
410if (empty($actiondone)) {
411 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
415if (!$ok && isset($argv[1])) {
421$nonext = (!$ok && empty($_GET[
"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.