Fix: Test if child exists to avoid error
This commit is contained in:
parent
20dea64979
commit
e4b445fcb1
@ -791,30 +791,38 @@ class Societe extends CommonObject
|
|||||||
dol_syslog("Societe::Delete", LOG_DEBUG);
|
dol_syslog("Societe::Delete", LOG_DEBUG);
|
||||||
$sqr = 0;
|
$sqr = 0;
|
||||||
|
|
||||||
// Check if third party can be deleted
|
// Test if child exists
|
||||||
$nbpropal=0;
|
$listtable=array("propal","commande","facture","contrat","facture_fourn","commande_fournisseur");
|
||||||
$sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX."propal";
|
$haschild=0;
|
||||||
$sql.= " WHERE fk_soc = " . $id;
|
foreach($listtable as $table)
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
{
|
||||||
$obj=$this->db->fetch_object($resql);
|
// Check if third party can be deleted
|
||||||
$nbpropal=$obj->nb;
|
$nb=0;
|
||||||
if ($nbpropal > 0)
|
$sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table;
|
||||||
{
|
$sql.= " WHERE fk_soc = " . $id;
|
||||||
$this->error="ErrorRecordHasChildren";
|
$resql=$this->db->query($sql);
|
||||||
return -1;
|
if ($resql)
|
||||||
}
|
{
|
||||||
|
$obj=$this->db->fetch_object($resql);
|
||||||
|
if ($obj->nb > 0)
|
||||||
|
{
|
||||||
|
$haschild+=$obj->nb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error .= $this->db->lasterror();
|
||||||
|
dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
if ($haschild > 0)
|
||||||
{
|
{
|
||||||
$this->error .= $this->db->lasterror();
|
$this->error="ErrorRecordHasChildren";
|
||||||
dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($this->db->begin())
|
if ($this->db->begin())
|
||||||
{
|
{
|
||||||
// Added by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html)
|
// Added by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user