FIX: object cloning: set unique extrafield values to null to prevent duplicates

This commit is contained in:
Marc de Lima Lucio 2022-03-01 10:50:22 +01:00
parent df9fa39d34
commit e3aae6d2e1

View File

@ -5307,8 +5307,15 @@ abstract class CommonObject
$attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey];
$attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey];
$attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey];
$attributeUnique = $extrafields->attributes[$this->table_element]['unique'][$attributeKey];
$attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey];
// If we clone, we have to clean unique extrafields to prevent duplicates.
// This behaviour can be prevented by external code by changing $this->context['createfromclone'] value in createFrom hook
if (! empty($this->context['createfromclone']) && $this->context['createfromclone'] == 'createfromclone' && ! empty($attributeUnique)) {
$new_array_options[$key] = null;
}
// Similar code than into insertExtraFields
if ($attributeRequired)
{