Fix update field when visilbity is 4 or -4

This commit is contained in:
Laurent Destailleur 2020-11-09 09:53:56 +01:00
parent fc49583efe
commit 807d3b99c9
2 changed files with 11 additions and 5 deletions

View File

@ -60,7 +60,10 @@ if ($action == 'add' && !empty($permissiontoadd))
if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited
}
// Ignore special fields
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
if (in_array($key, array('rowid', 'entity', 'import_key'))) continue;
if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
if (!in_array(abs($val['visible']), array(1, 3))) continue; // Only 1 and 3 that are case to create
}
// Set value to insert
if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
@ -141,7 +144,10 @@ if ($action == 'update' && !empty($permissiontoadd))
if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited
}
// Ignore special fields
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
if (in_array($key, array('rowid', 'entity', 'import_key'))) continue;
if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
if (!in_array(abs($val['visible']), array(1, 3, 4))) continue; // Only 1 and 3 and 4 that are case to update
}
// Set value to update
if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) {

View File

@ -7512,8 +7512,7 @@ abstract class CommonObject
// Depending on field type ('datetime', ...)
if ($this->isDate($info))
{
if (empty($this->{$field}))
{
if (empty($this->{$field})) {
$queryarray[$field] = null;
} else {
$queryarray[$field] = $this->db->idate($this->{$field});
@ -7928,6 +7927,7 @@ abstract class CommonObject
unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update.
if (array_key_exists('ref', $fieldvalues)) $fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']); // If field is a ref, we sanitize data
// Add quotes and escape on fields with type string
$keys = array();
$values = array();
$tmp = array();
@ -7938,7 +7938,7 @@ abstract class CommonObject
$tmp[] = $k.'='.$this->quote($v, $this->fields[$k]);
}
// Clean and check mandatory
// Clean and check mandatory fields
foreach ($keys as $key)
{
if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field