From 551daa5ca1806e0ac4d272a10a787ebf1b326a33 Mon Sep 17 00:00:00 2001 From: hystepik Date: Thu, 12 Jan 2023 16:26:39 +0100 Subject: [PATCH 1/2] New : Add reload of modules in configuration --- htdocs/admin/modules.php | 54 +++++++++++++++++++++++++++++++++++ htdocs/core/lib/admin.lib.php | 15 ++++++---- htdocs/langs/en_US/admin.lang | 2 ++ 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index e93b5a58e96..db019bd262a 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -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 .= 'warnings_unactivation[$mysoc->country_code]).'&value='.$modName.'&mode='.$mode.$param.'">'; $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on'); $codeenabledisable .= ''; + if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) { + $codeenabledisable .= ' '; + $codeenabledisable .= ''; + $codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="fa-15"'); + $codeenabledisable .= ''; + } } else { $codeenabledisable .= ''; $codeenabledisable .= img_picto($langs->trans("Activated"), 'switch_on'); $codeenabledisable .= ''; + if (getDolGlobalInt("MAIN_FEATURES_LEVEL") > 1) { + $codeenabledisable .= ' '; + $codeenabledisable .= ''; + $codeenabledisable .= img_picto($langs->trans("Reload"), 'refresh', 'class="fa-15"'); + $codeenabledisable .= ''; + } } } diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 71bcc082961..92895793082 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -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 diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 421ba4f6fa2..34bae07fc37 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2357,3 +2357,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 \ No newline at end of file From 8a5423b464df64b3c825efc47901f2ec1c61342d Mon Sep 17 00:00:00 2001 From: hystepik Date: Thu, 12 Jan 2023 16:29:58 +0100 Subject: [PATCH 2/2] add newline end of file --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 34bae07fc37..cfe01784bea 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2358,4 +2358,4 @@ 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 \ No newline at end of file +ConfirmReload=Confirm module reload