Clean module dependency system

This commit is contained in:
Laurent Destailleur 2023-04-21 13:27:50 +02:00
parent 692eee1e25
commit 9859720dc3
17 changed files with 80 additions and 43 deletions

View File

@ -369,14 +369,32 @@ if ($mode == 'desc') {
if ($mode == 'feature') {
$text .= '<br><strong>'.$langs->trans("DependsOn").':</strong> ';
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 .= '<span class="opacitymedium">'.$langs->trans("None").'</span>';
}
$text .= '<br>';
$text .= '<br><strong>'.$langs->trans("RequiredBy").':</strong> ';
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 .= '<span class="opacitymedium">'.$langs->trans("None").'</span>';
}

View File

@ -550,7 +550,10 @@ if (is_array($blocks)) {
print '</td>';
// Link to source object
print '<td'.(preg_match('/<a/', $object_link) ? ' class="nowrap"' : '').'><!-- object_link -->'.$object_link.'</td>';
print '<td class="tdoverflowmax150"'.(preg_match('/<a/', $object_link) ? '' : 'title="'.dol_escape_htmltag(dol_string_nohtmltag($object_link)).'"').'>';
print '<!-- object_link -->'; // $object_link can be a '<a href' link or a text
print $object_link;
print '</td>';
// Amount
print '<td class="right nowraponall">'.price($block->amounts).'</td>';

View File

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

View File

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

View File

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

View File

@ -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', ...)

View File

@ -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', ...)

View File

@ -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', ...)

View File

@ -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', ...)

View File

@ -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', ...)

View File

@ -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', ...)

View File

@ -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', ...)

View File

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

View File

@ -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', ...)

View File

@ -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', ...)

View File

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

View File

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