FIX Can't insert if there is extrafields mandatory on another entity.
FIX Can't set default value of extrafield of type varchar
This commit is contained in:
parent
4c85068a85
commit
032aa869e4
@ -4993,9 +4993,12 @@ abstract class CommonObject
|
|||||||
$sql.=",".$attributeKey;
|
$sql.=",".$attributeKey;
|
||||||
}
|
}
|
||||||
// We must insert a default value for fields for other entities that are mandatory to avoid not null error
|
// We must insert a default value for fields for other entities that are mandatory to avoid not null error
|
||||||
foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval)
|
if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities']))
|
||||||
{
|
{
|
||||||
$sql.=",".$tmpkey;
|
foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval)
|
||||||
|
{
|
||||||
|
$sql.=",".$tmpkey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$sql .= ") VALUES (".$this->id;
|
$sql .= ") VALUES (".$this->id;
|
||||||
|
|
||||||
@ -5016,10 +5019,13 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We must insert a default value for fields for other entities that are mandatory to avoid not null error
|
// We must insert a default value for fields for other entities that are mandatory to avoid not null error
|
||||||
foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval)
|
if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities']))
|
||||||
{
|
{
|
||||||
if (in_array($tmpval, array('int', 'double'))) $sql.=", 0";
|
foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval)
|
||||||
else $sql.=", ''";
|
{
|
||||||
|
if (in_array($tmpval, array('int', 'double'))) $sql.=", 0";
|
||||||
|
else $sql.=", ''";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql.=")";
|
$sql.=")";
|
||||||
|
|||||||
@ -797,7 +797,7 @@ class ExtraFields
|
|||||||
if ($tab->entity != 0 && $tab->entity != $conf->entity)
|
if ($tab->entity != 0 && $tab->entity != $conf->entity)
|
||||||
{
|
{
|
||||||
// This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field
|
// This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field
|
||||||
if ($tab->fieldrequired)
|
if ($tab->fieldrequired && is_null($tab->fielddefault))
|
||||||
{
|
{
|
||||||
$this->attributes[$tab->elementtype]['mandatoryfieldsofotherentities'][$tab->name]=$tab->type;
|
$this->attributes[$tab->elementtype]['mandatoryfieldsofotherentities'][$tab->name]=$tab->type;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -835,7 +835,7 @@ class DoliDBMysqli extends DoliDB
|
|||||||
if ($field_desc['default'] != '')
|
if ($field_desc['default'] != '')
|
||||||
{
|
{
|
||||||
if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
|
if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
|
||||||
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
elseif ($field_desc['type'] != 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
|
dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
|
||||||
|
|||||||
@ -1138,7 +1138,7 @@ class DoliDBPgsql extends DoliDB
|
|||||||
if ($field_desc['default'] != '')
|
if ($field_desc['default'] != '')
|
||||||
{
|
{
|
||||||
if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
|
if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
|
||||||
elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
elseif ($field_desc['type'] != 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog($sql,LOG_DEBUG);
|
dol_syslog($sql,LOG_DEBUG);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user