Fix trigger to insert lines where called when inserting line but also
when cloning parent object, making no way to know when to use them or not. I introduced a context to allow code to know that and do not triggers twice.
This commit is contained in:
parent
386eaf0911
commit
41a74c62e2
@ -267,6 +267,8 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
$object=new Mailing($this->db);
|
$object=new Mailing($this->db);
|
||||||
|
|
||||||
|
$object->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -362,6 +364,8 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -393,6 +393,8 @@ class Propal extends CommonObject
|
|||||||
// Insert line
|
// Insert line
|
||||||
$this->line=new PropaleLigne($this->db);
|
$this->line=new PropaleLigne($this->db);
|
||||||
|
|
||||||
|
$this->line->context = $this->context;
|
||||||
|
|
||||||
$this->line->fk_propal=$this->id;
|
$this->line->fk_propal=$this->id;
|
||||||
$this->line->label=$label;
|
$this->line->label=$label;
|
||||||
$this->line->desc=$desc;
|
$this->line->desc=$desc;
|
||||||
@ -953,6 +955,8 @@ class Propal extends CommonObject
|
|||||||
{
|
{
|
||||||
global $user,$langs,$conf,$hookmanager;
|
global $user,$langs,$conf,$hookmanager;
|
||||||
|
|
||||||
|
$this->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
$now=dol_now();
|
$now=dol_now();
|
||||||
|
|
||||||
@ -1046,6 +1050,8 @@ class Propal extends CommonObject
|
|||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -878,6 +878,8 @@ class Commande extends CommonOrder
|
|||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
$this->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// get extrafields so they will be clone
|
// get extrafields so they will be clone
|
||||||
@ -942,6 +944,8 @@ class Commande extends CommonOrder
|
|||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -300,7 +300,9 @@ class BankCateg // extends CommonObject
|
|||||||
|
|
||||||
$object=new BankCateg($this->db);
|
$object=new BankCateg($this->db);
|
||||||
|
|
||||||
$this->db->begin();
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$object->fetch($fromid);
|
$object->fetch($fromid);
|
||||||
@ -327,6 +329,8 @@ class BankCateg // extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -607,6 +607,8 @@ class Facture extends CommonInvoice
|
|||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
$this->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// get extrafields so they will be clone
|
// get extrafields so they will be clone
|
||||||
@ -693,6 +695,8 @@ class Facture extends CommonInvoice
|
|||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -33,6 +33,7 @@ class PaymentTerm // extends CommonObject
|
|||||||
var $errors=array(); //!< To return several error codes (or messages)
|
var $errors=array(); //!< To return several error codes (or messages)
|
||||||
//public $element='c_payment_term'; //!< Id that identify managed objects
|
//public $element='c_payment_term'; //!< Id that identify managed objects
|
||||||
//public $table_element='c_payment_term'; //!< Name of table without prefix where object is stored
|
//public $table_element='c_payment_term'; //!< Name of table without prefix where object is stored
|
||||||
|
var $context =array();
|
||||||
|
|
||||||
var $id;
|
var $id;
|
||||||
|
|
||||||
@ -409,6 +410,8 @@ class PaymentTerm // extends CommonObject
|
|||||||
|
|
||||||
$object=new PaymentTerm($this->db);
|
$object=new PaymentTerm($this->db);
|
||||||
|
|
||||||
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -436,6 +439,8 @@ class PaymentTerm // extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -384,6 +384,8 @@ class PaymentSocialContribution extends CommonObject
|
|||||||
|
|
||||||
$object=new PaymentSocialContribution($this->db);
|
$object=new PaymentSocialContribution($this->db);
|
||||||
|
|
||||||
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -411,6 +413,8 @@ class PaymentSocialContribution extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,6 +38,7 @@ abstract class CommonObject
|
|||||||
public $error;
|
public $error;
|
||||||
public $errors;
|
public $errors;
|
||||||
public $canvas; // Contains canvas name if it is
|
public $canvas; // Contains canvas name if it is
|
||||||
|
public $context=array(); // Use to pass context information
|
||||||
|
|
||||||
public $name;
|
public $name;
|
||||||
public $lastname;
|
public $lastname;
|
||||||
|
|||||||
@ -718,6 +718,8 @@ class Cronjob extends CommonObject
|
|||||||
|
|
||||||
$object=new Cronjob($this->db);
|
$object=new Cronjob($this->db);
|
||||||
|
|
||||||
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -744,6 +746,8 @@ class Cronjob extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1024,7 +1024,9 @@ class CommandeFournisseur extends CommonOrder
|
|||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$objFrom = dol_clone($this);
|
$objFrom = dol_clone($this);
|
||||||
@ -1060,7 +1062,9 @@ class CommandeFournisseur extends CommonOrder
|
|||||||
// End call triggers
|
// End call triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
// End
|
unset($this->context['createfromclone']);
|
||||||
|
|
||||||
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|||||||
@ -1699,7 +1699,9 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
|
|
||||||
$object=new FactureFournisseur($this->db);
|
$object=new FactureFournisseur($this->db);
|
||||||
|
|
||||||
$this->db->begin();
|
$object->context['createfromclone'] = 'createfromclone';
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$object->fetch($fromid);
|
$object->fetch($fromid);
|
||||||
@ -1745,6 +1747,8 @@ class FactureFournisseur extends CommonInvoice
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -327,7 +327,9 @@ class Productbatch extends CommonObject
|
|||||||
|
|
||||||
$object=new Productbatch($this->db);
|
$object=new Productbatch($this->db);
|
||||||
|
|
||||||
$this->db->begin();
|
$object->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
$object->fetch($fromid);
|
$object->fetch($fromid);
|
||||||
@ -353,6 +355,8 @@ class Productbatch extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -853,6 +853,8 @@ class Productcustomerprice extends CommonObject
|
|||||||
|
|
||||||
$object = new Productcustomerprice($this->db);
|
$object = new Productcustomerprice($this->db);
|
||||||
|
|
||||||
|
$object->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -875,6 +877,8 @@ class Productcustomerprice extends CommonObject
|
|||||||
if (! $error) {
|
if (! $error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (! $error) {
|
if (! $error) {
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|||||||
@ -1017,6 +1017,8 @@ class Project extends CommonObject
|
|||||||
|
|
||||||
$clone_project=new Project($this->db);
|
$clone_project=new Project($this->db);
|
||||||
|
|
||||||
|
$clone_project->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -1068,8 +1070,6 @@ class Project extends CommonObject
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
|
||||||
|
|
||||||
//Get the new project id
|
//Get the new project id
|
||||||
$clone_project_id=$clone_project->id;
|
$clone_project_id=$clone_project->id;
|
||||||
|
|
||||||
@ -1223,23 +1223,19 @@ class Project extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($clone_project->context['createfromclone']);
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
if (! $error)
|
{
|
||||||
{
|
$this->db->commit();
|
||||||
return $clone_project_id;
|
return $clone_project_id;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1092,6 +1092,8 @@ class Task extends CommonObject
|
|||||||
$clone_task=new Task($this->db);
|
$clone_task=new Task($this->db);
|
||||||
$origin_task=new Task($this->db);
|
$origin_task=new Task($this->db);
|
||||||
|
|
||||||
|
$clone_task->context['createfromclone']='createfromclone';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Load source object
|
// Load source object
|
||||||
@ -1158,8 +1160,6 @@ class Task extends CommonObject
|
|||||||
// End
|
// End
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
|
||||||
|
|
||||||
$clone_task_id=$clone_task->id;
|
$clone_task_id=$clone_task->id;
|
||||||
$clone_task_ref = $clone_task->ref;
|
$clone_task_ref = $clone_task->ref;
|
||||||
|
|
||||||
@ -1279,20 +1279,19 @@ class Task extends CommonObject
|
|||||||
{
|
{
|
||||||
//TODO clone time of affectation
|
//TODO clone time of affectation
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! $error)
|
unset($clone_task->context['createfromclone']);
|
||||||
{
|
|
||||||
return $clone_task_id;
|
if (! $error)
|
||||||
}
|
{
|
||||||
else
|
$this->db->commit();
|
||||||
{
|
return $clone_task_id;
|
||||||
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user