Fix: Compatibility of new module setup with old setup
This commit is contained in:
parent
1b236c5c56
commit
cc6a2c8d84
@ -72,13 +72,15 @@ class modMyModule extends DolibarrModules
|
|||||||
// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
|
// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
|
||||||
// for specific path of parts (eg: /mymodule/core/modules/barcode)
|
// for specific path of parts (eg: /mymodule/core/modules/barcode)
|
||||||
// for specific css file (eg: /mymodule/css/mymodule.css.php)
|
// for specific css file (eg: /mymodule/css/mymodule.css.php)
|
||||||
//$this->module_parts = array( 'triggers' => 1,
|
//$this->module_parts = array(
|
||||||
// 'login' => 0,
|
// 'triggers' => 0, // Set this to 1 if module has its own trigger directory
|
||||||
// 'substitutions' => 0,
|
// 'login' => 0, // Set this to 1 if module has its own login method directory
|
||||||
// 'menus' => 0,
|
// 'substitutions' => 0, // Set this to 1 if module has its own substitution function file
|
||||||
// 'css' => '/mymodule/css/mymodule.css.php',
|
// 'menus' => 0, // Set this to 1 if module has its own menus handler directory
|
||||||
// 'barcode' => '/mymodule/path/to/your/parts',
|
// 'barcode' => 0, // Set this to 1 if module has its own barcode directory
|
||||||
// 'hooks' => array('hookcontext1','hookcontext2'));
|
// 'css' => '/mymodule/css/mymodule.css.php', // Set this to relative path of css if module has its own css file
|
||||||
|
// 'hooks' => array('hookcontext1','hookcontext2') // Set here all hooks context managed by module
|
||||||
|
// );
|
||||||
$this->module_parts = array();
|
$this->module_parts = array();
|
||||||
|
|
||||||
// Data directories to create when module is enabled.
|
// Data directories to create when module is enabled.
|
||||||
|
|||||||
@ -33,6 +33,7 @@ $langs->load("admin");
|
|||||||
|
|
||||||
$mode=isset($_GET["mode"])?GETPOST("mode"):(isset($_SESSION['mode'])?$_SESSION['mode']:0);
|
$mode=isset($_GET["mode"])?GETPOST("mode"):(isset($_SESSION['mode'])?$_SESSION['mode']:0);
|
||||||
$mesg=GETPOST("mesg");
|
$mesg=GETPOST("mesg");
|
||||||
|
$action=GETPOST('action');
|
||||||
|
|
||||||
if (!$user->admin) accessforbidden();
|
if (!$user->admin) accessforbidden();
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ if (!$user->admin) accessforbidden();
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == 'set' && $user->admin)
|
if ($action == 'set' && $user->admin)
|
||||||
{
|
{
|
||||||
$result=activateModule($_GET["value"]);
|
$result=activateModule($_GET["value"]);
|
||||||
$mesg='';
|
$mesg='';
|
||||||
@ -50,7 +51,7 @@ if (isset($_GET["action"]) && $_GET["action"] == 'set' && $user->admin)
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == 'reset' && $user->admin)
|
if ($action == 'reset' && $user->admin)
|
||||||
{
|
{
|
||||||
$result=unActivateModule($_GET["value"]);
|
$result=unActivateModule($_GET["value"]);
|
||||||
$mesg='';
|
$mesg='';
|
||||||
|
|||||||
@ -59,10 +59,10 @@ class HookManager
|
|||||||
* class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
|
* class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
|
||||||
* Then when a hook is executeHook('aMethod'...) is called, the method aMethod found into class will be executed.
|
* Then when a hook is executeHook('aMethod'...) is called, the method aMethod found into class will be executed.
|
||||||
*
|
*
|
||||||
* @param array $arraytype Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
|
* @param array $arraycontext Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
|
||||||
* @return int Always 1
|
* @return int Always 1
|
||||||
*/
|
*/
|
||||||
function callHooks($arraytype)
|
function callHooks($arraycontext)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
@ -70,24 +70,27 @@ class HookManager
|
|||||||
if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return;
|
if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return;
|
||||||
|
|
||||||
// For backward compatibility
|
// For backward compatibility
|
||||||
if (! is_array($arraytype)) $arraytype=array($arraytype);
|
if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
|
||||||
|
|
||||||
$this->contextarray=array_merge($arraytype,$this->contextarray);
|
$this->contextarray=array_merge($arraycontext,$this->contextarray); // All contexts are concatenated
|
||||||
|
|
||||||
$i=0;
|
$i=0;
|
||||||
foreach($conf->hooks_modules as $module => $hooks)
|
foreach($conf->hooks_modules as $module => $hooks)
|
||||||
{
|
{
|
||||||
if ($conf->$module->enabled)
|
if ($conf->$module->enabled)
|
||||||
{
|
{
|
||||||
foreach($arraytype as $type)
|
foreach($arraycontext as $context)
|
||||||
{
|
{
|
||||||
if (in_array($type,$hooks)) // We instantiate action class only if hook is required
|
if (is_array($hooks)) $arrayhooks=$hooks; // New system
|
||||||
|
else $arrayhooks=explode(':',$hooks); // Old system (for backward compatibility)
|
||||||
|
|
||||||
|
if (in_array($context,$arrayhooks)) // We instantiate action class only if hook is required
|
||||||
{
|
{
|
||||||
$path = '/'.$module.'/class/';
|
$path = '/'.$module.'/class/';
|
||||||
$actionfile = 'actions_'.$module.'.class.php';
|
$actionfile = 'actions_'.$module.'.class.php';
|
||||||
$pathroot = '';
|
$pathroot = '';
|
||||||
|
|
||||||
$this->hooks[$i]['type']=$type;
|
$this->hooks[$i]['type']=$context;
|
||||||
|
|
||||||
// Include actions class overwriting hooks
|
// Include actions class overwriting hooks
|
||||||
$resaction=dol_include_once($path.$actionfile);
|
$resaction=dol_include_once($path.$actionfile);
|
||||||
|
|||||||
@ -73,7 +73,7 @@ abstract class DolibarrModules
|
|||||||
|
|
||||||
// Insert new pages for tabs into llx_const
|
// Insert new pages for tabs into llx_const
|
||||||
if (! $err) $err+=$this->insert_tabs();
|
if (! $err) $err+=$this->insert_tabs();
|
||||||
|
|
||||||
// Insert activation of module's parts
|
// Insert activation of module's parts
|
||||||
if (! $err) $err+=$this->insert_module_parts();
|
if (! $err) $err+=$this->insert_module_parts();
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ abstract class DolibarrModules
|
|||||||
|
|
||||||
// Remove activation of module's new tabs (MAIN_MODULE_MYMODULE_TABS_XXX in llx_const)
|
// Remove activation of module's new tabs (MAIN_MODULE_MYMODULE_TABS_XXX in llx_const)
|
||||||
if (! $err) $err+=$this->delete_tabs();
|
if (! $err) $err+=$this->delete_tabs();
|
||||||
|
|
||||||
// Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const)
|
// Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const)
|
||||||
if (! $err) $err+=$this->delete_module_parts();
|
if (! $err) $err+=$this->delete_module_parts();
|
||||||
|
|
||||||
@ -1253,22 +1253,22 @@ abstract class DolibarrModules
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert activation of generic parts from modules in llx_const
|
* Insert activation of generic parts from modules in llx_const
|
||||||
*
|
*
|
||||||
* @return int Nb of errors (0 if OK)
|
* @return int Nb of errors (0 if OK)
|
||||||
*/
|
*/
|
||||||
function insert_module_parts()
|
function insert_module_parts()
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$err=0;
|
$err=0;
|
||||||
$entity=$conf->entity;
|
$entity=$conf->entity;
|
||||||
|
|
||||||
if (is_array($this->module_parts) && ! empty($this->module_parts))
|
if (is_array($this->module_parts) && ! empty($this->module_parts))
|
||||||
{
|
{
|
||||||
foreach($this->module_parts as $key => $value)
|
foreach($this->module_parts as $key => $value)
|
||||||
{
|
{
|
||||||
$newvalue = $value;
|
$newvalue = $value;
|
||||||
|
|
||||||
// Serialize array parameters
|
// Serialize array parameters
|
||||||
if (is_array($value))
|
if (is_array($value))
|
||||||
{
|
{
|
||||||
@ -1283,7 +1283,7 @@ abstract class DolibarrModules
|
|||||||
$newvalue = serialize($value);
|
$newvalue = serialize($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
|
||||||
$sql.= "name";
|
$sql.= "name";
|
||||||
$sql.= ", type";
|
$sql.= ", type";
|
||||||
@ -1300,30 +1300,30 @@ abstract class DolibarrModules
|
|||||||
$sql.= ", '0'";
|
$sql.= ", '0'";
|
||||||
$sql.= ", ".$entity;
|
$sql.= ", ".$entity;
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::insert_".$key." sql=".$sql);
|
dol_syslog(get_class($this)."::insert_const_".$key." sql=".$sql);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if (! $resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::insert_".$key." ".$this->error);
|
dol_syslog(get_class($this)."::insert_const_".$key." ".$this->error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove activation of generic parts from modules in llx_const
|
* Remove activation of generic parts of modules from llx_const
|
||||||
*
|
*
|
||||||
* @return int Nb of errors (0 if OK)
|
* @return int Nb of errors (0 if OK)
|
||||||
*/
|
*/
|
||||||
function delete_module_parts()
|
function delete_module_parts()
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$err=0;
|
$err=0;
|
||||||
|
|
||||||
if (is_array($this->module_parts) && ! empty($this->module_parts))
|
if (is_array($this->module_parts) && ! empty($this->module_parts))
|
||||||
{
|
{
|
||||||
foreach($this->module_parts as $key => $value)
|
foreach($this->module_parts as $key => $value)
|
||||||
@ -1331,17 +1331,17 @@ abstract class DolibarrModules
|
|||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
|
||||||
$sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_".strtoupper($key)."'";
|
$sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_".strtoupper($key)."'";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete_".$key." sql=".$sql);
|
dol_syslog(get_class($this)."::delete_const_".$key." sql=".$sql);
|
||||||
if (! $this->db->query($sql))
|
if (! $this->db->query($sql))
|
||||||
{
|
{
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog(get_class($this)."::delete_".$key." ".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::delete_const_".$key." ".$this->error, LOG_ERR);
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,9 +70,6 @@ class modWorkflow extends DolibarrModules
|
|||||||
|
|
||||||
// Config pages. Put here list of php page names stored in admmin directory used to setup module.
|
// Config pages. Put here list of php page names stored in admmin directory used to setup module.
|
||||||
$this->config_page_url = 'workflow.php';
|
$this->config_page_url = 'workflow.php';
|
||||||
|
|
||||||
// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
|
|
||||||
$this->module_parts = array('triggers' => 1);
|
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
$this->depends = array(); // List of modules id that must be enabled if this module is enabled
|
$this->depends = array(); // List of modules id that must be enabled if this module is enabled
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user