41define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
42include_once
'inc.php';
43if (!file_exists($conffile)) {
44 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").';
46require_once $conffile;
47require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
58$err = error_reporting();
64$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
65$langs->setDefaultLang($setuplang);
66$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
67$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
68$dirmodule = ((
GETPOST(
"dirmodule",
'alpha', 3) &&
GETPOST(
"dirmodule",
'alpha', 3) !=
'ignoredbversion')) ?
GETPOST(
"dirmodule",
'alpha', 3) : ((empty($argv[3]) || $argv[3] ==
'ignoredbversion') ?
'' : $argv[3]);
69$ignoredbversion = (
GETPOST(
'ignoredbversion',
'alpha', 3) ==
'ignoredbversion') ?
GETPOST(
'ignoredbversion',
'alpha', 3) : ((empty($argv[3]) || $argv[3] !=
'ignoredbversion') ?
'' : $argv[3]);
71$langs->loadLangs(array(
"admin",
"install",
"other",
"errors"));
73if ($dolibarr_main_db_type ==
"mysqli") {
76if ($dolibarr_main_db_type ==
"pgsql") {
79if ($dolibarr_main_db_type ==
"mssql") {
85if (!is_object(
$conf)) {
94if (!$versionfrom && !$versionto) {
95 print
'Error: Parameter versionfrom or versionto missing.'.
"\n";
96 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
98 $sapi_type = php_sapi_name();
99 $script_file = basename(__FILE__);
101 if (substr($sapi_type, 0, 3) ==
'cli') {
102 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c\n";
108pHeader(
'',
"upgrade2",
GETPOST(
'action',
'aZ09'),
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
113if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
116 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
117 print
'<span class="inline-block">'.$langs->trans(
"DatabaseMigration").
'</span></h3>';
119 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
123 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
124 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
125 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
126 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
127 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
128 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
130 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
135 $conf->db->type = $dolibarr_main_db_type;
136 $conf->db->host = $dolibarr_main_db_host;
137 $conf->db->port = $dolibarr_main_db_port;
138 $conf->db->name = $dolibarr_main_db_name;
139 $conf->db->user = $dolibarr_main_db_user;
140 $conf->db->pass = $dolibarr_main_db_pass;
143 if (empty($dolibarr_main_db_encryption)) {
144 $dolibarr_main_db_encryption = 0;
146 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
147 if (empty($dolibarr_main_db_cryptkey)) {
148 $dolibarr_main_db_cryptkey =
'';
150 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
155 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
158 if ($db->connected) {
159 print
'<tr><td class="nowrap">';
160 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
'</span></td></tr>'.
"\n";
161 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ServerConnection").
": $dolibarr_main_db_host ".$langs->transnoentities(
"OK"));
164 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="error">'.$langs->transnoentities(
"Error").
"</span></td></tr>\n";
165 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
170 if ($db->database_selected) {
171 print
'<tr><td class="nowrap">';
172 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right"><span class="neutral">'.$langs->trans(
"OK").
"</span></td></tr>\n";
176 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right"><span class="ok">'.$langs->trans(
"Error").
"</span></td></tr>\n";
177 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
184 $version = $db->getVersion();
185 $versionarray = $db->getVersionArray();
186 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
187 print
'<td class="right">'.$version.
'</td></tr>';
189 if ($db->type ==
'mysqli' && function_exists(
'mysqli_get_charset')) {
190 $tmparray = $db->db->get_charset();
191 print
'<tr><td>'.$langs->trans(
"ClientCharset").
'</td>';
192 print
'<td class="right">'.$tmparray->charset.
'</td></tr>';
194 print
'<tr><td>'.$langs->trans(
"ClientSortingCharset").
'</td>';
195 print
'<td class="right">'.$tmparray->collation.
'</td></tr>';
200 $versionmindb = explode(
'.', $db::VERSIONMIN);
202 if (count($versionmindb) && count($versionarray)
205 print
"<tr><td>".$langs->trans(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)).
'</td><td class="right"><span class="error">'.$langs->trans(
"Error").
"</span></td></tr>\n";
206 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionTooLow", implode(
'.', $versionarray), implode(
'.', $versionmindb)));
211 if (empty($ignoredbversion)) {
212 $dbversion_disallowed = array(
213 array(
'type'=>
'mysql',
'version'=>array(5, 5, 40)),
214 array(
'type'=>
'mysqli',
'version'=>array(5, 5, 40))
218 $listofforbiddenversion =
'';
219 foreach ($dbversion_disallowed as $dbversion_totest) {
220 if ($dbversion_totest[
'type'] == $db->type) {
221 $listofforbiddenversion .= ($listofforbiddenversion ?
', ' :
'').implode(
'.', $dbversion_totest[
'version']);
224 foreach ($dbversion_disallowed as $dbversion_totest) {
226 if ($dbversion_totest[
'type'] == $db->type
227 && (
versioncompare($dbversion_totest[
'version'], $versionarray) == 0 ||
versioncompare($dbversion_totest[
'version'], $versionarray) <= -4 ||
versioncompare($dbversion_totest[
'version'], $versionarray) >= 4)
230 print
'<tr><td><div class="warning">'.$langs->trans(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion).
"</div></td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>\n";
231 dolibarr_install_syslog(
"upgrade: ".$langs->transnoentities(
"ErrorDatabaseVersionForbiddenForMigration", implode(
'.', $versionarray), $listofforbiddenversion));
241 print
'<tr><td colspan="2"><span class="opacitymedium messagebepatient">'.$langs->trans(
"PleaseBePatient").
'</span></td></tr>';
246 print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
253 if ($ok && preg_match(
'/mysql/', $db->type)) {
254 $versioncommande = array(4, 0, 0);
255 if (count($versioncommande) && count($versionarray)
262 MAIN_DB_PREFIX.
'adherent_options',
263 MAIN_DB_PREFIX.
'category_bankline',
264 MAIN_DB_PREFIX.
'c_ecotaxe',
265 MAIN_DB_PREFIX.
'c_methode_commande_fournisseur',
266 MAIN_DB_PREFIX.
'c_input_method'
269 $listtables = $db->DDLListTables(
$conf->db->name,
'');
271 foreach ($listtables as $val) {
273 if (preg_match(
'/^'.MAIN_DB_PREFIX.
'/', $val)) {
275 $sql =
"SHOW CREATE TABLE ".$val;
276 $resql = $db->query($sql);
278 $values = $db->fetch_array($resql);
279 if (is_array($values)) {
281 $createsql = $values[1];
283 while (preg_match(
'/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i', $createsql, $reg) && $i < 100) {
284 $sqldrop =
"ALTER TABLE ".$val.
" DROP FOREIGN KEY ".$reg[1];
285 $resqldrop = $db->query($sqldrop);
287 print
'<tr><td colspan="2">'.$sqldrop.
";</td></tr>\n";
289 $createsql = preg_replace(
'/CONSTRAINT `'.$reg[1].
'`/i',
'XXX', $createsql);
295 if ($db->lasterrno() !=
'DB_ERROR_NOSUCHTABLE') {
296 print
'<tr><td colspan="2"><span class="error">'.dol_escape_htmltag($sql).
' : '.
dol_escape_htmltag($db->lasterror()).
"</span></td></tr>\n";
308 $dir =
"mysql/migration/";
309 if (!empty($dirmodule)) {
315 $newversionfrom = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionfrom);
316 $newversionto = preg_replace(
'/(\.[0-9]+)$/i',
'.0', $versionto);
321 $from =
'^'.preg_quote($newversionfrom,
'/');
322 $to = preg_quote($newversionto.
'.sql',
'/').
'$';
325 $filesindir = array();
326 $handle = opendir($dir);
327 if (is_resource($handle)) {
328 while (($file = readdir($handle)) !==
false) {
329 if (preg_match(
'/\.sql$/i', $file)) {
330 $filesindir[] = $file;
335 print
'<div class="error">'.$langs->trans(
"ErrorCanNotReadDir", $dir).
'</div>';
339 foreach ($filesindir as $file) {
340 if (preg_match(
'/'.$from.
'\-/i', $file)) {
342 } elseif (preg_match(
'/\-'.$to.
'/i', $file)) {
347 if (count($filelist) == 0) {
348 print
'<div class="error">'.$langs->trans(
"ErrorNoMigrationFilesFoundForParameters").
'</div>';
350 $listoffileprocessed = array();
353 foreach ($filelist as $file) {
354 if (in_array($dir.$file, $listoffileprocessed)) {
358 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
359 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
'</td><td class="right">'.$file.
'</td></tr>'.
"\n";
362 $ok =
run_sql($dir.$file, 0, 0, 1,
'',
'default', 32768, 0, 0, 2, 0, $db->database_name);
363 $listoffileprocessed[$dir.$file] = $dir.$file;
368 $modulesfile = array();
369 foreach (
$conf->file->dol_document_root as $type => $dirroot) {
370 $handlemodule = @opendir($dirroot);
371 if (is_resource($handlemodule)) {
372 while (($filemodule = readdir($handlemodule)) !==
false) {
373 if (!preg_match(
'/\./', $filemodule) && is_dir($dirroot.
'/'.$filemodule.
'/sql')) {
375 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file)) {
376 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_'.$file] =
'/'.$filemodule.
'/sql/dolibarr_'.$file;
378 if (is_file($dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql')) {
379 $modulesfile[$dirroot.
'/'.$filemodule.
'/sql/dolibarr_allversions.sql'] =
'/'.$filemodule.
'/sql/dolibarr_allversions.sql';
383 closedir($handlemodule);
387 if (count($modulesfile)) {
388 print
'<tr><td colspan="2"><hr style="border-color: #ccc; border-top-style: none;"></td></tr>';
390 foreach ($modulesfile as $modulefilelong => $modulefileshort) {
391 if (in_array($modulefilelong, $listoffileprocessed)) {
395 print
'<tr><td class="nowrap">'.$langs->trans(
"ChoosedMigrateScript").
' (external modules)</td><td class="right">'.$modulefileshort.
'</td></tr>'.
"\n";
398 $okmodule =
run_sql($modulefilelong, 0, 0, 1);
399 $listoffileprocessed[$modulefilelong] = $modulefilelong;
408 if ($db->connected) {
414if (empty($actiondone)) {
415 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
419if (!$ok && isset($argv[1])) {
426$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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.