diff --git a/ChangeLog b/ChangeLog
index 89978452254..d5e30f09ddd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -45,6 +45,8 @@ For developers:
- New: dol_syslog method accept a suffix to use different log files for log.
- New: Type of fields are received by export format handlers
- New: when adding an action, we can define a free code to tag it for a specific need.
+- New: Enhance Dolibarr migration process to include migration script of external
+ modules.
WARNING: If you used external modules, some of them may need to be upgraded due to:
- fields of classes were renamed to be normalized (nom, prenom, cp, ville, adresse were
diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php
index cf817ae494d..85218aaee58 100644
--- a/htdocs/core/lib/admin.lib.php
+++ b/htdocs/core/lib/admin.lib.php
@@ -250,7 +250,7 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker
$newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql);
// Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes)
- if (! $silent) print '
| '.$langs->trans("Request").' '.($i+1)." sql='".$newsql."' |
\n";
+ if (! $silent) print '| '.$langs->trans("Request").' '.($i+1)." sql='".dol_htmlentities($newsql,ENT_NOQUOTES)."' |
\n";
dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG);
// Replace for encrypt data
@@ -1153,10 +1153,10 @@ function showModulesExludedForExternal($modules)
$moduleconst=$module->const_name;
$modulename=strtolower($module->name);
//print 'modulename='.$modulename;
-
+
//if (empty($conf->global->$moduleconst)) continue;
if (! in_array($modulename,$listofmodules)) continue;
-
+
if ($i > 0) $text.=', ';
else $text.=' ';
$i++;
diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index 2df2c8db4b9..e04a3a94261 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -326,7 +326,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
$dir = "mysql/migration/"; // We use mysql migration scripts whatever is database driver
if (! empty($versionmodule)) $dir=dol_buildpath('/'.$versionmodule.'/sql/',0);
- // For minor version
+ // Clean last part to exclude minor version x.y.z -> x.y
$newversionfrom=preg_replace('/(\.[0-9]+)$/i','.0',$versionfrom);
$newversionto=preg_replace('/(\.[0-9]+)$/i','.0',$versionto);
@@ -368,13 +368,43 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
// Loop on each migrate files
foreach($filelist as $file)
{
- print '| ';
- print $langs->trans("ChoosedMigrateScript").' | '.$file.' |
'."\n";
-
- $name = substr($file, 0, dol_strlen($file) - 4);
+ print '
|
';
+ print '| '.$langs->trans("ChoosedMigrateScript").' | '.$file.' |
'."\n";
// Run sql script
$ok=run_sql($dir.$file, 0, '', 1);
+
+ // Scan if there is migration scripts for modules htdocs/module/sql or htdocs/custom/module/sql
+ $modulesfile = array();
+ foreach ($conf->file->dol_document_root as $type => $dirroot)
+ {
+ $handlemodule=@opendir($dirroot);
+ if (is_resource($handlemodule))
+ {
+ while (($filemodule = readdir($handlemodule))!==false)
+ {
+ if (is_dir($dirroot.'/'.$filemodule.'/sql'))
+ {
+ //print "Scan for ".$dirroot . '/' . $filemodule . '/sql/'.$file;
+ if (is_file($dirroot . '/' . $filemodule . '/sql/'.$file))
+ {
+ $modulesfile[$dirroot . '/' . $filemodule . '/sql/'.$file] = '/' . $filemodule . '/sql/'.$file;
+ }
+ }
+ }
+ closedir($handlemodule);
+ }
+ }
+
+ foreach ($modulesfile as $modulefilelong => $modulefileshort)
+ {
+ print '
|
';
+ print '| '.$langs->trans("ChoosedMigrateScript").' (external modules) | '.$modulefileshort.' |
'."\n";
+
+ // Run sql script
+ $okmodule=run_sql($modulefilelong, 0, '', 1); // Note: Result of migration of external module should not decide if we continue migration of Dolibarr or not.
+ }
+
}
}