NEW Can enable a module, even external module, from command line
This commit is contained in:
parent
291f149a9b
commit
d3d1b6d513
@ -256,10 +256,10 @@ class ExtraFields
|
|||||||
if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255';
|
if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255';
|
||||||
}
|
}
|
||||||
$field_desc = array(
|
$field_desc = array(
|
||||||
'type'=>$typedb,
|
'type'=>$typedb,
|
||||||
'value'=>$lengthdb,
|
'value'=>$lengthdb,
|
||||||
'null'=>($required?'NOT NULL':'NULL'),
|
'null'=>($required?'NOT NULL':'NULL'),
|
||||||
'default' => $default_value
|
'default' => $default_value
|
||||||
);
|
);
|
||||||
|
|
||||||
$result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
|
$result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
|
||||||
@ -376,8 +376,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.= " ".($help?"'".$this->db->escape($help)."'":"null");
|
$sql.= " ".($help?"'".$this->db->escape($help)."'":"null");
|
||||||
|
|||||||
@ -765,28 +765,36 @@ class DoliDBMysqli extends DoliDB
|
|||||||
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
|
||||||
$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']))
|
}
|
||||||
$sql.= " ".$field_desc['attribute'];
|
if (isset($field_desc['attribute']) && preg_match("/^[^\s]/i",$field_desc['attribute']))
|
||||||
if(preg_match("/^[^\s]/i",$field_desc['null']))
|
{
|
||||||
$sql.= " ".$field_desc['null'];
|
$sql.= " ".$field_desc['attribute'];
|
||||||
if(preg_match("/^[^\s]/i",$field_desc['default']))
|
}
|
||||||
|
if (isset($field_desc['null']) && preg_match("/^[^\s]/i",$field_desc['null']))
|
||||||
|
{
|
||||||
|
$sql.= " ".$field_desc['null'];
|
||||||
|
}
|
||||||
|
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);
|
||||||
if($this->query($sql)) {
|
if ($this->query($sql)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -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__);
|
||||||
|
|||||||
@ -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 ".$versionfrom." ".$versionto);
|
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;
|
||||||
}
|
}
|
||||||
@ -438,6 +444,13 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
|
|||||||
migrate_rename_directories($db,$langs,$conf,'/contracts','/contract');
|
migrate_rename_directories($db,$langs,$conf,'/contracts','/contract');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scripts for 9.0
|
||||||
|
$afterversionarray=explode('.','8.0.9');
|
||||||
|
$beforeversionarray=explode('.','9.0.9');
|
||||||
|
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
|
||||||
|
{
|
||||||
|
//migrate_rename_directories($db,$langs,$conf,'/contracts','/contract');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code executed only if migration is LAST ONE. Must always be done.
|
// Code executed only if migration is LAST ONE. Must always be done.
|
||||||
@ -541,12 +554,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,11 +4549,11 @@ function migrate_delete_old_dir($db,$langs,$conf)
|
|||||||
* @param int $force 1=Reload module even if not already loaded
|
* @param int $force 1=Reload module even if not already loaded
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0)
|
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'
|
||||||
{
|
{
|
||||||
@ -4723,8 +4736,15 @@ 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]))
|
||||||
{
|
{
|
||||||
$moduletoreloadshort = ucfirst(strtolower($reg[1]));
|
if (strtoupper($moduletoreload) == $moduletoreload) // If key is un uppercase
|
||||||
dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort);
|
{
|
||||||
|
$moduletoreloadshort = ucfirst(strtolower($reg[1]));
|
||||||
|
}
|
||||||
|
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;
|
||||||
@ -4732,10 +4752,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
|
||||||
|
{
|
||||||
|
dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Error, can't find module name";
|
dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_WARNING);
|
||||||
|
print "Error, can't find module with name ".$moduletoreload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user