Fix: Compatibility of new module setup with old setup

This commit is contained in:
Laurent Destailleur 2012-02-24 11:06:05 +01:00
parent 1b236c5c56
commit cc6a2c8d84
5 changed files with 42 additions and 39 deletions

View File

@ -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.

View File

@ -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='';

View File

@ -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);

View File

@ -1301,12 +1301,12 @@ abstract class DolibarrModules
$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);
} }
} }
} }
@ -1314,7 +1314,7 @@ abstract class DolibarrModules
} }
/** /**
* 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)
*/ */
@ -1332,11 +1332,11 @@ abstract class DolibarrModules
$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++;
} }
} }

View File

@ -71,9 +71,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
$this->requiredby = array(); // List of modules id to disable if this one is disabled $this->requiredby = array(); // List of modules id to disable if this one is disabled