Merge pull request #20134 from Hystepik/develop#2

Fix : fix bug in modulebuilder and fix php8.0 warnings in modulebuilder
This commit is contained in:
Laurent Destailleur 2022-05-20 22:50:35 +02:00 committed by GitHub
commit 58a77ae890
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 37 deletions

View File

@ -128,46 +128,46 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
$texttoinsert .= " 'position'=>".($val['position'] !== '' ? $val['position'] : 50).","; $texttoinsert .= " 'position'=>".($val['position'] !== '' ? $val['position'] : 50).",";
$texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).","; $texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).",";
$texttoinsert .= " 'visible'=>".($val['visible'] !== '' ? $val['visible'] : -1).","; $texttoinsert .= " 'visible'=>".($val['visible'] !== '' ? $val['visible'] : -1).",";
if ($val['noteditable']) { if (!empty($val['noteditable'])) {
$texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',"; $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',";
} }
if ($val['default'] || $val['default'] === '0') { if (!empty($val['default']) || (isset($val['default']) && $val['default'] === '0')) {
$texttoinsert .= " 'default'=>'".$val['default']."',"; $texttoinsert .= " 'default'=>'".$val['default']."',";
} }
if ($val['index']) { if (!empty($val['index'])) {
$texttoinsert .= " 'index'=>".$val['index'].","; $texttoinsert .= " 'index'=>".$val['index'].",";
} }
if ($val['foreignkey']) { if (!empty($val['foreignkey'])) {
$texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',"; $texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',";
} }
if ($val['searchall']) { if (!empty($val['searchall'])) {
$texttoinsert .= " 'searchall'=>".$val['searchall'].","; $texttoinsert .= " 'searchall'=>".$val['searchall'].",";
} }
if ($val['isameasure']) { if (!empty($val['isameasure'])) {
$texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',"; $texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',";
} }
if ($val['css']) { if (!empty($val['css'])) {
$texttoinsert .= " 'css'=>'".$val['css']."',"; $texttoinsert .= " 'css'=>'".$val['css']."',";
} }
if ($val['cssview']) { if (!empty($val['cssview'])) {
$texttoinsert .= " 'cssview'=>'".$val['cssview']."',"; $texttoinsert .= " 'cssview'=>'".$val['cssview']."',";
} }
if ($val['csslist']) { if (!empty($val['csslist'])) {
$texttoinsert .= " 'csslist'=>'".$val['csslist']."',"; $texttoinsert .= " 'csslist'=>'".$val['csslist']."',";
} }
if ($val['help']) { if (!empty($val['help'])) {
$texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; $texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\",";
} }
if ($val['showoncombobox']) { if (!empty($val['showoncombobox'])) {
$texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',"; $texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',";
} }
if ($val['disabled']) { if (!empty($val['disabled'])) {
$texttoinsert .= " 'disabled'=>'".$val['disabled']."',"; $texttoinsert .= " 'disabled'=>'".$val['disabled']."',";
} }
if ($val['autofocusoncreate']) { if (!empty($val['autofocusoncreate'])) {
$texttoinsert .= " 'autofocusoncreate'=>'".$val['autofocusoncreate']."',"; $texttoinsert .= " 'autofocusoncreate'=>'".$val['autofocusoncreate']."',";
} }
if ($val['arrayofkeyval']) { if (!empty($val['arrayofkeyval'])) {
$texttoinsert .= " 'arrayofkeyval'=>array("; $texttoinsert .= " 'arrayofkeyval'=>array(";
$i = 0; $i = 0;
foreach ($val['arrayofkeyval'] as $key2 => $val2) { foreach ($val['arrayofkeyval'] as $key2 => $val2) {
@ -179,10 +179,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
} }
$texttoinsert .= "),"; $texttoinsert .= "),";
} }
if ($val['validate']) { if (!empty($val['validate'])) {
$texttoinsert .= " 'validate'=>'".$val['validate']."',"; $texttoinsert .= " 'validate'=>'".$val['validate']."',";
} }
if ($val['comment']) { if (!empty($val['comment'])) {
$texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\""; $texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\"";
} }
@ -314,7 +314,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
if ($key == 'entity') { if ($key == 'entity') {
$texttoinsert .= ' DEFAULT 1'; $texttoinsert .= ' DEFAULT 1';
} else { } else {
if ($val['default'] != '') { if (!empty($val['default'])) {
if (preg_match('/^null$/i', $val['default'])) { if (preg_match('/^null$/i', $val['default'])) {
$texttoinsert .= " DEFAULT NULL"; $texttoinsert .= " DEFAULT NULL";
} elseif (preg_match('/varchar/', $type)) { } elseif (preg_match('/varchar/', $type)) {

View File

@ -1442,7 +1442,7 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
} }
if (!$error) { if (!$error && !GETPOST('regenerateclasssql')&& !GETPOST('regeneratemissing')) {
$addfieldentry = array( $addfieldentry = array(
'name'=>GETPOST('propname', 'aZ09'), 'name'=>GETPOST('propname', 'aZ09'),
'label'=>GETPOST('proplabel', 'alpha'), 'label'=>GETPOST('proplabel', 'alpha'),
@ -1465,10 +1465,13 @@ if ($dirins && $action == 'addproperty' && empty($cancel) && !empty($module) &&
'validate' => GETPOST('propvalidate', 'int') 'validate' => GETPOST('propvalidate', 'int')
); );
if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) { if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval'])) {
$addfieldentry['arrayofkeyval'] = json_decode($addfieldentry['arrayofkeyval'], true); $addfieldentry['arrayofkeyval'] = json_decode($addfieldentry['arrayofkeyval'], true);
} }
} }
} else {
$addfieldentry = array();
} }
/*if (GETPOST('regeneratemissing')) /*if (GETPOST('regeneratemissing'))