Merge branch '7.0' of git@github.com:Dolibarr/dolibarr.git into 8.0

Conflicts:
	htdocs/install/upgrade2.php
This commit is contained in:
Laurent Destailleur 2018-07-16 15:44:44 +02:00
commit f747cefda3
4 changed files with 76 additions and 35 deletions

View File

@ -375,8 +375,8 @@ class ExtraFields
$sql.= " '".$this->db->escape($list)."',"; $sql.= " '".$this->db->escape($list)."',";
$sql.= " ".($default?"'".$this->db->escape($default)."'":"null").","; $sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").","; $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
$sql .= " " . $user->id . ","; $sql .= " " . (is_object($user) ? $user->id : 0). ",";
$sql .= " " . $user->id . ","; $sql .= " " . (is_object($user) ? $user->id : 0). ",";
$sql .= "'" . $this->db->idate(dol_now()) . "',"; $sql .= "'" . $this->db->idate(dol_now()) . "',";
$sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1"); $sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1");
$sql.=')'; $sql.=')';

View File

@ -766,23 +766,31 @@ class DoliDBMysqli extends DoliDB
$sql= "ALTER TABLE ".$table." ADD ".$field_name." "; $sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
$sql.= $field_desc['type']; $sql.= $field_desc['type'];
if (preg_match("/^[^\s]/i",$field_desc['value'])) if (preg_match("/^[^\s]/i",$field_desc['value']))
{
if (! in_array($field_desc['type'],array('date','datetime'))) if (! in_array($field_desc['type'],array('date','datetime')))
{ {
$sql.= "(".$field_desc['value'].")"; $sql.= "(".$field_desc['value'].")";
} }
if(preg_match("/^[^\s]/i",$field_desc['attribute'])) }
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i",$field_desc['attribute']))
{
$sql.= " ".$field_desc['attribute']; $sql.= " ".$field_desc['attribute'];
if(preg_match("/^[^\s]/i",$field_desc['null'])) }
if (isset($field_desc['null']) && preg_match("/^[^\s]/i",$field_desc['null']))
{
$sql.= " ".$field_desc['null']; $sql.= " ".$field_desc['null'];
if(preg_match("/^[^\s]/i",$field_desc['default'])) }
if (isset($field_desc['default']) && preg_match("/^[^\s]/i",$field_desc['default']))
{ {
if(preg_match("/null/i",$field_desc['default'])) if(preg_match("/null/i",$field_desc['default']))
$sql.= " default ".$field_desc['default']; $sql.= " default ".$field_desc['default'];
else else
$sql.= " default '".$field_desc['default']."'"; $sql.= " default '".$field_desc['default']."'";
} }
if(preg_match("/^[^\s]/i",$field_desc['extra'])) if (isset($field_desc['extra']) && preg_match("/^[^\s]/i",$field_desc['extra']))
{
$sql.= " ".$field_desc['extra']; $sql.= " ".$field_desc['extra'];
}
$sql.= " ".$field_position; $sql.= " ".$field_position;
dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
@ -21,10 +21,13 @@
* *
* cd htdocs/install * cd htdocs/install
* php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion] * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion]
* php upgrade2.php 3.4.0 3.5.0 * php upgrade2.php 3.4.0 3.5.0 [MODULE_NAME1_TO_ENABLE,MODULE_NAME2_TO_ENABLE]
* *
* Option 'dirmodule' allows to provide a path for an external module, so we migrate from command line a script from a module. * And for final step:
* Option 'ignoredbversion' allows to run migration even if database is a bugged database version. * php step5.php 3.4.0 3.5.0
*
* Option 'dirmodule' allows to provide a path for an external module, so we migrate from command line using a script from a module.
* Option 'ignoredbversion' allows to run migration even if database version does not match start version of migration
* Return code is 0 if OK, >0 if error * Return code is 0 if OK, >0 if error
*/ */
@ -84,7 +87,7 @@ if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initial
if (! $versionfrom && ! $versionto) if (! $versionfrom && ! $versionto)
{ {
print 'Error: Parameter versionfrom or versionto missing.'."\n"; print 'Error: Parameter versionfrom or versionto missing.'."\n";
print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install) instead of page install/upgrade.php'."\n"; print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
// Test if batch mode // Test if batch mode
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> /* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -18,13 +18,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* Upgrade scripts can be ran from command line with syntax: * Upgrade2 scripts can be ran from command line with syntax:
* *
* cd htdocs/install * cd htdocs/install
* php upgrade.php 3.4.0 3.5.0 * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion]
* php upgrade2.php 3.4.0 3.5.0 [MODULE_NAME1_TO_ENABLE,MODULE_NAME2_TO_ENABLE] * php upgrade2.php 3.4.0 3.5.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
*
* And for final step:
* php step5.php 3.4.0 3.5.0
* *
* Return code is 0 if OK, >0 if error * Return code is 0 if OK, >0 if error
*
* Note: To just enable a module from command line, use this syntax:
* php upgrade2.php 0.0.0 0.0.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
*/ */
/** /**
@ -77,7 +83,7 @@ if ($dolibarr_main_db_type == 'pgsql') $choix=2;
if ($dolibarr_main_db_type == 'mssql') $choix=3; if ($dolibarr_main_db_type == 'mssql') $choix=3;
dolibarr_install_syslog("--- upgrade2: entering upgrade2.php page"); dolibarr_install_syslog("--- upgrade2: entering upgrade2.php page ".$versionfrom." ".$versionto." ".$enablemodules);
if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR); if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
@ -89,14 +95,14 @@ if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initial
if ((! $versionfrom || preg_match('/version/', $versionfrom)) && (! $versionto || preg_match('/version/', $versionto))) if ((! $versionfrom || preg_match('/version/', $versionfrom)) && (! $versionto || preg_match('/version/', $versionto)))
{ {
print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\n"; print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\n";
print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install) instead of page install/upgrade.php'."\n"; print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
// Test if batch mode // Test if batch mode
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file = basename(__FILE__); $script_file = basename(__FILE__);
$path=dirname(__FILE__).'/'; $path=dirname(__FILE__).'/';
if (substr($sapi_type, 0, 3) == 'cli') if (substr($sapi_type, 0, 3) == 'cli')
{ {
print 'Syntax from command line: '.$script_file." x.y.z a.b.c\n"; print 'Syntax from command line: '.$script_file." x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
} }
exit; exit;
} }
@ -537,12 +543,12 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
dolCopyDir($srcroot, $destroot, 0, 0); dolCopyDir($srcroot, $destroot, 0, 0);
// Actions for all versions (no database change, delete files and directories) // Actions for all versions (no database change but delete some files and directories)
migrate_delete_old_files($db, $langs, $conf); migrate_delete_old_files($db, $langs, $conf);
migrate_delete_old_dir($db, $langs, $conf); migrate_delete_old_dir($db, $langs, $conf);
// Actions for all versions (no database change, create directories) // Actions for all versions (no database change but create some directories)
dol_mkdir(DOL_DATA_ROOT.'/bank'); dol_mkdir(DOL_DATA_ROOT.'/bank');
// Actions for all versions (no database change, rename directories) // Actions for all versions (no database change but rename some directories)
migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits'); migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits');
print '<div><br>'.$langs->trans("MigrationFinished").'</div>'; print '<div><br>'.$langs->trans("MigrationFinished").'</div>';
@ -4536,7 +4542,7 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
{ {
if (count($listofmodule) == 0) return; if (count($listofmodule) == 0) return;
dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force); dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".join(',', array_keys($listofmodule)));
foreach($listofmodule as $moduletoreload => $reloadmode) // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate' foreach($listofmodule as $moduletoreload => $reloadmode) // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
{ {
@ -4718,9 +4724,16 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
{ {
$tmp = preg_match('/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg); $tmp = preg_match('/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
if (! empty($reg[1])) if (! empty($reg[1]))
{
if (strtoupper($moduletoreload) == $moduletoreload) // If key is un uppercase
{ {
$moduletoreloadshort = ucfirst(strtolower($reg[1])); $moduletoreloadshort = ucfirst(strtolower($reg[1]));
dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort); }
else // If key is a mix of up and low case
{
$moduletoreloadshort = $reg[1];
}
dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort." with mode ".$reloadmode);
$res=@include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php'; $res=@include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php';
if ($res) { if ($res) {
$classname = 'mod'.$moduletoreloadshort; $classname = 'mod'.$moduletoreloadshort;
@ -4728,10 +4741,27 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
//$mod->remove('noboxes'); //$mod->remove('noboxes');
$mod->init($reloadmode); $mod->init($reloadmode);
} }
else
{
dolibarr_install_syslog('Failed to include '.DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php');
$res=@dol_include_once(strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
if ($res) {
$classname = 'mod'.$moduletoreloadshort;
$mod=new $classname($db);
//$mod->remove('noboxes');
$mod->init($reloadmode);
} }
else else
{ {
print "Error, can't find module name"; dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
}
}
}
else
{
dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_WARNING);
print "Error, can't find module with name ".$moduletoreload;
} }
} }