From e1cf1070969983619c83866ff3311c2c0398d663 Mon Sep 17 00:00:00 2001 From: abb Date: Fri, 12 Feb 2016 21:51:26 +0100 Subject: [PATCH 1/2] Target object does not need to have all source object extrafields --- htdocs/core/class/commonobject.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 005f4684322..7cf15af7386 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3921,8 +3921,16 @@ abstract class CommonObject $langs->load('admin'); require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($this->table_element); - + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); + + //Eliminate copied source object extra_fiels that do not exist in target object + $new_array_options=array(); + foreach ($this->array_options as $key => $value) { + if (in_array(substr($key,8), array_keys($target_extrafields))) + $new_array_options[$key] = $value; + } + $this->array_options =$new_array_options; + foreach($this->array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix From 5966170a0d55835f42fe3ab1e50f203247ce7f01 Mon Sep 17 00:00:00 2001 From: Bahfir Abbes Date: Fri, 15 Jul 2016 10:43:01 +0100 Subject: [PATCH 2/2] Done, thanks --- htdocs/core/class/commonobject.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cc336939bb9..c833f880a6d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4127,15 +4127,14 @@ abstract class CommonObject $extrafields = new ExtraFields($this->db); $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); - //Eliminate copied source object extra_fiels that do not exist in target object + //Eliminate copied source object extra_fields that do not exist in target object $new_array_options=array(); foreach ($this->array_options as $key => $value) { if (in_array(substr($key,8), array_keys($target_extrafields))) $new_array_options[$key] = $value; } - $this->array_options =$new_array_options; - - foreach($this->array_options as $key => $value) + + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix $attributeType = $extrafields->attribute_type[$attributeKey]; @@ -4198,7 +4197,7 @@ abstract class CommonObject $this->db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; - foreach($this->array_options as $key => $value) + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix // Add field of attribut @@ -4206,7 +4205,7 @@ abstract class CommonObject $sql.=",".$attributeKey; } $sql .= ") VALUES (".$this->id; - foreach($this->array_options as $key => $value) + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix // Add field o fattribut