diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index d19e28faa01..960d9ee7eec 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -644,19 +644,17 @@ function dol_fileperm($pathoffile) /** * Make replacement of strings into a file. * - * @param string $srcfile Source file (can't be a directory) + * @param string $srcfile Source file (can't be a directory) * @param array $arrayreplacement Array with strings to replace. Example: array('valuebefore'=>'valueafter', ...) - * @param string $destfile Destination file (can't be a directory). If empty, will be same than source file. - * @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666' - * @param int $indexdatabase 1=index new file into database. - * @param int $arrayreplacementisregex 1=Array of replacement is already an array with key that is a regex. Warning: the key must be escaped with preg_quote for '/' - * @return int Return integer <0 if error, 0 if nothing done (dest file already exists), >0 if OK + * @param string $destfile Destination file (can't be a directory). If empty, will be same than source file. + * @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666' + * @param int $indexdatabase 1=index new file into database. + * @param int $arrayreplacementisregex 1=Array of replacement is already an array with key that is a regex. Warning: the key must be escaped with preg_quote for '/' + * @return int Return integer <0 if error, 0 if nothing done (dest file already exists), >0 if OK * @see dol_copy() */ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = '0', $indexdatabase = 0, $arrayreplacementisregex = 0) { - global $conf; - dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase." arrayreplacementisregex=".$arrayreplacementisregex); if (empty($srcfile)) { diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 19d9c9319a2..68e8b982cce 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -456,20 +456,37 @@ function dolGetListOfObjectClasses($destdir) return -1; } + /** - * function for check if comment begin an end exist in modMyModule class - * @param string $file filename or path - * @param int $number 0 = For Menus,1 = For permissions, 2 = For Dictionaries - * @return int 1 if OK , -1 if KO + * Function to check if comment begin an end exist in modMyModule class + * + * @param string $file Filename or path + * @param int $number 0 = For Menus,1 = For permissions, 2 = For Dictionaries + * @return int 1 if OK , -1 if KO */ function checkExistComment($file, $number) { if (!file_exists($file)) { return -1; } + $content = file_get_contents($file); if ($number === 0) { - if (strpos($content, '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */') !== false && strpos($content, '/* END MODULEBUILDER LEFTMENU MYOBJECT */') !== false) { + $ret = 0; + if (strpos($content, '/* BEGIN MODULEBUILDER TOPMENU MYOBJECT */') !== false) { + $ret++; + } + if (strpos($content, '/* END MODULEBUILDER TOPMENU MYOBJECT */') !== false) { + $ret++; + } + if (strpos($content, '/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */') !== false) { + $ret++; + } + if (strpos($content, '/* END MODULEBUILDER LEFTMENU MYOBJECT */') !== false) { + $ret++; + } + + if ($ret == 4) { return 1; } } elseif ($number === 1) { diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 3290d9a2251..fe7cb304610 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -374,7 +374,7 @@ WarningModuleNeedRefresh = Module %s has been disabled. Don't forget to e WarningPermissionAlreadyExist=Existing permissions for this object WarningGoOnAccountancySetupToAddAccounts=If this list is empty, go into menu %s - %s - %s to load or create accounts for your chart of account. WarningCorrectedInvoiceNotFound=Corrected invoice not found -WarningCommentNotFound=Please check placement of start and end comments for %s section in file %s before submitting your action +WarningCommentNotFound=Warning: Can't find the start and/or end comments for the section %s into the file %s WarningAlreadyReverse=Stock movement already reversed SwissQrOnlyVIR = SwissQR invoice can only be added on invoices set to be paid with credit transfer payments. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 6d1a5a85d06..1e78c341f06 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1017,6 +1017,8 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) { // Init an object if ($dirins && $action == 'initobject' && $module && $objectname) { + $warning = 0; + $objectname = ucfirst($objectname); $dirins = $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath']; @@ -1365,13 +1367,12 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { } } - if (!$error) { foreach ($filetogenerate as $srcfile => $destfile) { $result = dol_copy($srcdir.'/'.$srcfile, $destdir.'/'.$destfile, $newmask, 0); if ($result <= 0) { if ($result < 0) { - $error++; + $warning++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFailToCopyFile", $srcdir.'/'.$srcfile, $destdir.'/'.$destfile), null, 'errors'); } else { @@ -1383,6 +1384,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { '/myobject\.class\.php/' => strtolower($objectname).'.class.php', '/myobject\.lib\.php/' => strtolower($objectname).'.lib.php', ); + dolReplaceInFile($destdir.'/'.$destfile, $arrayreplacement, '', 0, 0, 1); } } @@ -1529,8 +1531,8 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { if (!$counter) { $checkComment = checkExistComment($moduledescriptorfile, 0); if ($checkComment < 0) { - $error++; - setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), "mod".$module."class.php"), null, 'warnings'); + $warning++; + setEventMessages($langs->trans("WarningCommentNotFound", $langs->trans("Menus"), basename($moduledescriptorfile)), null, 'warnings'); } else { $arrayofreplacement = array('/* END MODULEBUILDER LEFTMENU MYOBJECT */' => '/*LEFTMENU '.strtoupper($objectname).'*/'.$stringtoadd."\n\t\t".'/*END LEFTMENU '.strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER LEFTMENU MYOBJECT */'); dolReplaceInFile($moduledescriptorfile, $arrayofreplacement); @@ -1580,7 +1582,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { if (is_numeric($object) && $object <= 0) { $pathoffiletoeditsrc = $destdir.'/class/'.strtolower($objectname).'.class.php'; setEventMessages($langs->trans('ErrorFailToCreateFile', $pathoffiletoeditsrc), null, 'errors'); - $error++; + $warning++; } // check if documentation was generate and add table of properties object $file = $destdir.'/class/'.strtolower($objectname).'.class.php'; @@ -1610,7 +1612,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { // check if module is enabled 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); + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity); if ($result) { setEventMessages($result, null, 'errors'); } @@ -1898,11 +1900,12 @@ if ($dirins && $action == 'confirm_deletemodule') { } else { $error++; $langs->load("errors"); - dol_print_error($db, $langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module)); - exit; + setEventMessages($langs->trans("ErrorFailedToLoadModuleDescriptorForXXX", $module), null, 'warnings'); } - $moduleobj->remove(); + if ($moduleobj) { + $moduleobj->remove(); + } $result = dol_delete_dir_recursive($dir); diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 0b166dd54b1..53c7957cf78 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -28,6 +28,7 @@ */ include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; + /** * Description and activation class for module MyModule */ @@ -303,8 +304,10 @@ class modMyModule extends DolibarrModules // Main menu entries to add $this->menu = array(); $r = 0; + // Add here entries to declare new menus - /* BEGIN MODULEBUILDER TOPMENU */ + + /* BEGIN MODULEBUILDER TOPMENU MYOBJECT */ $this->menu[$r++] = array( 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode 'type'=>'top', // This is a Top menu entry @@ -320,7 +323,8 @@ class modMyModule extends DolibarrModules 'target'=>'', 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both ); - /* END MODULEBUILDER TOPMENU */ + /* END MODULEBUILDER TOPMENU MYOBJECT */ + /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */ /*$this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=mymodule', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode @@ -366,6 +370,8 @@ class modMyModule extends DolibarrModules 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both );*/ /* END MODULEBUILDER LEFTMENU MYOBJECT */ + + // Exports profiles provided by this module $r = 1; /* BEGIN MODULEBUILDER EXPORT MYOBJECT */