diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 2f8f7f18e4e304e9dd22fc41a21bceb808ebe0c2..69a3520d1e827d8b7a9ddfbfe2f1a26ed996fead 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -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'); } - - - - + + + + } } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 929932b47c2a9db57060d0568edacc0f3d718f41..26c2c0a0d64edb265b72244c0a42c0e111aa5f78 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -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) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 35834419a74b239456eb63214328129c3609ed2d..2e98f6f21dec8eb25ce36c96c4a6244151640e56 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -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) { diff --git a/htdocs/compta/bank/class/bankcateg.class.php b/htdocs/compta/bank/class/bankcateg.class.php index fb796b219ee08dd26c3d5758970830573dac027e..5004d13caf18e656304ea258a0dbcafa40438ea1 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -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) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d50079f78c882de505cf4b72724e9d601b30865a..08f17832c42abc4d34182f25275aa6f3e170d677 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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) { diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index b75bb056e03185e49e9d4a877e1b82fe8a14200c..d524c501698a1de2f4fcc2070a2d3dd547b5b16e 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -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) { diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 395932de69f4257ec88e676b2c0039aea9746aa7..10f856cf858fe4902e0183d18bf8084444849700 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -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) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8a8258ca641ff82176e18d0af0f9bfc315ccd3d8..4dc3b55c057b1e550383e7400161aec58b88ca9a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -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; diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 723660f1d9ce2e6d2ad2cb224881893b14c46181..5f2ef68b1946780245f0a697dbc9cdaa19d06c4e 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -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) { diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 5faba969755cd2a1509246f574cb65f00d43b1e4..95c8c1801a75b550d021606f043e17228b5fddd8 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -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(); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 96e00aba182d40505adc316236d8e7aed788f9de..7f2697d7c0c2609bb365095ae7d6eea5f57f40fb 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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) { diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index a4df7a95829a238198ec8d586dc76909c4bfb71d..839dce77fed8b3323ac0e5d2655d926a7a5eeb17 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -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) { diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 4cc6e7feb49854266fcce454e97e16765cf4e49d..62d9bb0a406054f393708f3cb6e4b4d1be5da9db 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -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 = ''; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index fbb359909540ed6db2af159354ee08d37c3dd6a8..a52a9f133e9c389d1b5c96adcdc52f64002a87eb 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -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; } } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 0f9645fe237415527109b3f30e0266c8e4d53624..017e2b782ecdd8b4d3cdd86ca9563377ff62ce74 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -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; } }