From 9859720dc3a21fcd02c9705406943f6f3adf46c1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 21 Apr 2023 13:27:50 +0200 Subject: [PATCH] Clean module dependency system --- htdocs/admin/modulehelp.php | 26 ++++++++-- htdocs/blockedlog/admin/blockedlog_list.php | 5 +- htdocs/core/class/menubase.class.php | 2 +- htdocs/core/lib/admin.lib.php | 52 ++++++++++++------- htdocs/core/modules/modBom.class.php | 7 +-- htdocs/core/modules/modBookCal.class.php | 2 +- .../modules/modEventOrganization.class.php | 2 +- .../modules/modKnowledgeManagement.class.php | 2 +- htdocs/core/modules/modMrp.class.php | 2 +- htdocs/core/modules/modPartnership.class.php | 2 +- htdocs/core/modules/modRecruitment.class.php | 2 +- .../core/modules/modStockTransfer.class.php | 2 +- htdocs/core/modules/modTakePos.class.php | 3 +- htdocs/core/modules/modWebhook.class.php | 2 +- htdocs/core/modules/modWorkstation.class.php | 2 +- htdocs/core/modules/modZapier.class.php | 2 +- .../core/modules/modMyModule.class.php | 8 +-- 17 files changed, 80 insertions(+), 43 deletions(-) diff --git a/htdocs/admin/modulehelp.php b/htdocs/admin/modulehelp.php index 09172e985e9..ecbe14e76f4 100644 --- a/htdocs/admin/modulehelp.php +++ b/htdocs/admin/modulehelp.php @@ -369,14 +369,32 @@ if ($mode == 'desc') { if ($mode == 'feature') { $text .= '
'.$langs->trans("DependsOn").': '; - if (count($objMod->depends)) { - $text .= join(',', $objMod->depends); + if (is_array($objMod->depends) && count($objMod->depends)) { + $i = 0; + foreach($objMod->depends as $modulestringorarray) { + if (is_array($modulestringorarray)) { + $text .= ($i ? ', ' : '').join(', ', $modulestringorarray); + } else { + $text .= ($i ? ', ' : '').$modulestringorarray; + } + $i++; + } } else { $text .= ''.$langs->trans("None").''; } + $text .= '
'; + $text .= '
'.$langs->trans("RequiredBy").': '; - if (count($objMod->requiredby)) { - $text .= join(',', $objMod->requiredby); + if (is_array($objMod->requiredby) && count($objMod->requiredby)) { + $i = 0; + foreach($objMod->requiredby as $modulestringorarray) { + if (is_array($modulestringorarray)) { + $text .= ($i ? ', ' : '').join(', ', $modulestringorarray); + } else { + $text .= ($i ? ', ' : '').$modulestringorarray; + } + $i++; + } } else { $text .= ''.$langs->trans("None").''; } diff --git a/htdocs/blockedlog/admin/blockedlog_list.php b/htdocs/blockedlog/admin/blockedlog_list.php index bf5a07f98b5..8d03c029cd6 100644 --- a/htdocs/blockedlog/admin/blockedlog_list.php +++ b/htdocs/blockedlog/admin/blockedlog_list.php @@ -550,7 +550,10 @@ if (is_array($blocks)) { print ''; // Link to source object - print ''.$object_link.''; + print ''; + print ''; // $object_link can be a ''; // Amount print ''.price($block->amounts).''; diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 2965db0f7c5..f289e2c8cf9 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -313,7 +313,7 @@ class Menubase } } else { dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING); - $this->error = 'Error Menu entry already exists'; + $this->error = 'Error Menu entry ('.$this->menu_handler.','.$this->position.','.$this->url.') already exists'; return 0; } } else { diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 0064fad3bc7..572b4219bd4 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1166,33 +1166,45 @@ function activateModule($value, $withdeps = 1, $noconfverification = 0) if ($withdeps) { if (isset($objMod->depends) && is_array($objMod->depends) && !empty($objMod->depends)) { // Activation of modules this module depends on - // this->depends may be array('modModule1', 'mmodModule2') or array('always1'=>"modModule1", 'FR'=>'modModule2') - foreach ($objMod->depends as $key => $modulestring) { + // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>array('modModule1'), 'FR'=>array('modModule2")) + foreach ($objMod->depends as $key => $modulestringorarray) { //var_dump((! is_numeric($key)) && ! preg_match('/^always/', $key) && $mysoc->country_code && ! preg_match('/^'.$mysoc->country_code.'/', $key));exit; if ((!is_numeric($key)) && !preg_match('/^always/', $key) && $mysoc->country_code && !preg_match('/^'.$mysoc->country_code.'/', $key)) { dol_syslog("We are not concerned by dependency with key=".$key." because our country is ".$mysoc->country_code); continue; } - $activate = false; - foreach ($modulesdir as $dir) { - if (file_exists($dir.$modulestring.".class.php")) { - $resarray = activateModule($modulestring); - if (empty($resarray['errors'])) { - $activate = true; - } else { - foreach ($resarray['errors'] as $errorMessage) { - dol_syslog($errorMessage, LOG_ERR); - } - } - break; - } + + if (!is_array($modulestringorarray)) { + $modulestringorarray = array($modulestringorarray); } - if ($activate) { - $ret['nbmodules'] += $resarray['nbmodules']; - $ret['nbperms'] += $resarray['nbperms']; - } else { - $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring); + foreach($modulestringorarray as $modulestring) { + $activate = false; + $activateerr = ''; + foreach ($modulesdir as $dir) { + if (file_exists($dir.$modulestring.".class.php")) { + $resarray = activateModule($modulestring); + if (empty($resarray['errors'])) { + $activate = true; + } else { + $activateerr = join(', ', $resarray['errors']); + foreach ($resarray['errors'] as $errorMessage) { + dol_syslog($errorMessage, LOG_ERR); + } + } + break; + } + } + + if ($activate) { + $ret['nbmodules'] += $resarray['nbmodules']; + $ret['nbperms'] += $resarray['nbperms']; + } else { + if ($activateerr) { + $ret['errors'][] = $activateerr; + } + $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring); + } } } } diff --git a/htdocs/core/modules/modBom.class.php b/htdocs/core/modules/modBom.class.php index 12fc50b5ff3..d8c95c3c26b 100644 --- a/htdocs/core/modules/modBom.class.php +++ b/htdocs/core/modules/modBom.class.php @@ -105,9 +105,10 @@ class modBom extends DolibarrModules // Dependencies $this->hidden = false; // A condition to hide module - $this->depends = array('modProduct'); // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) - $this->requiredby = array('modMrp'); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) - $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) + $this->depends = array('modProduct'); + $this->requiredby = array('modMrp'); + $this->conflictwith = array(); $this->langfiles = array("mrp"); //$this->phpmin = array(7, 0)); // Minimum version of PHP required by module $this->need_dolibarr_version = array(9, 0); // Minimum version of Dolibarr required by module diff --git a/htdocs/core/modules/modBookCal.class.php b/htdocs/core/modules/modBookCal.class.php index 6e3d6768206..935293fedc4 100644 --- a/htdocs/core/modules/modBookCal.class.php +++ b/htdocs/core/modules/modBookCal.class.php @@ -129,7 +129,7 @@ class modBookCal extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modEventOrganization.class.php b/htdocs/core/modules/modEventOrganization.class.php index 1bec1c5c67e..0ecd1ba805f 100644 --- a/htdocs/core/modules/modEventOrganization.class.php +++ b/htdocs/core/modules/modEventOrganization.class.php @@ -114,7 +114,7 @@ class modEventOrganization extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array('modProjet','modCategorie'); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modKnowledgeManagement.class.php b/htdocs/core/modules/modKnowledgeManagement.class.php index c372f611c60..6bfee4935e9 100644 --- a/htdocs/core/modules/modKnowledgeManagement.class.php +++ b/htdocs/core/modules/modKnowledgeManagement.class.php @@ -131,7 +131,7 @@ class modKnowledgeManagement extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modMrp.class.php b/htdocs/core/modules/modMrp.class.php index 593a5611de0..f315a4594c4 100644 --- a/htdocs/core/modules/modMrp.class.php +++ b/htdocs/core/modules/modMrp.class.php @@ -117,7 +117,7 @@ class modMrp extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array('modBom'); $this->requiredby = array('modWorkstation'); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modPartnership.class.php b/htdocs/core/modules/modPartnership.class.php index 44ef6b527db..b8aafc853fb 100644 --- a/htdocs/core/modules/modPartnership.class.php +++ b/htdocs/core/modules/modPartnership.class.php @@ -138,7 +138,7 @@ class modPartnership extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modRecruitment.class.php b/htdocs/core/modules/modRecruitment.class.php index 8b2db1a115a..499b6419982 100644 --- a/htdocs/core/modules/modRecruitment.class.php +++ b/htdocs/core/modules/modRecruitment.class.php @@ -117,7 +117,7 @@ class modRecruitment extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modStockTransfer.class.php b/htdocs/core/modules/modStockTransfer.class.php index 34de040fdb8..b0b616e3b36 100644 --- a/htdocs/core/modules/modStockTransfer.class.php +++ b/htdocs/core/modules/modStockTransfer.class.php @@ -119,7 +119,7 @@ class modStockTransfer extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array('modStock', 'modProduct'); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modTakePos.class.php b/htdocs/core/modules/modTakePos.class.php index ce6395fdb73..697501a62a7 100644 --- a/htdocs/core/modules/modTakePos.class.php +++ b/htdocs/core/modules/modTakePos.class.php @@ -98,7 +98,8 @@ class modTakePos extends DolibarrModules // Dependencies $this->hidden = false; // A condition to hide module - $this->depends = array('always1'=>"modBanque", 'always2'=>"modFacture", 'always3'=>"modProduct", 'always4'=>'modCategorie', 'FR1'=>'modBlockedLog'); // List of module class names as string that must be enabled if this module is enabled + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) + $this->depends = array('always'=>array("modBanque", "modFacture", "modProduct", "modCategorie"), 'FR'=>array('modBlockedLog')); $this->requiredby = array(); // List of module ids to disable if this one is disabled $this->conflictwith = array(); // List of module class names as string this module is in conflict with $this->langfiles = array("cashdesk"); diff --git a/htdocs/core/modules/modWebhook.class.php b/htdocs/core/modules/modWebhook.class.php index e9f3e7f5baa..57761bb6fe2 100644 --- a/htdocs/core/modules/modWebhook.class.php +++ b/htdocs/core/modules/modWebhook.class.php @@ -130,7 +130,7 @@ class modWebhook extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modWorkstation.class.php b/htdocs/core/modules/modWorkstation.class.php index 6bba7b1807a..be697917563 100644 --- a/htdocs/core/modules/modWorkstation.class.php +++ b/htdocs/core/modules/modWorkstation.class.php @@ -119,7 +119,7 @@ class modWorkstation extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array('modMrp'); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) diff --git a/htdocs/core/modules/modZapier.class.php b/htdocs/core/modules/modZapier.class.php index b14419e0982..f3d187cf3bb 100644 --- a/htdocs/core/modules/modZapier.class.php +++ b/htdocs/core/modules/modZapier.class.php @@ -117,7 +117,7 @@ class modZapier extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...)) $this->depends = array('modApi'); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->requiredby = array(); diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 2788c78fc37..8133013bbb0 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -135,10 +135,12 @@ class modMyModule extends DolibarrModules // Dependencies // A condition to hide module $this->hidden = false; - // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...) + // List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...) $this->depends = array(); - $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) - $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) + // List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...) + $this->requiredby = array(); + // List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...) + $this->conflictwith = array(); // The language file dedicated to your module $this->langfiles = array("mymodule@mymodule");