From 9f0523dc1da2a0f259edc9fbec88eff65645b6e7 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 11 Aug 2023 19:34:35 +0200 Subject: [PATCH 1/2] add functionality for edit property of module --- htdocs/langs/en_US/modulebuilder.lang | 3 +- htdocs/langs/fr_FR/modulebuilder.lang | 3 +- htdocs/modulebuilder/index.php | 144 ++++++++++++++++++++++++-- 3 files changed, 141 insertions(+), 9 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 5a7e8fbd980..6c11876b9c6 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -179,4 +179,5 @@ CRUDRead=Read CRUDCreateWrite=Create or Update FailedToAddCodeIntoDescriptor=Failed to add code into descriptor. Check that the string comment "%s" is still present into the file. DictionariesCreated=Dictionary %s created successfully -DictionaryDeleted=Dictionary %s removed successfully \ No newline at end of file +DictionaryDeleted=Dictionary %s removed successfully +PropertyModuleUpdated=Property %s has been update successfully \ No newline at end of file diff --git a/htdocs/langs/fr_FR/modulebuilder.lang b/htdocs/langs/fr_FR/modulebuilder.lang index 4ca5ddc464c..7ed3dda2382 100644 --- a/htdocs/langs/fr_FR/modulebuilder.lang +++ b/htdocs/langs/fr_FR/modulebuilder.lang @@ -179,4 +179,5 @@ CRUDRead=Lire CRUDCreateWrite=Créer ou mettre à jour FailedToAddCodeIntoDescriptor=Échec de l'ajout de code dans le descripteur. Vérifiez que le commentaire de chaîne "%s" est toujours présent dans le fichier. DictionariesCreated = Le dictionnaire %s a été créé avec succès -DictionaryDeleted=Le dictionnaire %s a été supprimé avec succès \ No newline at end of file +DictionaryDeleted=Le dictionnaire %s a été supprimé avec succès +PropertyModuleUpdated=Propriété %s a été modifiée avec succès \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 5e6ea71a22f..77a620e9256 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2726,6 +2726,77 @@ if ($dirins && $action == "modify_menu" && GETPOST('menukey', 'int')) { } } +// update properties description of module +if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescription', 'alpha')) && empty($cancel)) { + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + 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: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=menus&module='.$module); + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); + } + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + $modulelogfile = $dirins.'/'.strtolower($module).'/ChangeLog.md'; + + dol_include_once($pathtofile); + + $class = 'mod'.$module; + if (class_exists($class)) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + + $keydescription = GETPOST('keydescription', 'alpha'); + switch ($keydescription) { + case 'desc': + $propertyToUpdate = 'description'; + break; + case 'version': + $propertyToUpdate = 'version'; + break; + case 'family': + $propertyToUpdate = 'family'; + break; + case 'editor_name': + $propertyToUpdate = 'editor_name'; + break; + case 'editor_url': + $propertyToUpdate = 'editor_url'; + break; + default: + $error = GETPOST('keydescription'); + break; + } + + if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) { + $newValue = GETPOST('propsmodule'); + $lineToReplace = "\$this->$propertyToUpdate = '".$moduleobj->$propertyToUpdate."';"; + $newLine = "\$this->$propertyToUpdate = '$newValue';"; + + //for change version in log file + if ($propertyToUpdate === 'version') { + dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue)); + } + + dolReplaceInFile($moduledescriptorfile, array($lineToReplace => $newLine)); + + clearstatcache(true); + if (function_exists('opcache_invalidate')) { + opcache_reset(); + } + setEventMessages($langs->trans('PropertyModuleUpdated', $propertyToUpdate), null); + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=description&module='.$module); + exit; + } +} + /* * View */ @@ -3192,7 +3263,12 @@ if ($module == 'initmodule') { if (!empty($moduleobj)) { print '
'; print '
'; - + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print $langs->trans("Parameter"); @@ -3220,20 +3296,59 @@ if ($module == 'initmodule') { print '
'; print $langs->trans("Description"); print ''; - print $moduleobj->getDesc(); + if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') { + print ''; + print ''; + print ''; + } else { + print $moduleobj->getDesc(); + print ''.img_edit().''; + } print '
'; print $langs->trans("Version"); print ''; - print $moduleobj->getVersion(); + if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'version') { + print ''; + print ''; + print ''; + } else { + print $moduleobj->getVersion(); + print ''.img_edit().''; + } print '
'; print $langs->trans("Family"); //print "
'crm','financial','hr','projects','products','ecm','technic','interface','other'"; print '
'; - print $moduleobj->family; + if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'family') { + print ''; + print ''; + print ''; + } else { + print $moduleobj->family; + print ''.img_edit().''; + } print '
'; @@ -3246,18 +3361,33 @@ if ($module == 'initmodule') { print '
'; print $langs->trans("EditorName"); print ''; - print $moduleobj->editor_name; + if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_name') { + print ''; + print ''; + print ''; + } else { + print $moduleobj->editor_name; + print ''.img_edit().''; + } print '
'; print $langs->trans("EditorUrl"); print ''; - if (!empty($moduleobj->editor_url)) { - print ''.$moduleobj->editor_url.' '.img_picto('', 'globe').''; + if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'editor_url') { + print ''; + print ''; + print ''; + } else { + if (!empty($moduleobj->editor_url)) { + print ''.$moduleobj->editor_url.' '.img_picto('', 'globe').''; + } + print ''.img_edit().''; } print '
'; + print '
'; } else { print $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module).'
'; } From bd67313d348f91ecff1cecec57809379aed9a082 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Mon, 14 Aug 2023 12:37:21 +0200 Subject: [PATCH 2/2] finish this functionnality --- htdocs/modulebuilder/index.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 77a620e9256..0ce99f75a19 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2777,15 +2777,21 @@ if ($dirins && $action == "update_props_module" && !empty(GETPOST('keydescriptio if (isset($propertyToUpdate) && !empty(GETPOST('propsmodule'))) { $newValue = GETPOST('propsmodule'); - $lineToReplace = "\$this->$propertyToUpdate = '".$moduleobj->$propertyToUpdate."';"; - $newLine = "\$this->$propertyToUpdate = '$newValue';"; + $lineToReplace = "\t\t\$this->$propertyToUpdate = "; + $newLine = "\t\t\$this->$propertyToUpdate = '$newValue';\n"; //for change version in log file if ($propertyToUpdate === 'version') { dolReplaceInFile($modulelogfile, array("## ".$moduleobj->$propertyToUpdate => $newValue)); } - dolReplaceInFile($moduledescriptorfile, array($lineToReplace => $newLine)); + $fileLines = file($moduledescriptorfile); + foreach ($fileLines as &$line) { + if (strpos($line, $lineToReplace) === 0) { + dolReplaceInFile($moduledescriptorfile, array($line => $newLine)); + break; + } + } clearstatcache(true); if (function_exists('opcache_invalidate')) { @@ -3297,7 +3303,7 @@ if ($module == 'initmodule') { print $langs->trans("Description"); print ''; if ($action == 'edit_moduledescription' && GETPOST('keydescription', 'alpha') === 'desc') { - print ''; + print ''; print ''; print ''; } else { @@ -3339,8 +3345,11 @@ if ($module == 'initmodule') { 'base' => 'ModuleFamilyBase', 'other' => 'ModuleFamilyOther' ); + print ''; foreach ($arrayoffamilies as $key => $value) { - print ''; + if ($key != $moduleobj->family) { + print ''; + } } print ''; print '';