forked from Wavyzz/dolibarr
Merge pull request #2755 from aternatik/company_delete
Modify thirdparty delete() method to pass user object as an argument.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user