From 192e62fa5c00e5d82d831aa377c2916e41849806 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 21 Feb 2022 15:41:41 +0100 Subject: [PATCH 1/5] Fix : fix bug class and sql regeneration in modulebuilder --- htdocs/core/lib/modulebuilder.lib.php | 34 +++++++++++++-------------- htdocs/modulebuilder/index.php | 4 +++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 7c32b377bd4..d5d4aa8c2c4 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -125,46 +125,46 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $texttoinsert .= " 'position'=>".($val['position'] !== '' ? $val['position'] : 50).","; $texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).","; $texttoinsert .= " 'visible'=>".($val['visible'] !== '' ? $val['visible'] : -1).","; - if ($val['noteditable']) { + if (!empty($val['noteditable'])) { $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',"; } - if ($val['default'] || $val['default'] === '0') { + if (!empty($val['default']) || (!empty($val['default']) && $val['default'] === '0')) { $texttoinsert .= " 'default'=>'".$val['default']."',"; } - if ($val['index']) { + if (!empty($val['index'])) { $texttoinsert .= " 'index'=>".$val['index'].","; } - if ($val['foreignkey']) { + if (!empty($val['foreignkey'])) { $texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',"; } - if ($val['searchall']) { + if (!empty($val['searchall'])) { $texttoinsert .= " 'searchall'=>".$val['searchall'].","; } - if ($val['isameasure']) { + if (!empty($val['isameasure'])) { $texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',"; } - if ($val['css']) { + if (!empty($val['css'])) { $texttoinsert .= " 'css'=>'".$val['css']."',"; } - if ($val['cssview']) { + if (!empty($val['cssview'])) { $texttoinsert .= " 'cssview'=>'".$val['cssview']."',"; } - if ($val['csslist']) { + if (!empty($val['csslist'])) { $texttoinsert .= " 'csslist'=>'".$val['csslist']."',"; } - if ($val['help']) { + if (!empty($val['help'])) { $texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; } - if ($val['showoncombobox']) { + if (!empty($val['showoncombobox'])) { $texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',"; } - if ($val['disabled']) { + if (!empty($val['disabled'])) { $texttoinsert .= " 'disabled'=>'".$val['disabled']."',"; } - if ($val['autofocusoncreate']) { + if (!empty($val['autofocusoncreate'])) { $texttoinsert .= " 'autofocusoncreate'=>'".$val['autofocusoncreate']."',"; } - if ($val['arrayofkeyval']) { + if (!empty($val['arrayofkeyval'])) { $texttoinsert .= " 'arrayofkeyval'=>array("; $i = 0; foreach ($val['arrayofkeyval'] as $key2 => $val2) { @@ -176,10 +176,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = } $texttoinsert .= "),"; } - if ($val['validate']) { + if (!empty($val['validate'])) { $texttoinsert .= " 'validate'=>'".$val['validate']."',"; } - if ($val['comment']) { + if (!empty($val['comment'])) { $texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\""; } @@ -311,7 +311,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' if ($key == 'entity') { $texttoinsert .= ' DEFAULT 1'; } else { - if ($val['default'] != '') { + if (!empty($val['default']) && $val['default'] != '') { if (preg_match('/^null$/i', $val['default'])) { $texttoinsert .= " DEFAULT NULL"; } elseif (preg_match('/varchar/', $type)) { diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 60f23cbee1a..e0bd19ab251 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1309,7 +1309,7 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && } } - if (!$error) { + if (!$error && !GETPOST('regenerateclasssql')&& !GETPOST('regeneratemissing')) { $addfieldentry = array( 'name'=>GETPOST('propname', 'aZ09'), 'label'=>GETPOST('proplabel', 'alpha'), @@ -1335,6 +1335,8 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) { $addfieldentry['arrayofkeyval'] = json_decode($addfieldentry['arrayofkeyval'], true); } + } else { + $addfieldentry = array(); } /*if (GETPOST('regeneratemissing')) From edbf1bb34b903d3c16c903935cac8b1847f516e3 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 22 Feb 2022 16:35:10 +0100 Subject: [PATCH 2/5] update to fix PR --- htdocs/core/lib/modulebuilder.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index d5d4aa8c2c4..1e4c43b1f90 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -311,7 +311,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = ' if ($key == 'entity') { $texttoinsert .= ' DEFAULT 1'; } else { - if (!empty($val['default']) && $val['default'] != '') { + if (!empty($val['default'])) { if (preg_match('/^null$/i', $val['default'])) { $texttoinsert .= " DEFAULT NULL"; } elseif (preg_match('/varchar/', $type)) { From b45aeda14d1d3d37b3f9560f6bcbab74bff6cea4 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 15 Mar 2022 09:41:51 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/modulebuilder/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 240c739e5c0..eddf9b3c7de 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1332,8 +1332,8 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); } - if (!$error && !GETPOST('regenerateclasssql')&& !GETPOST('regeneratemissing')) { - $addfieldentry = array( + if (!$error && !GETPOST('regenerateclasssql')&& !GETPOST('regeneratemissing')) { + $addfieldentry = array( 'name'=>GETPOST('propname', 'aZ09'), 'label'=>GETPOST('proplabel', 'alpha'), 'type'=>GETPOST('proptype', 'alpha'), @@ -1353,7 +1353,7 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) && 'default'=>GETPOST('propdefault', 'restricthtml'), 'noteditable'=>intval(GETPOST('propnoteditable', 'int')), 'validate' => GETPOST('propvalidate', 'int') - ); + ); if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) { From 89eb19bafb4acdcc0b71eb3dafec044682646a1c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 5 Apr 2022 17:51:42 +0200 Subject: [PATCH 4/5] Update modulebuilder.lib.php --- htdocs/core/lib/modulebuilder.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 1e4c43b1f90..27c96c2e972 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -128,7 +128,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = if (!empty($val['noteditable'])) { $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',"; } - if (!empty($val['default']) || (!empty($val['default']) && $val['default'] === '0')) { + if (!empty($val['default']) || (isset($val['default']) && $val['default'] === '0')) { $texttoinsert .= " 'default'=>'".$val['default']."',"; } if (!empty($val['index'])) { From 2af2efacdb68bb8847287fb2ce2966caa87cb2ed Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 15 Apr 2022 14:42:34 +0200 Subject: [PATCH 5/5] better fix for line 131 in modulebuilder.lib --- htdocs/core/lib/modulebuilder.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 1e4c43b1f90..27c96c2e972 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -128,7 +128,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = if (!empty($val['noteditable'])) { $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',"; } - if (!empty($val['default']) || (!empty($val['default']) && $val['default'] === '0')) { + if (!empty($val['default']) || (isset($val['default']) && $val['default'] === '0')) { $texttoinsert .= " 'default'=>'".$val['default']."',"; } if (!empty($val['index'])) {