Merge pull request #2755 from aternatik/company_delete

Modify thirdparty delete() method to pass user object as an argument.
This commit is contained in:
Laurent Destailleur 2015-05-03 21:18:38 +02:00
commit a566ec3ace
4 changed files with 17 additions and 11 deletions

View File

@ -1278,12 +1278,14 @@ class Societe extends CommonObject
/** /**
* Delete a third party from database and all its dependencies (contacts, rib...) * 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 * @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'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -1298,10 +1300,14 @@ class Societe extends CommonObject
{ {
$this->db->begin(); $this->db->begin();
// Call trigger // User is mandatory for trigger call
$result=$this->call_trigger('COMPANY_DELETE',$user); if ($user && $call_trigger)
if ($result < 0) $error++; {
// End call triggers // Call trigger
$result=$this->call_trigger('COMPANY_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {

View File

@ -169,7 +169,7 @@ if (empty($reshook))
if (!$errors) { if (!$errors) {
//We finally remove the old thirdparty //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(); $db->rollback();
$errors++; $errors++;
} }
@ -598,7 +598,7 @@ if (empty($reshook))
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{ {
$object->fetch($socid); $object->fetch($socid);
$result = $object->delete($socid); $result = $object->delete($socid, $user);
if ($result > 0) if ($result > 0)
{ {

View File

@ -416,7 +416,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase
$this->assertNull($localobject->fk_soc); $this->assertNull($localobject->fk_soc);
//Now we remove the third party //Now we remove the third party
$result = $thirdparty->delete($thirdparty->id); $result = $thirdparty->delete($thirdparty->id,$user);
$this->assertEquals($result, 1); $this->assertEquals($result, 1);
return $localobject; return $localobject;

View File

@ -365,7 +365,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase
$localobject=new Societe($this->savdb); $localobject=new Societe($this->savdb);
$result=$localobject->fetch($id); $result=$localobject->fetch($id);
$result=$localobject->delete($id); $result=$localobject->delete($id, $user);
print __METHOD__." id=".$id." result=".$result."\n"; print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0); $this->assertLessThan($result, 0);