diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9d2317d3c2c..243d4d57f7c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5417,26 +5417,20 @@ abstract class CommonObject $sql .= ",".$attributeKey; } // We must insert a default value for fields for other entities that are mandatory to avoid not null error - if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) - { - foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) - { - if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) // If field not already added previously - { + if (!empty($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) { + foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) { + if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) { // If field not already added previously $sql .= ",".$tmpkey; } } } $sql .= ") VALUES (".$this->id; - foreach ($new_array_options as $key => $value) - { + foreach ($new_array_options as $key => $value) { $attributeKey = substr($key, 8); // Remove 'options_' prefix // Add field of attribute - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) - { - if ($new_array_options[$key] != '' || $new_array_options[$key] == '0') - { + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { // Only for other type than separator) + if ($new_array_options[$key] != '' || $new_array_options[$key] == '0') { $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; } else { $sql .= ",null"; @@ -5444,12 +5438,9 @@ abstract class CommonObject } } // We must insert a default value for fields for other entities that are mandatory to avoid not null error - if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) - { - foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) - { - if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) // If field not already added previously - { + if (!empty($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) { + foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) { + if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) { // If field not already added previously if (in_array($tmpval, array('int', 'double', 'price'))) $sql .= ", 0"; else $sql .= ", ''"; }