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:
commit
efd292e8f5
@ -599,48 +599,64 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
$datecreate = dol_now();
|
$datecreate = dol_now();
|
||||||
|
|
||||||
$this->db->begin();
|
// 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);
|
||||||
// Insertion dans la base
|
$already_added=false;
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
|
if(!empty($TListeContacts)) {
|
||||||
$sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
|
foreach($TListeContacts as $array_contact) {
|
||||||
$sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
||||||
$sql.= "'".$this->db->idate($datecreate)."'";
|
$already_added=true;
|
||||||
$sql.= ", 4, ". $id_type_contact;
|
break;
|
||||||
$sql.= ")";
|
}
|
||||||
|
}
|
||||||
$resql=$this->db->query($sql);
|
}
|
||||||
if ($resql)
|
|
||||||
{
|
if(!$already_added) {
|
||||||
if (! $notrigger)
|
|
||||||
{
|
$this->db->begin();
|
||||||
$result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user);
|
|
||||||
if ($result < 0)
|
// Insertion dans la base
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
|
||||||
|
$sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
|
||||||
|
$sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
||||||
|
$sql.= "'".$this->db->idate($datecreate)."'";
|
||||||
|
$sql.= ", 4, ". $id_type_contact;
|
||||||
|
$sql.= ")";
|
||||||
|
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
if (! $notrigger)
|
||||||
{
|
{
|
||||||
|
$result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user);
|
||||||
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
||||||
|
{
|
||||||
|
$this->error=$this->db->errno();
|
||||||
|
$this->db->rollback();
|
||||||
|
echo 'err rollback';
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else return 0;
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
|
||||||
{
|
|
||||||
$this->error=$this->db->errno();
|
|
||||||
$this->db->rollback();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->error();
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user