Skip to content

Commit

Permalink
Fix #5843 best way fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanjo Menent committed Oct 7, 2016
1 parent 298e5ce commit 45dfb8c
Showing 1 changed file with 30 additions and 44 deletions.
74 changes: 30 additions & 44 deletions htdocs/categories/class/categorie.class.php
Expand Up @@ -558,7 +558,6 @@ function add_type($obj,$type)
global $user,$langs,$conf;

$error=0;
$trigger=true;

if ($this->id == -1) return -2;

Expand Down Expand Up @@ -591,26 +590,23 @@ function add_type($obj,$type)
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql) > 0)
{
$objparent = $this->db->fetch_object($resql);
if ($this->db->num_rows($resql) > 0) {
$objparent = $this->db->fetch_object($resql);

if (!empty($objparent->fk_parent)) {
$cat = new Categorie($this->db);
$cat->id = $objparent->fk_parent;

if (!$cat->containsObject($type, $obj->id)) {
$result = $cat->add_type($obj, $type);
if ($result < 0) {
$this->error = $cat->error;
$error++;
}

if (!empty($objparent->fk_parent))
{
$cat = new Categorie($this->db);
$cat->id=$objparent->fk_parent;

if (! $cat->containsObject($type,$obj->id)) {
$result=$cat->add_type($obj, $type);
if ($result < 0) {
$this->error=$cat->error;
$error++;
}
} else {
$trigger=false;
}
}
}
}
}
}
else
{
Expand All @@ -629,13 +625,10 @@ function add_type($obj,$type)
$this->linkto=$obj;

// Call trigger
if ($trigger) {
$result = $this->call_trigger('CATEGORY_LINK', $user);
if ($result < 0) {
$error++;
}
// End call triggers
}
$result=$this->call_trigger('CATEGORY_LINK',$user);
if ($result < 0) { $error++; }
// End call triggers

if (! $error)
{
$this->db->commit();
Expand All @@ -650,24 +643,17 @@ function add_type($obj,$type)
}
else
{
if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
if (empty($conf->global->CATEGORIE_RECURSIV_ADD)) {
$this->db->rollback();
$this->error = $this->db->lasterrno();
return -3;
}
else {
$this->db->commit();
return 1;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1;
}
$this->db->rollback();
if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error=$this->db->lasterrno();
return -3;
}
else
{
$this->error=$this->db->lasterror();
}
return -1;
}
}

Expand Down

0 comments on commit 45dfb8c

Please sign in to comment.