From 55334dff3b67a2ce211a86addd7e128a68a305a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 28 Aug 2019 13:04:22 +0200 Subject: [PATCH] FIX management of extrafields in modulebuilder --- htdocs/modulebuilder/index.php | 81 +++++++++++++++---- .../llx_mymodule_myobject_extrafields.key.sql | 19 +++++ 2 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index b80977decd8..d67fa08fafa 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -258,7 +258,6 @@ if ($dirins && $action == 'initapi' && !empty($module)) dolReplaceInFile($destfile, $arrayreplacement); } } - if ($dirins && $action == 'initphpunit' && !empty($module)) { $modulename = ucfirst($module); // Force first letter in uppercase @@ -297,7 +296,45 @@ if ($dirins && $action == 'initphpunit' && !empty($module)) } } +if ($dirins && $action == 'initsqlextrafields' && !empty($module)) +{ + $modulename = ucfirst($module); // Force first letter in uppercase + $objectname = $tabobj; + dol_mkdir($dirins.'/'.strtolower($module).'/sql'); + $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template'; + $srcfile1 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.sql'; + $destfile1 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql'; + //var_dump($srcfile);var_dump($destfile); + $result1 = dol_copy($srcfile1, $destfile1, 0, 0); + $srcfile2 = $srcdir.'/sql/llx_mymodule_myobject_extrafields.key.sql'; + $destfile2 = $dirins.'/'.strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.key.sql'; + //var_dump($srcfile);var_dump($destfile); + $result2 = dol_copy($srcfile2, $destfile2, 0, 0); + + if ($result1 > 0 && $result2 > 0) + { + $modulename = ucfirst($module); // Force first letter in uppercase + + //var_dump($phpfileval['fullname']); + $arrayreplacement=array( + 'mymodule'=>strtolower($modulename), + 'MyModule'=>$modulename, + 'MYMODULE'=>strtoupper($modulename), + 'My module'=>$modulename, + 'my module'=>$modulename, + 'Mon module'=>$modulename, + 'mon module'=>$modulename, + 'htdocs/modulebuilder/template'=>strtolower($modulename), + '---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'') + ); + + dolReplaceInFile($destfile1, $arrayreplacement); + dolReplaceInFile($destfile2, $arrayreplacement); + } + + // TODO Enable in class the property $isextrafieldmanaged = 1 +} if ($dirins && $action == 'inithook' && !empty($module)) { dol_mkdir($dirins.'/'.strtolower($module).'/class'); @@ -1893,8 +1930,8 @@ elseif (! empty($module)) if ($realpathtoapi) { print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '   '; - print ''.img_picto($langs->trans("Delete"), 'delete').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; print '   '; if (empty($conf->global->$const_name)) // If module is not activated { @@ -1917,8 +1954,8 @@ elseif (! empty($module)) if ($realpathtophpunit) { print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '   '; - print ''.img_picto($langs->trans("Delete"), 'delete').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; } else { @@ -1942,12 +1979,21 @@ elseif (! empty($module)) print '
'; print ' '.$langs->trans("SqlFile").' : '.($realpathtosql?'':'').$pathtosql.($realpathtosql?'':'').''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '   '.$langs->trans("DropTableIfEmpty").''; + print '   '.$langs->trans("DropTableIfEmpty").''; //print '   '.$langs->trans("RunSql").''; print '
'; print ' '.$langs->trans("SqlFileExtraFields").' : '.($realpathtosqlextra?'':'').$pathtosqlextra.($realpathtosqlextra?'':'').''; - print ' '.img_picto($langs->trans("Edit"), 'edit').''; - print '   '.$langs->trans("DropTableIfEmpty").''; + if ($realpathtosqlextra) + { + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; + print '   '; + print ''.$langs->trans("DropTableIfEmpty").''; + } + else { + print ''; + } //print '   '.$langs->trans("RunSql").''; print '
'; print ' '.$langs->trans("SqlFileKey").' : '.($realpathtosqlkey?'':'').$pathtosqlkey.($realpathtosqlkey?'':'').''; @@ -1955,7 +2001,12 @@ elseif (! empty($module)) //print '   '.$langs->trans("RunSql").''; print '
'; print ' '.$langs->trans("SqlFileKeyExtraFields").' : '.($realpathtosqlextrakey?'':'').$pathtosqlextrakey.($realpathtosqlextrakey?'':'').''; - print ' '.img_picto($langs->trans("Edit"), 'edit').''; + if ($realpathtosqlextrakey) + { + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; + } //print '   '.$langs->trans("RunSql").''; print '
'; @@ -1976,24 +2027,24 @@ elseif (! empty($module)) print ' '.img_picto($langs->trans("Edit"), 'edit').''; if ($realpathtoagenda) { - print '   '; - print ''.img_picto($langs->trans("Delete"), 'delete').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; } print '
'; print ' '.$langs->trans("PageForDocumentTab").' : '.($realpathtodocument?'':'').$pathtodocument.($realpathtodocument?'':'').''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; if ($realpathtodocument) { - print '   '; - print ''.img_picto($langs->trans("Delete"), 'delete').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; } print '
'; print ' '.$langs->trans("PageForNoteTab").' : '.($realpathtonote?'':'').$pathtonote.($realpathtonote?'':'').''; print ' '.img_picto($langs->trans("Edit"), 'edit').''; if ($realpathtonote) { - print '   '; - print ''.img_picto($langs->trans("Delete"), 'delete').''; + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; } print '
'; diff --git a/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql new file mode 100644 index 00000000000..016117feebb --- /dev/null +++ b/htdocs/modulebuilder/template/sql/llx_mymodule_myobject_extrafields.key.sql @@ -0,0 +1,19 @@ +-- Copyright (C) ---Put here your own copyright and developer email--- +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see http://www.gnu.org/licenses/. + + +-- BEGIN MODULEBUILDER INDEXES +ALTER TABLE llx_mymodule_myobject_extrafields ADD INDEX idx_fk_object(fk_object); +-- END MODULEBUILDER INDEXES