diff --git a/ChangeLog b/ChangeLog index 32bb738eba6..1a853809489 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,14 @@ For users: - Fix: [ bug #1494 ] CATEGORY_CREATE and CATEGORY_MODIFY triggers do not intercept trigger action - Fix: [ bug #1502 ] DON_CREATE trigger does not intercept trigger action - Fix: [ bug #1505, #1504] Project trigger problem +- Fix: [ bug #1463, #1464 ] Proposal triggers problem +- Fix: [ bug #1498, #1499 ] Shipment/Delivery triggers problem +- Fix: [ bug #1465, #1466 ] Product triggers problem +- Fix: [ bug #1508 ] STOCK_MOVEMENT does not show trigger error message +- Fix: [ bug #1501 ] DEPLACEMENT_CREATE trigger do not intercept trigger action +- Fix: [ bug #1506, #1507 ] ECM trigger error problem +- Fix: [ bug #1469 ] Triggers CONTACT_MODIFY and CONTACT_DELETE duplicates error message + For translators: - Update language files. diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 7f2ebf1de4b..0668b49121d 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -856,24 +856,22 @@ class Propal extends CommonObject if (! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } } else { + $this->error=$this->db->error(); $error++; } } } else { + $this->error=$this->db->error(); $error++; } @@ -885,7 +883,6 @@ class Propal extends CommonObject } else { - $this->error=$this->db->error(); $this->db->rollback(); return -2; } @@ -1006,14 +1003,10 @@ class Propal extends CommonObject if ($reshook < 0) $error++; } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_CLONE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_CLONE',$user); + if ($result < 0) { $error++; } + // End call triggers } // End @@ -1326,14 +1319,10 @@ class Propal extends CommonObject { if (! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_VALIDATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -1668,25 +1657,24 @@ class Propal extends CommonObject { if (! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_REOPEN',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_REOPEN',$user); + if ($result < 0) { $error++; } + // End call triggers } } // Commit or rollback if ($error) { - foreach($this->errors as $errmsg) - { - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); - $this->error.=($this->error?', '.$errmsg:$errmsg); - } + if (!empty($this->errors)) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + } $this->db->rollback(); return -1*$error; } @@ -1751,14 +1739,10 @@ class Propal extends CommonObject propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL?$conf->global->PROPALE_ADDON_PDF_ODT_TOBILL:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_CLOSE_SIGNED',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_CLOSE_SIGNED',$user); + if ($result < 0) { $error++; } + // End call triggers } else { @@ -1777,18 +1761,21 @@ class Propal extends CommonObject propale_pdf_create($this->db, $this, $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED?$conf->global->PROPALE_ADDON_PDF_ODT_CLOSED:$this->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_CLOSE_REFUSED',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PROPAL_CLOSE_REFUSED',$user); + if ($result < 0) { $error++; } + // End call triggers + } + if ( ! $error ) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; } - - $this->db->commit(); - return 1; } else { @@ -2039,15 +2026,11 @@ class Propal extends CommonObject $this->db->begin(); - if (! $error && ! $notrigger) + if (! $notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } + // Call trigger + $result=$this->call_trigger('PROPAL_DELETE',$user); + if ($result < 0) { $error++; } // End call triggers } @@ -2145,7 +2128,6 @@ class Propal extends CommonObject } else { - $this->error=$this->db->lasterror(); $this->db->rollback(); return -1; } @@ -2931,14 +2913,14 @@ class PropaleLigne extends CommonObject if (! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result = $interface->run_triggers('LINEPROPAL_INSERT',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('LINEPROPAL_INSERT',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers } $this->db->commit(); @@ -2981,14 +2963,14 @@ class PropaleLigne extends CommonObject } } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result = $interface->run_triggers('LINEPROPAL_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('LINEPROPAL_DELETE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers $this->db->commit(); @@ -3091,14 +3073,14 @@ class PropaleLigne extends CommonObject if (! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result = $interface->run_triggers('LINEPROPAL_UPDATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('LINEPROPAL_UPDATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers } $this->db->commit(); diff --git a/htdocs/compta/deplacement/class/deplacement.class.php b/htdocs/compta/deplacement/class/deplacement.class.php index 942ceb912c8..0f17c543b9d 100644 --- a/htdocs/compta/deplacement/class/deplacement.class.php +++ b/htdocs/compta/deplacement/class/deplacement.class.php @@ -126,15 +126,15 @@ class Deplacement extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement"); - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('DEPLACEMENT_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - + // Call trigger + $result=$this->call_trigger('DEPLACEMENT_CREATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -2; + } + // End call triggers + $result=$this->update($user); if ($result > 0) { diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 95f949b123f..7858f81dcf9 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -183,12 +183,10 @@ class Contact extends CommonObject if (! $error) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('CONTACT_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('CONTACT_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -304,12 +302,10 @@ class Contact extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('CONTACT_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('CONTACT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -319,7 +315,6 @@ class Contact extends CommonObject } else { - $this->error=join(',',$this->errors); dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR); $this->db->rollback(); return -$error; @@ -777,14 +772,10 @@ class Contact extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('CONTACT_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - if ($error) $this->error=join(',',$this->errors); + // Call trigger + $result=$this->call_trigger('CONTACT_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -1067,12 +1058,10 @@ class Contact extends CommonObject dol_syslog(get_class($this)."::setstatus", LOG_DEBUG); if ($result) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('CONTACT_ENABLEDISABLE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user); + if ($result < 0) { $error++; } + // End call triggers } if ($error) diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 9cb52738bb8..0d8a26cf81f 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -138,19 +138,30 @@ if (empty($reshook)) if ($action == 'disable') { $object->fetch($id); - $object->setstatus(0); - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); - exit; + if ($object->setstatus(0)<0) + { + setEventMessage($object->error,'errors'); + } + else + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); + exit; + } } // Confirmation activation if ($action == 'enable') { $object->fetch($id); - $object->setstatus(1); - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); - exit; - + if ($object->setstatus(1)<0) + { + setEventMessage($object->error,'errors'); + } + else + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); + exit; + } } // Add contact @@ -235,7 +246,8 @@ if (empty($reshook)) } else { - $error=$object->error; $errors=$object->errors; + setEventMessage($object->error,'errors'); + setEventMessage($object->errors,'errors'); } } @@ -295,7 +307,8 @@ if (empty($reshook)) } else { - $error=$object->error; $errors=$object->errors; + setEventMessage($object->error,'errors'); + setEventMessage($object->errors,'errors'); $action = 'edit'; } } @@ -367,6 +380,8 @@ else $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")); dol_fiche_head($head, 'card', $title, 0, 'contact'); + + dol_htmloutput_events(); } if ($user->rights->societe->contact->creer) diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index 62b758739c7..8bc4e42ed3f 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -211,6 +211,10 @@ class InterfaceDemo { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + elseif ($action == 'CONTACT_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } // Products elseif ($action == 'PRODUCT_CREATE') @@ -222,6 +226,30 @@ class InterfaceDemo dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'PRODUCT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PRODUCT_PRICE_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + //Stock mouvement + elseif ($action == 'STOCK_MOVEMENT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + //MYECMDIR + elseif ($action == 'MYECMDIR_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MYECMDIR_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MYECMDIR_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index 87f3bcd59ba..52c698c240f 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -152,12 +152,10 @@ class EcmDirectory // extends CommonObject $result=dol_mkdir($dir); if ($result < 0) { $error++; $this->error="ErrorFailedToCreateDir"; } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('MYECMDIR_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('MYECMDIR_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers if (! $error) { @@ -219,12 +217,10 @@ class EcmDirectory // extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('MYECMDIR_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('MYECMDIR_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -352,7 +348,18 @@ class EcmDirectory // extends CommonObject $this->error="Error ".$this->db->lasterror(); return -2; } - + else + { + // Call trigger + $result=$this->call_trigger('MYECMDIR_DELETE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -2; + } + // End call triggers + } + if ($mode != 'databaseonly') { $file = $conf->ecm->dir_output . "/" . $relativepath; @@ -371,16 +378,6 @@ class EcmDirectory // extends CommonObject $error++; } - if (! $error) - { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('MYECMDIR_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - if (! $error) return 1; else return -1; } @@ -696,5 +693,38 @@ class EcmDirectory // extends CommonObject return -1; } } + + /** + * Call trigger based on this instance + * + * NB: Error from trigger are stacked in errors + * NB2: if trigger fail, action should be canceled. + * NB3: Should be deleted if EcmDirectory extend CommonObject + * + * @param string $trigger_name trigger's name to execute + * @param User $user Object user + * @return int Result of run_triggers + */ + function call_trigger($trigger_name, $user) + { + global $langs,$conf; + + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); + if ($result < 0) { + if (!empty($this->errors)) + { + $this->errors=array_merge($this->errors,$interface->errors); + } + else + { + $this->errors=$interface->errors; + } + } + return $result; + + } + } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 5b50a18368e..f6a92b91434 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -275,12 +275,10 @@ class Expedition extends CommonObject if (! $error) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('SHIPPING_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('SHIPPING_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers if (! $error) { @@ -656,12 +654,10 @@ class Expedition extends CommonObject if (! $error) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('SHIPPING_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('SHIPPING_VALIDATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -867,12 +863,10 @@ class Expedition extends CommonObject { if (! $notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('SHIPPING_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // End call triggers + // Call trigger + $result=$this->call_trigger('SHIPPING_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } } @@ -982,12 +976,10 @@ class Expedition extends CommonObject if ($this->db->query($sql)) { - // Call triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('SHIPPING_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // End call triggers + // Call trigger + $result=$this->call_trigger('SHIPPING_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers if (! $error) { diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index ff6b23c10be..c2a2036c25f 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -241,26 +241,34 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->exped $object->fetch_thirdparty(); $result = $object->valid($user); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $ret=$object->fetch($id); // Reload to get new records - $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs); - } + if ($result < 0) { - dol_print_error($db,$result); - exit; + $langs->load("errors"); + setEventMessage($langs->trans($object->error),'errors'); + } + else + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $ret=$object->fetch($id); // Reload to get new records + $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs); + } + if ($result < 0) + { + dol_print_error($db,$result); + exit; + } } } diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 399050d0547..c46e333c191 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -446,15 +446,12 @@ class Livraison extends CommonObject return -1; } - // Appel des triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface = new Interfaces($this->db); - $result = $interface->run_triggers('DELIVERY_VALIDATE', $this, $user, $langs, $conf); - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('DELIVERY_VALIDATE',$user); + // End call triggers if ($result < 0) { $this->db->rollback(); - $this->error = $interface->errors; dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); return -1; } @@ -604,14 +601,14 @@ class Livraison extends CommonObject } } - // Call triggers - include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('DELIVERY_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // End call triggers + // Call trigger + $result=$this->call_trigger('DELIVERY_DELETE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -4; + } + // End call triggers return 1; } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 8871586c6c6..bfa814cd9ec 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -427,12 +427,10 @@ class Product extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -665,12 +663,10 @@ class Product extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) @@ -763,34 +759,33 @@ class Product extends CommonObject if (! $error) { - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_DELETE',$user); + if ($result < 0) { $error++; } + // End call triggers } - // Delete all child tables - $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); - foreach($elements as $table) + // Delete all child tables + if (! $error) { - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; - $sql.= " WHERE fk_product = ".$id; - dol_syslog(get_class($this).'::delete', LOG_DEBUG); - $result = $this->db->query($sql); - if (! $result) - { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } + $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product','product_stock'); + foreach($elements as $table) + { + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_product = ".$id; + dol_syslog(get_class($this).'::delete', LOG_DEBUG); + $result = $this->db->query($sql); + if (! $result) + { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + } } - + // Delete product if (! $error) { @@ -1227,6 +1222,8 @@ class Product extends CommonObject $localtax2=get_localtax($newvat,2); if (empty($localtax1)) $localtax1=0; // If = '' then = 0 if (empty($localtax2)) $localtax2=0; // If = '' then = 0 + + $this->db->begin(); // Ne pas mettre de quote sur les numeriques decimaux. // Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. @@ -1264,19 +1261,21 @@ class Product extends CommonObject $this->level = $level; // Store level of price edited for trigger - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PRODUCT_PRICE_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) - { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_PRICE_MODIFY',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers + + $this->db->commit(); } else { - dol_print_error($this->db); + $this->db->rollback(); + dol_print_error($this->db); } } @@ -2876,7 +2875,7 @@ class Product extends CommonObject } else { - dol_print_error($this->db); + $this->error=$movementstock->error; $this->db->rollback(); return -1; } @@ -3473,7 +3472,7 @@ class Product extends CommonObject } else { - dol_print_error($this->db); + $this->error=$movementstock->error; $this->db->rollback(); return -1; } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 338169a6154..a9b9c000553 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -154,6 +154,11 @@ if ($action == "correct_stock" && ! $cancel) header("Location: ".$_SERVER["PHP_SELF"]."?id=".$product->id); exit; } + else + { + setEventMessage($product->error,'errors'); + $action='correction'; + } } } } @@ -253,6 +258,8 @@ if ($id > 0 || $ref) $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); dol_fiche_head($head, 'stock', $titre, 0, $picto); + + dol_htmloutput_events(); $form = new Form($db);