Skip to content
Snippets Groups Projects
Commit 816db0e8 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Add protection against duplicate moduel with similar names

parent 7b2a7180
No related branches found
No related tags found
No related merge requests found
......@@ -51,4 +51,5 @@ WidgetFile=Widget file
ReadmeFile=Readme file
ChangeLog=ChangeLog file
SqlFile=Sql file
SqlFileKey=Sql file for keys
\ No newline at end of file
SqlFileKey=Sql file for keys
AnObjectAlreadyExistWithThisNameAndDiffCase=An object already exists with this name and a different case
\ No newline at end of file
......@@ -160,11 +160,29 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
}
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destdir = $dirins.'/'.strtolower($module);
// Scan dir class to find if an object with same name already exists.
if (! $error)
{
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destdir = $dirins.'/'.strtolower($module);
$dirlist=dol_dir_list($destdir.'/class','files',0,'\.txt$');
$alreadyfound=false;
foreach($dirlist as $key => $val)
{
$filefound=preg_replace('/\.txt$/','',$val['name']);
if (strtolower($objectname) == strtolower($filefound) && $objectname != $filefound)
{
$alreadyfound=true;
$error++;
setEventMessages($langs->trans("AnObjectAlreadyExistWithThisNameAndDiffCase"), null, 'errors');
break;
}
}
}
if (! $error)
{
// Delete some files
$filetogenerate = array(
'myobject_card.php'=>strtolower($objectname).'_card.php',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment