forked from Wavyzz/dolibarr
Fix: Avoid pgsql error of duplicate record making rollback.
This commit is contained in:
@@ -852,6 +852,7 @@ abstract class DolibarrModules
|
|||||||
|
|
||||||
dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
|
dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql_del);
|
$resql=$this->db->query($sql_del);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$obj=$this->db->fetch_object($resql);
|
$obj=$this->db->fetch_object($resql);
|
||||||
@@ -870,45 +871,57 @@ abstract class DolibarrModules
|
|||||||
|
|
||||||
if (empty($r_type)) $r_type='w';
|
if (empty($r_type)) $r_type='w';
|
||||||
|
|
||||||
if (dol_strlen($r_perms) )
|
// Search if perm already present
|
||||||
|
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."rights_def";
|
||||||
|
$sql.= " WHERE id = ".$r_id." AND entity = ".$entity;
|
||||||
|
$resqlselect=$this->db->query($sql);
|
||||||
|
|
||||||
|
$obj = $this->db->fetch_object($resqlselect);
|
||||||
|
if ($obj->nb == 0)
|
||||||
{
|
{
|
||||||
if (dol_strlen($r_subperms) )
|
if (dol_strlen($r_perms) )
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
if (dol_strlen($r_subperms) )
|
||||||
$sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
|
{
|
||||||
$sql.= " VALUES ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
||||||
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')";
|
$sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
|
||||||
}
|
$sql.= " VALUES ";
|
||||||
else
|
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')";
|
||||||
{
|
}
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
else
|
||||||
$sql.= " (id, entity, libelle, module, type, bydefault, perms)";
|
{
|
||||||
$sql.= " VALUES ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
||||||
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')";
|
$sql.= " (id, entity, libelle, module, type, bydefault, perms)";
|
||||||
}
|
$sql.= " VALUES ";
|
||||||
}
|
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')";
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
|
else
|
||||||
$sql .= " (id, entity, libelle, module, type, bydefault)";
|
{
|
||||||
$sql .= " VALUES ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
|
||||||
$sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")";
|
$sql .= " (id, entity, libelle, module, type, bydefault)";
|
||||||
|
$sql .= " VALUES ";
|
||||||
|
$sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")";
|
||||||
|
}
|
||||||
|
|
||||||
|
$resqlinsert=$this->db->query($sql,1);
|
||||||
|
|
||||||
|
if (! $resqlinsert)
|
||||||
|
{
|
||||||
|
if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS")
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
$err++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->free($resqlinsert);
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::insert_permissions", LOG_DEBUG);
|
$this->db->free($resqlselect);
|
||||||
$resqlinsert=$this->db->query($sql,1);
|
|
||||||
if (! $resqlinsert)
|
|
||||||
{
|
|
||||||
if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS")
|
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
$err++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO);
|
|
||||||
|
|
||||||
}
|
|
||||||
$this->db->free($resqlinsert);
|
|
||||||
|
|
||||||
// If we want to init permissions on admin users
|
// If we want to init permissions on admin users
|
||||||
if ($reinitadminperms)
|
if ($reinitadminperms)
|
||||||
|
|||||||
Reference in New Issue
Block a user