diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index a1c0ee2badf..1e506526a1d 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -579,20 +579,25 @@ class ActionComm extends CommonObject // Now insert assigned users if (!$error) { //dol_syslog(var_export($this->userassigned, true)); + $already_inserted = array(); foreach ($this->userassigned as $key => $val) { if (!is_array($val)) { // For backward compatibility when val=id $val = array('id'=>$val); } if ($val['id'] > 0) { + if (!empty($already_inserted[$val['id']])) continue; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql .= " VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['mandatory']) ? '0' : $val['mandatory']).", ".(empty($val['transparency']) ? '0' : $val['transparency']).", ".(empty($val['answer_status']) ? '0' : $val['answer_status']).")"; $resql = $this->db->query($sql); if (!$resql) { $error++; - dol_syslog('Error to process userassigned: '.$this->db->lasterror(), LOG_ERR); + dol_syslog('Error to process userassigned: ' . $this->db->lasterror(), LOG_ERR); $this->errors[] = $this->db->lasterror(); + } else { + $already_inserted[$val['id']] = true; } //var_dump($sql);exit; } @@ -601,15 +606,20 @@ class ActionComm extends CommonObject if (!$error) { if (!empty($this->socpeopleassigned)) { + $already_inserted = array(); foreach ($this->socpeopleassigned as $id => $val) { + if (!empty($already_inserted[$val['id']])) continue; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql .= " VALUES(".$this->id.", 'socpeople', ".$id.", 0, 0, 0)"; $resql = $this->db->query($sql); if (!$resql) { $error++; - dol_syslog('Error to process socpeopleassigned: '.$this->db->lasterror(), LOG_ERR); + dol_syslog('Error to process socpeopleassigned: ' . $this->db->lasterror(), LOG_ERR); $this->errors[] = $this->db->lasterror(); + } else { + $already_inserted[$val['id']] = true; } } } @@ -1143,10 +1153,13 @@ class ActionComm extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".$this->id." AND element_type = 'user'"; $resql = $this->db->query($sql); + $already_inserted = array(); foreach ($this->userassigned as $key => $val) { if (!is_array($val)) { // For backward compatibility when val=id $val = array('id'=>$val); } + if (!empty($already_inserted[$val['id']])) continue; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql .= " VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['mandatory']) ? '0' : $val['mandatory']).", ".(empty($val['transparency']) ? '0' : $val['transparency']).", ".(empty($val['answer_status']) ? '0' : $val['answer_status']).")"; @@ -1154,6 +1167,8 @@ class ActionComm extends CommonObject if (!$resql) { $error++; $this->errors[] = $this->db->lasterror(); + } else { + $already_inserted[$val['id']] = true; } //var_dump($sql);exit; } @@ -1164,7 +1179,10 @@ class ActionComm extends CommonObject $resql = $this->db->query($sql); if (!empty($this->socpeopleassigned)) { + $already_inserted = array(); foreach (array_keys($this->socpeopleassigned) as $id) { + if (!empty($already_inserted[$val['id']])) continue; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; $sql .= " VALUES(".$this->id.", 'socpeople', ".$id.", 0, 0, 0)"; @@ -1172,6 +1190,8 @@ class ActionComm extends CommonObject if (!$resql) { $error++; $this->errors[] = $this->db->lasterror(); + } else { + $already_inserted[$val['id']] = true; } } }