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:
Laurent Destailleur 2015-02-26 13:03:17 +01:00
parent 386eaf0911
commit 41a74c62e2
15 changed files with 196 additions and 149 deletions

View File

@ -57,7 +57,7 @@ class Mailing extends CommonObject
var $date_creat;
var $date_valid;
var $extraparams=array();
public $statut_dest=array();
@ -78,12 +78,12 @@ class Mailing extends CommonObject
$this->statuts[1] = 'MailingStatusValidated';
$this->statuts[2] = 'MailingStatusSentPartialy';
$this->statuts[3] = 'MailingStatusSentCompletely';
$this->statut_dest[-1] = 'MailingStatusError';
$this->statut_dest[1] = 'MailingStatusSent';
$this->statut_dest[2] = 'MailingStatusRead';
$this->statut_dest[3] = 'MailingStatusNotContact';
}
/**
@ -186,7 +186,7 @@ class Mailing extends CommonObject
function fetch($rowid)
{
global $conf;
$sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
$sql.= ", m.email_from, m.email_replyto, m.email_errorsto";
$sql.= ", m.statut, m.nbemail";
@ -211,14 +211,14 @@ class Mailing extends CommonObject
$this->statut = $obj->statut;
$this->nbemail = $obj->nbemail;
$this->titre = $obj->titre;
$this->sujet = $obj->sujet;
$this->sujet = $obj->sujet;
if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
$this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
}else {
$this->body = $obj->body;
}
$this->bgcolor = $obj->bgcolor;
$this->bgimage = $obj->bgimage;
@ -232,7 +232,7 @@ class Mailing extends CommonObject
$this->date_creat = $this->db->jdate($obj->date_creat);
$this->date_valid = $this->db->jdate($obj->date_valid);
$this->date_envoi = $this->db->jdate($obj->date_envoi);
$this->extraparams = (array) json_decode($obj->extraparams, true);
return 1;
@ -267,6 +267,8 @@ class Mailing extends CommonObject
$object=new Mailing($this->db);
$object->context['createfromclone']='createfromclone';
$this->db->begin();
// Load source object
@ -313,13 +315,13 @@ class Mailing extends CommonObject
{
//Clone target
if (!empty($option2)) {
require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php';
$mailing_target = new MailingTargets($this->db);
$target_array=array();
$sql = "SELECT fk_contact, ";
$sql.=" lastname, ";
$sql.=" firstname,";
@ -330,7 +332,7 @@ class Mailing extends CommonObject
$sql.=" source_type ";
$sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles ";
$sql.= " WHERE fk_mailing = ".$fromid;
dol_syslog(get_class($this)."::createFromClone", LOG_DEBUG);
$result=$this->db->query($sql);
if ($result)
@ -338,17 +340,17 @@ class Mailing extends CommonObject
if ($this->db->num_rows($result))
{
while ($obj = $this->db->fetch_object($result)) {
$target_array[]=array('fk_contact'=>$obj->fk_contact,
'lastname'=>$obj->lastname,
'firstname'=>$obj->firstname,
'email'=>$obj->email,
'email'=>$obj->email,
'other'=>$obj->other,
'source_url'=>$obj->source_url,
'source_id'=>$obj->source_id,
'source_type'=>$obj->source_type);
}
}
}
else
@ -356,12 +358,14 @@ class Mailing extends CommonObject
$this->error=$this->db->lasterror();
return -1;
}
$mailing_target->add_to_target($object->id, $target_array);
}
}
unset($object->context['createfromclone']);
// End
if (! $error)
{
@ -514,7 +518,7 @@ class Mailing extends CommonObject
}
}
/**
* Renvoi le libelle d'un statut donne
*
@ -526,7 +530,7 @@ class Mailing extends CommonObject
{
global $langs;
$langs->load('mails');
if ($mode == 0)
{
return $langs->trans($this->statut_dest[$statut]);
@ -563,10 +567,10 @@ class Mailing extends CommonObject
if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut6');
if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut8');
}
}
}

View File

@ -393,6 +393,8 @@ class Propal extends CommonObject
// Insert line
$this->line=new PropaleLigne($this->db);
$this->line->context = $this->context;
$this->line->fk_propal=$this->id;
$this->line->label=$label;
$this->line->desc=$desc;
@ -953,6 +955,8 @@ class Propal extends CommonObject
{
global $user,$langs,$conf,$hookmanager;
$this->context['createfromclone']='createfromclone';
$error=0;
$now=dol_now();
@ -1046,6 +1050,8 @@ class Propal extends CommonObject
// End call triggers
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -878,6 +878,8 @@ class Commande extends CommonOrder
$error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// get extrafields so they will be clone
@ -942,6 +944,8 @@ class Commande extends CommonOrder
// End call triggers
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -300,7 +300,9 @@ class BankCateg // extends CommonObject
$object=new BankCateg($this->db);
$this->db->begin();
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
$object->fetch($fromid);
@ -327,6 +329,8 @@ class BankCateg // extends CommonObject
}
unset($object->context['createfromclone']);
// End
if (! $error)
{

View File

@ -607,6 +607,8 @@ class Facture extends CommonInvoice
$error=0;
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// get extrafields so they will be clone
@ -693,6 +695,8 @@ class Facture extends CommonInvoice
// End call triggers
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -33,6 +33,7 @@ class PaymentTerm // extends CommonObject
var $errors=array(); //!< To return several error codes (or messages)
//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
var $context =array();
var $id;
@ -409,6 +410,8 @@ class PaymentTerm // extends CommonObject
$object=new PaymentTerm($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
@ -436,6 +439,8 @@ class PaymentTerm // extends CommonObject
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -384,6 +384,8 @@ class PaymentSocialContribution extends CommonObject
$object=new PaymentSocialContribution($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
@ -411,6 +413,8 @@ class PaymentSocialContribution extends CommonObject
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -38,6 +38,7 @@ abstract class CommonObject
public $error;
public $errors;
public $canvas; // Contains canvas name if it is
public $context=array(); // Use to pass context information
public $name;
public $lastname;

View File

@ -718,6 +718,8 @@ class Cronjob extends CommonObject
$object=new Cronjob($this->db);
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
@ -744,6 +746,8 @@ class Cronjob extends CommonObject
}
unset($this->context['createfromclone']);
// End
if (! $error)
{

View File

@ -1024,7 +1024,9 @@ class CommandeFournisseur extends CommonOrder
$error=0;
$this->db->begin();
$this->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
$objFrom = dol_clone($this);
@ -1060,7 +1062,9 @@ class CommandeFournisseur extends CommonOrder
// End call triggers
}
// End
unset($this->context['createfromclone']);
// End
if (! $error)
{
$this->db->commit();

View File

@ -1699,7 +1699,9 @@ class FactureFournisseur extends CommonInvoice
$object=new FactureFournisseur($this->db);
$this->db->begin();
$object->context['createfromclone'] = 'createfromclone';
$this->db->begin();
// Load source object
$object->fetch($fromid);
@ -1745,6 +1747,8 @@ class FactureFournisseur extends CommonInvoice
}
unset($object->context['createfromclone']);
// End
if (! $error)
{

View File

@ -327,7 +327,9 @@ class Productbatch extends CommonObject
$object=new Productbatch($this->db);
$this->db->begin();
$object->context['createfromclone']='createfromclone';
$this->db->begin();
// Load source object
$object->fetch($fromid);
@ -353,6 +355,8 @@ class Productbatch extends CommonObject
}
unset($object->context['createfromclone']);
// End
if (! $error)
{

View File

@ -75,9 +75,9 @@ class Productcustomerprice extends CommonObject
global $conf, $langs;
$error = 0;
// Clean parameters
if (isset($this->entity))
$this->entity = trim($this->entity);
if (isset($this->fk_product))
@ -106,16 +106,16 @@ class Productcustomerprice extends CommonObject
$this->fk_user = trim($this->fk_user);
if (isset($this->import_key))
$this->import_key = trim($this->import_key);
// Check parameters
// Put here code to add control on parameters values
if ($this->price != '' || $this->price == 0) {
if ($this->price_base_type == 'TTC') {
$this->price_ttc = price2num($this->price, 'MU');
$this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
$this->price = price2num($this->price, 'MU');
if ($this->price_min != '' || $this->price_min == 0) {
$this->price_min_ttc = price2num($this->price_min, 'MU');
$this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
@ -128,7 +128,7 @@ class Productcustomerprice extends CommonObject
$this->price = price2num($this->price, 'MU');
$this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
$this->price_ttc = price2num($this->price_ttc, 'MU');
if ($this->price_min != '' || $this->price_min == 0) {
$this->price_min = price2num($this->price_min, 'MU');
$this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
@ -140,10 +140,10 @@ class Productcustomerprice extends CommonObject
}
}
}
// Insert request
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price(";
$sql .= "entity,";
$sql .= "datec,";
$sql .= "fk_product,";
@ -159,9 +159,9 @@ class Productcustomerprice extends CommonObject
$sql .= "localtax2_tx,";
$sql .= "fk_user,";
$sql .= "import_key";
$sql .= ") VALUES (";
$sql .= " " . $conf->entity . ",";
$sql .= " '" . $this->db->idate(dol_now()) . "',";
$sql .= " " . (! isset($this->fk_product) ? 'NULL' : "'" . $this->fk_product . "'") . ",";
@ -177,25 +177,25 @@ class Productcustomerprice extends CommonObject
$sql .= " " . (! isset($this->localtax2_tx) ? 'NULL' : "'" . $this->localtax2_tx . "'") . ",";
$sql .= " " . $user->id . ",";
$sql .= " " . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . "";
$sql .= ")";
$this->db->begin();
dol_syslog(get_class($this) . "::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error ++;
$this->errors [] = "Error " . $this->db->lasterror();
}
if (! $error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "product_customer_price");
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
// // Call triggers
// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
// $interface=new Interfaces($this->db);
@ -204,14 +204,14 @@ class Productcustomerprice extends CommonObject
// // End call triggers
}
}
if (! $error) {
$result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
if ($result < 0) {
$error ++;
}
}
// Commit or rollback
if ($error) {
foreach ( $this->errors as $errmsg ) {
@ -237,7 +237,7 @@ class Productcustomerprice extends CommonObject
global $langs;
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.tms,";
@ -254,18 +254,18 @@ class Productcustomerprice extends CommonObject
$sql .= " t.localtax2_tx,";
$sql .= " t.fk_user,";
$sql .= " t.import_key";
$sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t";
$sql .= " WHERE t.rowid = " . $id;
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->datec = $this->db->jdate($obj->datec);
$this->tms = $this->db->jdate($obj->tms);
@ -284,7 +284,7 @@ class Productcustomerprice extends CommonObject
$this->import_key = $obj->import_key;
}
$this->db->free($resql);
return 1;
} else {
$this->error = "Error " . $this->db->lasterror();
@ -307,7 +307,7 @@ class Productcustomerprice extends CommonObject
global $langs;
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.tms,";
@ -332,7 +332,7 @@ class Productcustomerprice extends CommonObject
$sql .= " WHERE soc.rowid=t.fk_soc ";
$sql .= " AND prod.rowid=t.fk_product ";
$sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")";
// Manage filter
if (count($filter) > 0) {
foreach ( $filter as $key => $value ) {
@ -346,27 +346,27 @@ class Productcustomerprice extends CommonObject
}
}
}
if (! empty($sortfield)) {
$sql .= " ORDER BY " . $sortfield . ' ' . $sortorder;
}
if (! empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
}
dol_syslog(get_class($this) . "::fetch_all", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$this->lines = array ();
$num = $this->db->num_rows($resql);
while ( $obj = $this->db->fetch_object($resql) ) {
$line = new PriceByCustomerLine();
$line->id = $obj->rowid;
$line->entity = $obj->entity;
$line->datec = $this->db->jdate($obj->datec);
$line->tms = $this->db->jdate($obj->tms);
@ -385,11 +385,11 @@ class Productcustomerprice extends CommonObject
$line->import_key = $obj->import_key;
$line->socname = $obj->socname;
$line->prodref = $obj->prodref;
$this->lines [] = $line;
}
$this->db->free($resql);
return $num;
} else {
$this->error = "Error " . $this->db->lasterror();
@ -412,7 +412,7 @@ class Productcustomerprice extends CommonObject
global $langs;
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.fk_product,";
@ -436,7 +436,7 @@ class Productcustomerprice extends CommonObject
$sql .= " WHERE soc.rowid=t.fk_soc ";
$sql .= " AND prod.rowid=t.fk_product ";
$sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")";
// Manage filter
if (count($filter) > 0) {
foreach ( $filter as $key => $value ) {
@ -450,27 +450,27 @@ class Productcustomerprice extends CommonObject
}
}
}
if (! empty($sortfield)) {
$sql .= " ORDER BY " . $sortfield . ' ' . $sortorder;
}
if (! empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
}
dol_syslog(get_class($this) . "::fetch_all_log", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$this->lines = array ();
$num = $this->db->num_rows($resql);
while ( $obj = $this->db->fetch_object($resql) ) {
$line = new PriceByCustomerLine();
$line->id = $obj->rowid;
$line->entity = $obj->entity;
$line->datec = $this->db->jdate($obj->datec);
$line->tms = $this->db->jdate($obj->tms);
@ -489,11 +489,11 @@ class Productcustomerprice extends CommonObject
$line->import_key = $obj->import_key;
$line->socname = $obj->socname;
$line->prodref = $obj->prodref;
$this->lines [] = $line;
}
$this->db->free($resql);
return $num;
} else {
$this->error = "Error " . $this->db->lasterror();
@ -513,9 +513,9 @@ class Productcustomerprice extends CommonObject
global $conf, $langs;
$error = 0;
// Clean parameters
if (isset($this->entity))
$this->entity = trim($this->entity);
if (isset($this->fk_product))
@ -544,16 +544,16 @@ class Productcustomerprice extends CommonObject
$this->fk_user = trim($this->fk_user);
if (isset($this->import_key))
$this->import_key = trim($this->import_key);
// Check parameters
// Put here code to add a control on parameters values
if ($this->price != '' || $this->price == 0) {
if ($this->price_base_type == 'TTC') {
$this->price_ttc = price2num($this->price, 'MU');
$this->price = price2num($this->price) / (1 + ($this->tva_tx / 100));
$this->price = price2num($this->price, 'MU');
if ($this->price_min != '' || $this->price_min == 0) {
$this->price_min_ttc = price2num($this->price_min, 'MU');
$this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100));
@ -566,7 +566,7 @@ class Productcustomerprice extends CommonObject
$this->price = price2num($this->price, 'MU');
$this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price;
$this->price_ttc = price2num($this->price_ttc, 'MU');
if ($this->price_min != '' || $this->price_min == 0) {
$this->price_min = price2num($this->price_min, 'MU');
$this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100));
@ -578,11 +578,11 @@ class Productcustomerprice extends CommonObject
}
}
}
// Do a copy of current record into log table
// Insert request
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price_log(";
$sql .= "entity,";
$sql .= "datec,";
$sql .= "fk_product,";
@ -598,10 +598,10 @@ class Productcustomerprice extends CommonObject
$sql .= "localtax2_tx,";
$sql .= "fk_user,";
$sql .= "import_key";
$sql .= ") ";
$sql .= "SELECT";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.fk_product,";
@ -617,10 +617,10 @@ class Productcustomerprice extends CommonObject
$sql .= " t.localtax2_tx,";
$sql .= " t.fk_user,";
$sql .= " t.import_key";
$sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t";
$sql .= " WHERE t.rowid = " . $this->id;
$this->db->begin();
dol_syslog(get_class($this) . "::update", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -628,10 +628,10 @@ class Productcustomerprice extends CommonObject
$error ++;
$this->errors [] = "Error " . $this->db->lasterror();
}
// Update request
$sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET";
$sql .= " entity=" . $conf->entity . ",";
$sql .= " datec='" . $this->db->idate(dol_now()) . "',";
$sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ",";
@ -648,21 +648,21 @@ class Productcustomerprice extends CommonObject
$sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? $this->localtax2_tx : "null") . ",";
$sql .= " fk_user=" . $user->id . ",";
$sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . "";
$sql .= " WHERE rowid=" . $this->id;
dol_syslog(get_class($this) . "::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error ++;
$this->errors [] = "Error " . $this->db->lasterror();
}
if (! $error) {
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
// // Call triggers
// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
// $interface=new Interfaces($this->db);
@ -671,14 +671,14 @@ class Productcustomerprice extends CommonObject
// // End call triggers
}
}
if (! $error) {
$result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate);
if ($result < 0) {
$error ++;
}
}
// Commit or rollback
if ($error) {
foreach ( $this->errors as $errmsg ) {
@ -703,50 +703,50 @@ class Productcustomerprice extends CommonObject
function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate) {
$error = 0;
// Find all susidiaries
$sql = "SELECT s.rowid";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
$sql .= " WHERE s.parent = " . $this->fk_soc;
$sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")";
dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$this->lines = array ();
$num = $this->db->num_rows($resql);
while ( ($obj = $this->db->fetch_object($resql)) && (empty($error)) ) {
// find if there is an existing line for the product and the subsidiaries
$prodsocprice = new Productcustomerprice($this->db);
$filter = array (
't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid
't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid
);
$result = $prodsocprice->fetch_all('', '', 0, 0, $filter);
if ($result < 0) {
$error ++;
$this->error = $prodsocprice->error;
} else {
// There is one line
if (count($prodsocprice->lines) > 0) {
// If force update => Update
if (! empty($forceupdateaffiliate)) {
$prodsocpriceupd = new Productcustomerprice($this->db);
$prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
$prodsocpriceupd->price = $this->price;
$prodsocpriceupd->price_min = $this->price_min;
$prodsocpriceupd->price_base_type = $this->price_base_type;
$prodsocpriceupd->tva_tx = $this->tva_tx;
$prodsocpriceupd->recuperableonly = $this->recuperableonly;
$resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
if ($result < 0) {
$error ++;
@ -763,7 +763,7 @@ class Productcustomerprice extends CommonObject
$prodsocpricenew->price_base_type = $this->price_base_type;
$prodsocpricenew->tva_tx = $this->tva_tx;
$prodsocpricenew->recuperableonly = $this->recuperableonly;
$resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
if ($result < 0) {
$error ++;
@ -773,7 +773,7 @@ class Productcustomerprice extends CommonObject
}
}
$this->db->free($resql);
if (empty($error)) {
return 1;
} else {
@ -796,14 +796,14 @@ class Productcustomerprice extends CommonObject
global $conf, $langs;
$error = 0;
$this->db->begin();
if (! $error) {
if (! $notrigger) {
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
// // Call triggers
// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
// $interface=new Interfaces($this->db);
@ -812,11 +812,11 @@ class Productcustomerprice extends CommonObject
// // End call triggers
}
}
if (! $error) {
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_customer_price";
$sql .= " WHERE rowid=" . $this->id;
dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
@ -824,7 +824,7 @@ class Productcustomerprice extends CommonObject
$this->errors [] = "Error " . $this->db->lasterror();
}
}
// Commit or rollback
if ($error) {
foreach ( $this->errors as $errmsg ) {
@ -848,33 +848,37 @@ class Productcustomerprice extends CommonObject
function createFromClone($fromid) {
global $user, $langs;
$error = 0;
$object = new Productcustomerprice($this->db);
$object->context['createfromclone']='createfromclone';
$this->db->begin();
// Load source object
$object->fetch($fromid);
$object->id = 0;
$object->statut = 0;
// Clear fields
// ...
// Create clone
$result = $object->create($user);
// Other options
if ($result < 0) {
$this->error = $object->error;
$error ++;
}
if (! $error) {
}
unset($object->context['createfromclone']);
// End
if (! $error) {
$this->db->commit();
@ -894,7 +898,7 @@ class Productcustomerprice extends CommonObject
function initAsSpecimen() {
$this->id = 0;
$this->entity = '';
$this->datec = '';
$this->tms = '';

View File

@ -1017,6 +1017,8 @@ class Project extends CommonObject
$clone_project=new Project($this->db);
$clone_project->context['createfromclone']='createfromclone';
$this->db->begin();
// Load source object
@ -1068,8 +1070,6 @@ class Project extends CommonObject
if (! $error)
{
$this->db->commit();
//Get the new project id
$clone_project_id=$clone_project->id;
@ -1223,23 +1223,19 @@ class Project extends CommonObject
}
}
}
}
unset($clone_project->context['createfromclone']);
if (! $error)
{
return $clone_project_id;
}
else
{
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
if (! $error)
{
$this->db->commit();
return $clone_project_id;
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
}

View File

@ -1092,6 +1092,8 @@ class Task extends CommonObject
$clone_task=new Task($this->db);
$origin_task=new Task($this->db);
$clone_task->context['createfromclone']='createfromclone';
$this->db->begin();
// Load source object
@ -1158,8 +1160,6 @@ class Task extends CommonObject
// End
if (! $error)
{
$this->db->commit();
$clone_task_id=$clone_task->id;
$clone_task_ref = $clone_task->ref;
@ -1279,20 +1279,19 @@ class Task extends CommonObject
{
//TODO clone time of affectation
}
}
if (! $error)
{
return $clone_task_id;
}
else
{
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
unset($clone_task->context['createfromclone']);
if (! $error)
{
$this->db->commit();
return $clone_task_id;
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR);
return -1;
}
}