Fix better comaptibilty for extrafield email/mail

This commit is contained in:
ldestailleur
2025-08-05 00:45:00 +02:00
parent eab3227ea0
commit 86f5db7aa9
8 changed files with 48 additions and 18 deletions

View File

@@ -55,7 +55,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
$error = 0;
// Check parameters
// Check parameters into $addfieldentry (this provided array is filled by modulebuilder/index.php)
if (is_array($addfieldentry) && count($addfieldentry) > 0) {
if (empty($addfieldentry['name'])) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors');
@@ -66,11 +66,12 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
return -2;
}
if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration|stars)/', $addfieldentry['type'])
&& !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|mail|url|ip|password)$/', $addfieldentry['type'])) {
&& !preg_match('/^(boolean|smallint|real|date|datetime|timestamp|phone|email|url|ip|password)$/', $addfieldentry['type'])) { // Use email for email, mail is kept for compatibility
setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors');
return -2;
}
// Check for type stars(NumberOfStars), NumberOfStars must be an integer between 1 and 10
$matches = array();
if (preg_match('/^stars\((.+)\)$/', $addfieldentry['type'], $matches)) {
if (!ctype_digit($matches[1]) || $matches[1] < 1 || $matches[1] > 10) {
setEventMessages($langs->trans('BadValueForType', $addfieldentry['type']), null, 'errors');
@@ -350,7 +351,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$type = 'integer';
} elseif ($type == 'chkbxlst') {
$type = 'varchar(128)';
} elseif ($type == 'mail') {
} elseif ($type == 'mail' || $type == 'email') { // Prefer to use 'email'
$type = 'varchar(128)';
} elseif (strpos($type, 'stars(') === 0) {
$type = 'integer';
@@ -358,6 +359,8 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$type = 'varchar(20)';
} elseif ($type == 'ip') {
$type = 'varchar(32)';
} elseif ($type == 'url') {
$type = 'varchar(255)';
}
$texttoinsert .= "\t".$key." ".$type;