Fix: bug #31902 : CLIENT CATEGORY SUPPRESS
This commit is contained in:
parent
8a58ab981e
commit
69aee95b21
@ -265,54 +265,112 @@ class Categorie
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete category
|
* Delete a category from database
|
||||||
* Les produits et sous-categories deviennent orphelins
|
* @param user Object user that ask to delete
|
||||||
* si $all = false, et sont (seront :) supprimes sinon
|
|
||||||
*/
|
*/
|
||||||
function remove ($all = false)
|
function delete($user)
|
||||||
{
|
{
|
||||||
|
global $conf,$langs;
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product";
|
$error=0;
|
||||||
$sql .= " WHERE fk_categorie = ".$this->id;
|
|
||||||
|
dol_syslog("Categorie::remove");
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
if (! $error)
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_societe";
|
||||||
return -1;
|
$sql .= " WHERE fk_categorie = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_fournisseur";
|
||||||
|
$sql .= " WHERE fk_categorie = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product";
|
||||||
|
$sql .= " WHERE fk_categorie = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member";
|
||||||
|
$sql .= " WHERE fk_categorie = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link childs to parent
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
|
||||||
|
$sql .= " WHERE fk_categorie_mere = ".$this->id;
|
||||||
|
$sql .= " OR fk_categorie_fille = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
|
// Delete category
|
||||||
$sql .= " WHERE fk_categorie_mere = ".$this->id;
|
if (! $error)
|
||||||
$sql .= " OR fk_categorie_fille = ".$this->id;
|
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie";
|
||||||
return -1;
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
if (!$this->db->query($sql))
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('CATEGORY_DELETE',$this,$user,$langs,$conf);
|
||||||
|
if ($result < 0) { $error++; $this->errors=$interface->errors; $this->error=join(',',$this->errors); }
|
||||||
|
// Fin appel triggers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie";
|
if (! $error)
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
$this->db->commit();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
$this->db->rollback();
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
return -1;
|
||||||
$interface=new Interfaces($this->db);
|
|
||||||
$result=$interface->run_triggers('CATEGORY_DELETE',$this,$user,$langs,$conf);
|
|
||||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
|
||||||
// Fin appel triggers
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajout d'une sous-categorie
|
* Ajout d'une sous-categorie
|
||||||
|
|||||||
@ -60,7 +60,7 @@ $type=$c->type;
|
|||||||
|
|
||||||
if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete' && $_POST['confirm'] == 'yes')
|
if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete' && $_POST['confirm'] == 'yes')
|
||||||
{
|
{
|
||||||
if ($c->remove() >= 0)
|
if ($c->delete($user) >= 0)
|
||||||
{
|
{
|
||||||
header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type);
|
header("Location: ".DOL_URL_ROOT.'/categories/index.php?type='.$type);
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user