Merge pull request #7126 from atm-gauthier/FIX_add_contact

FIX : we have to check if contact doesn't already exist on add_contact
This commit is contained in:
Laurent Destailleur 2017-07-07 20:33:24 +02:00 committed by GitHub
commit efd292e8f5

View File

@ -600,6 +600,20 @@ abstract class CommonObject
$datecreate = dol_now(); $datecreate = dol_now();
// Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error
$TListeContacts=$this->liste_contact(-1, $source);
$already_added=false;
if(!empty($TListeContacts)) {
foreach($TListeContacts as $array_contact) {
if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
$already_added=true;
break;
}
}
}
if(!$already_added) {
$this->db->begin(); $this->db->begin();
// Insertion dans la base // Insertion dans la base
@ -632,6 +646,7 @@ abstract class CommonObject
{ {
$this->error=$this->db->errno(); $this->error=$this->db->errno();
$this->db->rollback(); $this->db->rollback();
echo 'err rollback';
return -2; return -2;
} }
else else
@ -641,6 +656,7 @@ abstract class CommonObject
return -1; return -1;
} }
} }
} else return 0;
} }
/** /**