Merge pull request #23533 from Hystepik/develop#1

New : Add reload of modules in configuration
This commit is contained in:
Laurent Destailleur 2023-01-13 13:24:10 +01:00 committed by GitHub
commit 2890b7354f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 6 deletions

View File

@ -282,10 +282,39 @@ if ($action == 'set' && $user->admin) {
}
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
exit;
} elseif (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1 && $action == 'reload' && $user->admin && GETPOST('confirm') == 'yes') {
$result = unActivateModule($value, 0);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
if ($result) {
setEventMessages($result, null, 'errors');
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
}
$resarray = activateModule($value, 0, 1);
dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity);
if (!empty($resarray['errors'])) {
setEventMessages('', $resarray['errors'], 'errors');
} else {
if ($resarray['nbperms'] > 0) {
$tmpsql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."user WHERE admin <> 1";
$resqltmp = $db->query($tmpsql);
if ($resqltmp) {
$obj = $db->fetch_object($resqltmp);
if ($obj && $obj->nb > 1) {
$msg = $langs->trans('ModuleEnabledAdminMustCheckRights');
setEventMessages($msg, null, 'warnings');
}
} else {
dol_print_error($db);
}
}
}
header("Location: ".$_SERVER["PHP_SELF"]."?mode=".$mode.$param.($page_y ? '&page_y='.$page_y : ''));
exit;
}
/*
* View
*/
@ -464,6 +493,19 @@ if ($action == 'reset_confirm' && $user->admin) {
}
}
if ($action == 'reload_confirm' && $user->admin) {
if (!empty($modules[$value])) {
$objMod = $modules[$value];
if (!empty($objMod->langfiles)) {
$langs->loadLangs($objMod->langfiles);
}
$form = new Form($db);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?value='.$value.'&mode='.$mode.$param, $langs->trans('ConfirmReload'), $langs->trans(GETPOST('confirm_message_code')), 'reload', '', 'no', 1);
}
}
print $formconfirm;
asort($orders);
@ -802,10 +844,22 @@ if ($mode == 'common' || $mode == 'commonkanban') {
$codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reset_confirm&amp;confirm_message_code='.urlencode($objMod->warnings_unactivation[$mysoc->country_code]).'&amp;value='.$modName.'&amp;mode='.$mode.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
$codeenabledisable .= '</a>';
if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) {
$codeenabledisable .= '&nbsp;';
$codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reload_confirm&amp;value='.$modName.'&amp;mode='.$mode.'&amp;confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="fa-15"');
$codeenabledisable .= '</a>';
}
} else {
$codeenabledisable .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reset&amp;value='.$modName.'&amp;mode='.$mode.'&amp;confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on');
$codeenabledisable .= '</a>';
if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) {
$codeenabledisable .= '&nbsp;';
$codeenabledisable .= '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$objMod->numero.'&amp;token='.newToken().'&amp;module_position='.$module_position.'&amp;action=reload&amp;value='.$modName.'&amp;mode='.$mode.'&amp;confirm=yes'.$param.'">';
$codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="fa-15"');
$codeenabledisable .= '</a>';
}
}
}

View File

@ -1084,11 +1084,12 @@ function purgeSessions($mysessionid)
/**
* Enable a module
*
* @param string $value Name of module to activate
* @param int $withdeps Activate/Disable also all dependencies
* @return array array('nbmodules'=>nb modules activated with success, 'errors=>array of error messages, 'nbperms'=>Nb permission added);
* @param string $value Name of module to activate
* @param int $withdeps Activate/Disable also all dependencies
* @param int $noconfverification Remove verification of $conf variable for module
* @return array array('nbmodules'=>nb modules activated with success, 'errors=>array of error messages, 'nbperms'=>Nb permission added);
*/
function activateModule($value, $withdeps = 1)
function activateModule($value, $withdeps = 1, $noconfverification = 0)
{
global $db, $langs, $conf, $mysoc;
@ -1144,8 +1145,10 @@ function activateModule($value, $withdeps = 1)
}
$const_name = $objMod->const_name;
if (!empty($conf->global->$const_name)) {
return $ret;
if ($noconfverification == 0) {
if (!empty($conf->global->$const_name)) {
return $ret;
}
}
$result = $objMod->init(); // Enable module

View File

@ -2361,3 +2361,5 @@ AllowExternalDownload=Allow external download (without login, using a shared lin
DeadlineDayVATSubmission=Deadline day for vat submission on the next month
MaxNumberOfAttachementOnForms=Max number of joinded files in a form
IfDefinedUseAValueBeetween=If defined, use a value between %s and %s
Reload=Reload
ConfirmReload=Confirm module reload