diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 93144e155c9..897fab2d676 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1278,12 +1278,14 @@ class Societe extends CommonObject /** * Delete a third party from database and all its dependencies (contacts, rib...) * - * @param int $id Id of third party to delete + * @param int $id Id of third party to delete + * @param User $user User who ask to delete thirparty + * @param int $call_trigger 0=No, 1=yes * @return int <0 if KO, 0 if nothing done, >0 if OK */ - function delete($id) + function delete($id, $user='', $call_trigger=1) { - global $user, $langs, $conf; + global $langs, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1298,10 +1300,14 @@ class Societe extends CommonObject { $this->db->begin(); - // Call trigger - $result=$this->call_trigger('COMPANY_DELETE',$user); - if ($result < 0) $error++; - // End call triggers + // User is mandatory for trigger call + if ($user && $call_trigger) + { + // Call trigger + $result=$this->call_trigger('COMPANY_DELETE',$user); + if ($result < 0) $error++; + // End call triggers + } if (! $error) { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 20ebdca3ba2..7ce537bd149 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -169,7 +169,7 @@ if (empty($reshook)) if (!$errors) { //We finally remove the old thirdparty - if ($soc_origin->delete($soc_origin->id) < 1) { + if ($soc_origin->delete($soc_origin->id, $user) < 1) { $db->rollback(); $errors++; } @@ -598,7 +598,7 @@ if (empty($reshook)) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) { $object->fetch($socid); - $result = $object->delete($socid); + $result = $object->delete($socid, $user); if ($result > 0) { diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 01424d81796..3a19b195b7c 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -416,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertNull($localobject->fk_soc); //Now we remove the third party - $result = $thirdparty->delete($thirdparty->id); + $result = $thirdparty->delete($thirdparty->id,$user); $this->assertEquals($result, 1); return $localobject; diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 34fdee385f7..8bcfb247365 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -365,7 +365,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase $localobject=new Societe($this->savdb); $result=$localobject->fetch($id); - $result=$localobject->delete($id); + $result=$localobject->delete($id, $user); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0);